Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tar: read directly from stdin #1728

Merged
merged 2 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/buildcontext/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ limitations under the License.
package buildcontext

import (
"compress/gzip"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/util"
Expand All @@ -47,14 +46,15 @@ func (t *Tar) UnpackTarFromBuildContext() (string, error) {
logrus.Infof("To simulate EOF and exit, press 'Ctrl+D'")
// if launched through docker in interactive mode and without piped data
// process will be stuck here until EOF is sent
data, err := util.GetInputFrom(os.Stdin)
gzr, err := gzip.NewReader(os.Stdin)
if err != nil {
return "", errors.Wrap(err, "fail to get standard input")
}
t.context = filepath.Join(directory, constants.ContextTar)
if err := ioutil.WriteFile(t.context, data, 0644); err != nil {
return "", errors.Wrap(err, "fail to redirect standard input into compressed tar file")
return directory, err
}
defer gzr.Close()
_, err = util.UnTar(gzr, directory)

return directory, err

}

return directory, util.UnpackCompressedTar(t.context, directory)
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ func childDirInIgnoreList(path string) bool {
return false
}

// unTar returns a list of files that have been extracted from the tar archive at r to the path at dest
func unTar(r io.Reader, dest string) ([]string, error) {
// UnTar returns a list of files that have been extracted from the tar archive at r to the path at dest
func UnTar(r io.Reader, dest string) ([]string, error) {
var extractedFiles []string
tr := tar.NewReader(r)
for {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/fs_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func createUncompressedTar(fileContents map[string]string, tarFileName, testDir
return nil
}

func Test_unTar(t *testing.T) {
func Test_UnTar(t *testing.T) {
tcs := []struct {
name string
setupTarContents map[string]string
Expand Down Expand Up @@ -671,7 +671,7 @@ func Test_unTar(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fileList, err := unTar(file, tc.destination)
fileList, err := UnTar(file, tc.destination)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/tar_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func UnpackLocalTarArchive(path, dest string) ([]string, error) {
return nil, UnpackCompressedTar(path, dest)
} else if compressionLevel == archive.Bzip2 {
bzr := bzip2.NewReader(file)
return unTar(bzr, dest)
return UnTar(bzr, dest)
}
}
if fileIsUncompressedTar(path) {
Expand All @@ -227,7 +227,7 @@ func UnpackLocalTarArchive(path, dest string) ([]string, error) {
return nil, err
}
defer file.Close()
return unTar(file, dest)
return UnTar(file, dest)
}
return nil, errors.New("path does not lead to local tar archive")
}
Expand Down Expand Up @@ -286,6 +286,6 @@ func UnpackCompressedTar(path, dir string) error {
return err
}
defer gzr.Close()
_, err = unTar(gzr, dir)
_, err = UnTar(gzr, dir)
return err
}