diff --git a/pkg/buildcontext/tar.go b/pkg/buildcontext/tar.go index f7fcf178e..5333052cf 100644 --- a/pkg/buildcontext/tar.go +++ b/pkg/buildcontext/tar.go @@ -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" @@ -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) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 8673235f1..167b130c6 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -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 { diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index db12c059b..01a0741ff 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -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 @@ -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) } diff --git a/pkg/util/tar_util.go b/pkg/util/tar_util.go index fc114fee1..4b992ed0d 100644 --- a/pkg/util/tar_util.go +++ b/pkg/util/tar_util.go @@ -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) { @@ -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") } @@ -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 }