From fa0b6ced289f31f7e4eceb00378d4c92181cb5e9 Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Wed, 23 Oct 2024 16:44:19 -0400 Subject: [PATCH] Fixes Signed-off-by: Natalie Arellano --- acceptance/exporter_test.go | 13 ++++++++++--- ...866ebc91139e7c0e574f60d1d4092f53d7dff59.tar} | Bin acceptance/testdata/restorer/Dockerfile | 10 ++++------ .../io.buildpacks.lifecycle.cache.metadata | 2 +- ...7b9c99ad05776a89d19ab863c28850a91e5f2944.tar | Bin 0 -> 10240 bytes ...843599d96afe28784cffcb2d46ddb07beb00df78.tar | Bin 0 -> 10240 bytes cache/volume_cache.go | 3 +-- 7 files changed, 16 insertions(+), 12 deletions(-) rename acceptance/testdata/exporter/cache-dir/committed/{sha256:258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar => sha256_258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar} (100%) create mode 100644 acceptance/testdata/restorer/container/cache/committed/sha256_2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar create mode 100644 acceptance/testdata/restorer/container/cache/committed/sha256_430338f576c11e5236669f9c843599d96afe28784cffcb2d46ddb07beb00df78.tar diff --git a/acceptance/exporter_test.go b/acceptance/exporter_test.go index 1c45beace..c29a8e30c 100644 --- a/acceptance/exporter_test.go +++ b/acceptance/exporter_test.go @@ -56,7 +56,6 @@ func TestExporter(t *testing.T) { exportImage = exportTest.testImageRef exporterPath = exportTest.containerBinaryPath - cacheFixtureDir = filepath.Join("testdata", "exporter", "cache-dir") exportRegAuthConfig = exportTest.targetRegistry.authConfig exportRegNetwork = exportTest.targetRegistry.network exportDaemonFixtures = exportTest.targetDaemon.fixtures @@ -404,9 +403,16 @@ func testExporterFunc(platformAPI string) func(t *testing.T, when spec.G, it spe var err error cacheDir, err = os.MkdirTemp("", "cache") h.AssertNil(t, err) + h.AssertNil(t, os.Chmod(cacheDir, 0777)) // Override umask cacheFixtureDir := filepath.Join("testdata", "exporter", "cache-dir") h.AssertNil(t, fsutil.Copy(cacheFixtureDir, cacheDir)) + // We have to pre-create the tar files so that their digests do not change due to timestamps + // But, ':' in the filepath on Windows is not allowed + h.AssertNil(t, os.Rename( + filepath.Join(cacheDir, "committed", "sha256_258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar"), + filepath.Join(cacheDir, "committed", "sha256:258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar"), + )) }) it.After(func() { @@ -415,7 +421,7 @@ func testExporterFunc(platformAPI string) func(t *testing.T, when spec.G, it spe it("overwrites the original layer", func() { exportFlags := []string{ - "-cache-dir", "/cache/committed", + "-cache-dir", "/cache", "-log-level", "debug", } exportArgs := append([]string{ctrPath(exporterPath)}, exportFlags...) @@ -428,10 +434,11 @@ func testExporterFunc(platformAPI string) func(t *testing.T, when spec.G, it spe "--env", "CNB_PLATFORM_API="+platformAPI, "--env", "CNB_REGISTRY_AUTH="+exportRegAuthConfig, "--network", exportRegNetwork, - "--volume", fmt.Sprintf("%s:/cache/committed", cacheDir), + "--volume", fmt.Sprintf("%s:/cache", cacheDir), ), h.WithArgs(exportArgs...), ) + h.AssertStringContains(t, output, "Skipping reuse for layer corrupted_buildpack:corrupted-layer: expected layer contents to have SHA 'sha256:258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59'; found 'sha256:9e0b77ed599eafdab8611f7eeefef084077f91f02f1da0a3870c7ff20a08bee8'") h.AssertStringContains(t, output, "Saving "+exportedImageName) h.Run(t, exec.Command("docker", "pull", exportedImageName)) defer h.Run(t, exec.Command("docker", "image", "rm", exportedImageName)) diff --git a/acceptance/testdata/exporter/cache-dir/committed/sha256:258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar b/acceptance/testdata/exporter/cache-dir/committed/sha256_258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar similarity index 100% rename from acceptance/testdata/exporter/cache-dir/committed/sha256:258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar rename to acceptance/testdata/exporter/cache-dir/committed/sha256_258dfa0cc987efebc17559694866ebc91139e7c0e574f60d1d4092f53d7dff59.tar diff --git a/acceptance/testdata/restorer/Dockerfile b/acceptance/testdata/restorer/Dockerfile index f676cb75e..a176ba1b7 100644 --- a/acceptance/testdata/restorer/Dockerfile +++ b/acceptance/testdata/restorer/Dockerfile @@ -8,12 +8,10 @@ ENV CNB_GROUP_ID=${cnb_gid} COPY ./container/ / -# turn /to_cache/ directories into cache tarballs -# these are referenced by sha in /cache/committed/io.buildpacks.lifecycle.cache.metadata -RUN tar cvf /cache/committed/sha256:2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar -C /to_cache/cacher_buildpack layers -RUN tar cvf /cache/committed/sha256:58bafa1e79c8e44151141c95086beb37ca85b69578fc890bce33bb4c6c8e851f.tar -C /to_cache/unused_buildpack layers -# this layer has the wrong sha to mimic corrupted data -RUN tar cvf /cache/committed/sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c.tar -C /to_cache/corrupted_buildpack layers +# We have to pre-create the tar files so that their digests do not change due to timestamps +# But, ':' in the filepath on Windows is not allowed +RUN mv /cache/committed/sha256_2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar /cache/committed/sha256:2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar +RUN mv /cache/committed/sha256_430338f576c11e5236669f9c843599d96afe28784cffcb2d46ddb07beb00df78.tar /cache/committed/sha256:430338f576c11e5236669f9c843599d96afe28784cffcb2d46ddb07beb00df78.tar ENTRYPOINT ["/cnb/lifecycle/restorer"] diff --git a/acceptance/testdata/restorer/container/cache/committed/io.buildpacks.lifecycle.cache.metadata b/acceptance/testdata/restorer/container/cache/committed/io.buildpacks.lifecycle.cache.metadata index b94d82c76..51c7edd77 100644 --- a/acceptance/testdata/restorer/container/cache/committed/io.buildpacks.lifecycle.cache.metadata +++ b/acceptance/testdata/restorer/container/cache/committed/io.buildpacks.lifecycle.cache.metadata @@ -31,7 +31,7 @@ "version": "v1", "layers": { "cached-layer": { - "sha": "sha256:58bafa1e79c8e44151141c95086beb37ca85b69578fc890bce33bb4c6c8e851f", + "sha": "sha256:430338f576c11e5236669f9c843599d96afe28784cffcb2d46ddb07beb00df78", "data": null, "build": false, "launch": false, diff --git a/acceptance/testdata/restorer/container/cache/committed/sha256_2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar b/acceptance/testdata/restorer/container/cache/committed/sha256_2d9c9c638d5c4f0df067eeae7b9c99ad05776a89d19ab863c28850a91e5f2944.tar new file mode 100644 index 0000000000000000000000000000000000000000..2dae6cc55dbd0bba0440c01d9e25848a1fac3ac0 GIT binary patch literal 10240 zcmeIy-3o#*9Eaf@cNN}1G;<%96HA36!SLgtyKh=SiJ@SI(Yuq$=5##2{g=5*T9g|x zXOq5Jtwq!O*6rJ|P#GJB(ni_}=^u;{fu3_yk8jsy<%%E>MV?oWvA%w2zHiMBjAgg{ zV;3LNVz;l4S#oyq>7xgt33xbvE49+r8s+m>kqXKG8^`Be{_TNC*6sAv!!R!Y=lVBB zZ^?f#`6sS&6E@T2Z)DEIri8yo5$%@3{lfwAI} zf3s_<+%H$nrtk-sZC`pI+JK+SUnyzH{}adOUjCWO*13<*(^C(_^Z6T_O7j1j{JpE) zgw3@18>RYnzq^-mk&4^;AF4(8|K)^lj$Zob_5V`%