Skip to content

Commit

Permalink
Fix content not found with push=true,rewrite-timestamp=true
Browse files Browse the repository at this point in the history
Fix issue 4793

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Jun 10, 2024
1 parent 064e35a commit 8a7cb9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
13 changes: 1 addition & 12 deletions exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
}
}
if e.push {
if opts.RewriteTimestamp {
annotations := map[digest.Digest]map[string]string{}
addAnnotations(annotations, *desc)
// e.pushImage cannot be used because src ref does not point to the rewritten image
//
// TODO: change e.pushImage so that it takes Result[Remote] as parameter.
// https://github.com/moby/buildkit/pull/4057#discussion_r1324106088
err = push.Push(ctx, e.opt.SessionManager, sessionID, e.opt.ImageWriter.opt.ContentStore, e.opt.ImageWriter.ContentStore(),
desc.Digest, targetName, e.insecure, e.opt.RegistryHosts, e.pushByDigest, annotations)
} else {
err = e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
}
err = e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to push %v", targetName)
}
Expand Down
24 changes: 20 additions & 4 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func TestIntegration(t *testing.T) {
// Only use the amd64 digest, regardless to the host platform
integration.WithMirroredImages(map[string]string{
"amd64/bullseye-20230109-slim:latest": "docker.io/amd64/debian:bullseye-20230109-slim@sha256:1acb06a0c31fb467eb8327ad361f1091ab265e0bf26d452dea45dcb0c0ea5e75",
"amd64/bullseye-20230109:latest": "docker.io/amd64/debian:bullseye-20230109@sha256:640e07a7971e0c13eb14214421cf3d75407e0965b84430e08ec90c336537a2cf",
}),
)...)
}
Expand Down Expand Up @@ -6882,6 +6883,7 @@ func testReproSourceDateEpoch(t *testing.T, sb integration.Sandbox) {
dockerfile string
files []fstest.Applier
expectedDigest string
noCacheExport bool
}
testCases := []testCase{
{
Expand Down Expand Up @@ -6909,6 +6911,15 @@ COPY --link foo foo
files: []fstest.Applier{fstest.CreateFile("foo", []byte("foo"), 0600)},
expectedDigest: "sha256:9f75e4bdbf3d825acb36bb603ddef4a25742afb8ccb674763ffc611ae047d8a6",
},
{
// https://github.com/moby/buildkit/issues/4793
name: "DanglingStage",
dockerfile: `FROM amd64/debian:bullseye-20230109 AS dangling
FROM amd64/debian:bullseye-20230109-slim
`,
expectedDigest: "sha256:eeba8ef81dec46359d099c5d674009da54e088fa8f29945d4d7fb3a7a88c450e",
noCacheExport: true, // "skipping cache export for empty result"
},
}

// https://explore.ggcr.dev/?image=amd64%2Fdebian%3Abullseye-20230109-slim
Expand Down Expand Up @@ -6968,7 +6979,10 @@ COPY --link foo foo
require.NoError(t, err)

desc, manifest, img := readImage(t, ctx, target)
_, cacheManifest, _ := readImage(t, ctx, target+"-cache")
var cacheManifest ocispecs.Manifest
if !tc.noCacheExport {
_, cacheManifest, _ = readImage(t, ctx, target+"-cache")
}
t.Log("The digest may change depending on the BuildKit version, the snapshotter configuration, etc.")
require.Equal(t, tc.expectedDigest, desc.Digest.String())

Expand All @@ -6986,9 +7000,11 @@ COPY --link foo foo
require.Equal(t, fmt.Sprintf("%d", tm.Unix()), l.Annotations["buildkit/rewritten-timestamp"])
}
}
// Cache layers must *not* have rewritten-timestamp
for _, l := range cacheManifest.Layers {
require.Empty(t, l.Annotations["buildkit/rewritten-timestamp"])
if !tc.noCacheExport {
// Cache layers must *not* have rewritten-timestamp
for _, l := range cacheManifest.Layers {
require.Empty(t, l.Annotations["buildkit/rewritten-timestamp"])
}
}

// Build again, after pruning the base image layer cache.
Expand Down

0 comments on commit 8a7cb9c

Please sign in to comment.