tar: read directly from stdin (#1728)
* tar: run directly from stdin * export UnTar function
This commit is contained in:
parent
d2f3e896cd
commit
2ea368dde8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue