Skip to content

Commit

Permalink
Fixing logic for Copy command. The problem was not that tar files wer…
Browse files Browse the repository at this point in the history
…e being unpacked in wrong order. The problem was that the COPY command requires the FS to be unpacked before it does its work.
  • Loading branch information
donmccasland committed Sep 26, 2019
1 parent 1bb5a41 commit e58ee09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/commands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
// we need to add '/' to the end to indicate the destination is a directory
dest = filepath.Join(cwd, dest) + "/"
}
logrus.Debugf("Calling CopyDir fullPath:%s dest:%s", fullPath, dest)
copiedFiles, err := util.CopyDir(fullPath, dest, c.buildcontext)
if err != nil {
return err
Expand All @@ -87,6 +88,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
c.snapshotFiles = append(c.snapshotFiles, destPath)
} else {
// ... Else, we want to copy over a file
logrus.Debugf("Calling CopyFile fullPath:%s destPath:%s", fullPath, destPath)
exclude, err := util.CopyFile(fullPath, destPath, c.buildcontext)
if err != nil {
return err
Expand Down Expand Up @@ -134,3 +136,7 @@ func (c *CopyCommand) FilesUsedFromContext(config *v1.Config, buildArgs *dockerf
func (c *CopyCommand) MetadataOnly() bool {
return false
}

func (c *CopyCommand) RequiresUnpackedFS() bool {
return true
}
4 changes: 2 additions & 2 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error {
// or a file was copied over a directory prior to now
fi, err := os.Stat(dir)
if os.IsNotExist(err) || !fi.IsDir() {
logrus.Debugf("base %s for file %s does not exist. Creating.", base, path)
os.RemoveAll(dir)
logrus.Infof("base %s for file %s does not exist. Creating.", base, path)
//os.RemoveAll(dir)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
Expand Down

0 comments on commit e58ee09

Please sign in to comment.