github.com/GoogleContainerTools/kaniko@v1.23.0/pkg/buildcontext/tar.go (about) 1 /* 2 Copyright 2018 Google LLC 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package buildcontext 18 19 import ( 20 "compress/gzip" 21 "fmt" 22 "os" 23 24 kConfig "github.com/GoogleContainerTools/kaniko/pkg/config" 25 "github.com/GoogleContainerTools/kaniko/pkg/util" 26 "github.com/pkg/errors" 27 "github.com/sirupsen/logrus" 28 ) 29 30 // Tar unifies calls to download and unpack the build context. 31 type Tar struct { 32 context string 33 } 34 35 // UnpackTarFromBuildContext unpack the compressed tar file 36 func (t *Tar) UnpackTarFromBuildContext() (string, error) { 37 directory := kConfig.BuildContextDir 38 if err := os.MkdirAll(directory, 0750); err != nil { 39 return "", errors.Wrap(err, "unpacking tar from build context") 40 } 41 if t.context == "stdin" { 42 fi, _ := os.Stdin.Stat() 43 if (fi.Mode() & os.ModeCharDevice) != 0 { 44 return "", fmt.Errorf("no data found.. don't forget to add the '--interactive, -i' flag") 45 } 46 logrus.Infof("To simulate EOF and exit, press 'Ctrl+D'") 47 // if launched through docker in interactive mode and without piped data 48 // process will be stuck here until EOF is sent 49 gzr, err := gzip.NewReader(os.Stdin) 50 if err != nil { 51 return directory, err 52 } 53 defer gzr.Close() 54 _, err = util.UnTar(gzr, directory) 55 56 return directory, err 57 58 } 59 60 return directory, util.UnpackCompressedTar(t.context, directory) 61 }