Use cachekey not digest for COPY --from src

* use the cachekey of the src stage rather than the digest
for COPY --from commands as they are reproducible unlike digests
* track digest to cache keys and stage indexes to digest
* add extra debug logging for troubleshooting cachekey building issues
* convert Sha256 hashes to hex encoded strings rather than plain strings
for easier human reading
This commit is contained in:
Cole Wippern
2019-12-10 08:45:13 -08:00
parent 7b4b768edf
commit b19214ad1e
3 changed files with 63 additions and 100 deletions
+1 -48
View File
@@ -888,6 +888,7 @@ func tempDirAndFile(t *testing.T) (string, []string) {
return dir, filenames
}
func generateTar(t *testing.T, dir string, fileNames ...string) []byte {
buf := bytes.NewBuffer([]byte{})
writer := tar.NewWriter(buf)
@@ -919,51 +920,3 @@ func generateTar(t *testing.T, dir string, fileNames ...string) []byte {
}
return buf.Bytes()
}
//=======
// testCases := []struct {
// opts *config.KanikoOptions
// retrieve bool
// }{
// {
// opts: &config.KanikoOptions{Cache: true},
// },
// {
// opts: &config.KanikoOptions{Cache: true},
// retrieve: true,
// },
// {
// opts: &config.KanikoOptions{Cache: false},
// },
// {
// opts: &config.KanikoOptions{Cache: false},
// retrieve: true,
// },
// }
// for i, tc := range testCases {
// t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) {
// file, err := ioutil.TempFile("", "foo")
// if err != nil {
// t.Error(err)
// }
// cf := &v1.ConfigFile{}
// snap := fakeSnapShotter{file: file.Name()}
// lc := fakeLayerCache{retrieve: tc.retrieve}
// sb := &stageBuilder{opts: tc.opts, cf: cf, snapshotter: snap, layerCache: lc, pushCache: fakeCachePush}
// command := MockDockerCommand{
// contextFiles: []string{file.Name()},
// cacheCommand: MockCachedDockerCommand{
// contextFiles: []string{file.Name()},
// },
// }
// sb.cmds = []commands.DockerCommand{command}
// err = sb.build()
// if err != nil {
// t.Errorf("Expected error to be nil but was %v", err)
// }
// })
// }
//}
//>>>>>>> Add unit tests for stagebuilder build and optimize