update caching run and copy extracted files

Update caching run and copy commands to use the new
GetFSFromLayers method and include the whiteout option so that
whiteout files are extracted and included in extractedFiles
This commit is contained in:
Cole Wippern
2020-01-17 14:19:58 -08:00
parent 71aed35094
commit 876f24b0c9
4 changed files with 39 additions and 17 deletions
+11 -2
View File
@@ -167,7 +167,13 @@ func (cr *CachingCopyCommand) ExecuteCommand(config *v1.Config, buildArgs *docke
if cr.img == nil {
return errors.New(fmt.Sprintf("cached command image is nil %v", cr.String()))
}
cr.extractedFiles, err = util.GetFSFromImage(RootDir, cr.img, cr.extractFn)
layers, err := cr.img.Layers()
if err != nil {
return errors.Wrapf(err, "retrieve image layers")
}
cr.extractedFiles, err = util.GetFSFromLayers(RootDir, layers, util.ExtractFunc(cr.extractFn), util.IncludeWhiteout())
logrus.Infof("extractedFiles: %s", cr.extractedFiles)
if err != nil {
@@ -182,7 +188,10 @@ func (cr *CachingCopyCommand) FilesUsedFromContext(config *v1.Config, buildArgs
}
func (cr *CachingCopyCommand) FilesToSnapshot() []string {
return cr.extractedFiles
f := cr.extractedFiles
logrus.Debugf("files extracted by caching copy command %s", f)
return f
}
func (cr *CachingCopyCommand) String() string {
+16 -2
View File
@@ -197,7 +197,18 @@ func (cr *CachingRunCommand) ExecuteCommand(config *v1.Config, buildArgs *docker
if cr.img == nil {
return errors.New(fmt.Sprintf("command image is nil %v", cr.String()))
}
cr.extractedFiles, err = util.GetFSFromImage(constants.RootDir, cr.img, cr.extractFn)
layers, err := cr.img.Layers()
if err != nil {
return errors.Wrap(err, "retrieving image layers")
}
cr.extractedFiles, err = util.GetFSFromLayers(
constants.RootDir,
layers,
util.ExtractFunc(cr.extractFn),
util.IncludeWhiteout(),
)
if err != nil {
return errors.Wrap(err, "extracting fs from image")
}
@@ -206,7 +217,10 @@ func (cr *CachingRunCommand) ExecuteCommand(config *v1.Config, buildArgs *docker
}
func (cr *CachingRunCommand) FilesToSnapshot() []string {
return cr.extractedFiles
f := cr.extractedFiles
logrus.Debugf("files extracted from caching run command %s", f)
return f
}
func (cr *CachingRunCommand) String() string {
+6 -4
View File
@@ -160,12 +160,14 @@ func GetFSFromLayers(root string, layers []v1.Layer, opts ...FSOpt) ([]string, e
}
if !cfg.includeWhiteout {
logrus.Debug("not including whiteout files")
continue
}
} else {
if err := cfg.extractFunc(root, hdr, tr); err != nil {
return nil, err
}
}
if err := cfg.extractFunc(root, hdr, tr); err != nil {
return nil, err
}
extractedFiles = append(extractedFiles, filepath.Join(root, filepath.Clean(hdr.Name)))
+6 -9
View File
@@ -892,21 +892,20 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled(t *testing.T)
expectErr := false
f := func(expectedFiles []string, tw *tar.Writer) {
body := "Hello World\n"
for _, f := range expectedFiles {
f := strings.TrimPrefix(strings.TrimPrefix(f, root), "/")
hdr := &tar.Header{
Name: f,
Mode: 0644,
Size: int64(len(body)),
Size: int64(len("Hello World\n")),
}
if err := tw.WriteHeader(hdr); err != nil {
t.Fatal(err)
}
if _, err := tw.Write([]byte(body)); err != nil {
if _, err := tw.Write([]byte("Hello World\n")); err != nil {
t.Fatal(err)
}
}
@@ -982,21 +981,20 @@ func Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled(t *testing.T)
expectErr := false
f := func(expectedFiles []string, tw *tar.Writer) {
body := "Hello World\n"
for _, f := range expectedFiles {
f := strings.TrimPrefix(strings.TrimPrefix(f, root), "/")
hdr := &tar.Header{
Name: f,
Mode: 0644,
Size: int64(len(body)),
Size: int64(len("Hello world\n")),
}
if err := tw.WriteHeader(hdr); err != nil {
t.Fatal(err)
}
if _, err := tw.Write([]byte(body)); err != nil {
if _, err := tw.Write([]byte("Hello world\n")); err != nil {
t.Fatal(err)
}
}
@@ -1075,21 +1073,20 @@ func Test_GetFSFromLayers(t *testing.T) {
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
body := "Hello World\n"
for _, f := range expectedFiles {
f := strings.TrimPrefix(strings.TrimPrefix(f, root), "/")
hdr := &tar.Header{
Name: f,
Mode: 0644,
Size: int64(len(body)),
Size: int64(len("Hello world\n")),
}
if err := tw.WriteHeader(hdr); err != nil {
t.Fatal(err)
}
if _, err := tw.Write([]byte(body)); err != nil {
if _, err := tw.Write([]byte("Hello world\n")); err != nil {
t.Fatal(err)
}
}