Skip to content

Commit 5642608

Browse files
authored
Merge pull request moby#5008 from AkihiroSuda/fix-4793
Fix content not found with `push=true,rewrite-timestamp=true`
2 parents ec2f4e2 + 8bd3dd8 commit 5642608

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

exporter/containerimage/export.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
338338
}
339339
}
340340
if e.push {
341-
if opts.RewriteTimestamp {
342-
annotations := map[digest.Digest]map[string]string{}
343-
addAnnotations(annotations, *desc)
344-
// e.pushImage cannot be used because src ref does not point to the rewritten image
345-
//
346-
// TODO: change e.pushImage so that it takes Result[Remote] as parameter.
347-
// https://github.com/moby/buildkit/pull/4057#discussion_r1324106088
348-
err = push.Push(ctx, e.opt.SessionManager, sessionID, e.opt.ImageWriter.opt.ContentStore, e.opt.ImageWriter.ContentStore(),
349-
desc.Digest, targetName, e.insecure, e.opt.RegistryHosts, e.pushByDigest, annotations)
350-
} else {
351-
err = e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
352-
}
341+
err = e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
353342
if err != nil {
354343
return nil, nil, errors.Wrapf(err, "failed to push %v", targetName)
355344
}

frontend/dockerfile/dockerfile_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6882,6 +6882,7 @@ func testReproSourceDateEpoch(t *testing.T, sb integration.Sandbox) {
68826882
dockerfile string
68836883
files []fstest.Applier
68846884
expectedDigest string
6885+
noCacheExport bool
68856886
}
68866887
testCases := []testCase{
68876888
{
@@ -6909,6 +6910,14 @@ COPY --link foo foo
69096910
files: []fstest.Applier{fstest.CreateFile("foo", []byte("foo"), 0600)},
69106911
expectedDigest: "sha256:9f75e4bdbf3d825acb36bb603ddef4a25742afb8ccb674763ffc611ae047d8a6",
69116912
},
6913+
{
6914+
// https://github.com/moby/buildkit/issues/4793
6915+
name: "NoAdditionalLayer",
6916+
dockerfile: `FROM amd64/debian:bullseye-20230109-slim
6917+
`,
6918+
expectedDigest: "sha256:eeba8ef81dec46359d099c5d674009da54e088fa8f29945d4d7fb3a7a88c450e",
6919+
noCacheExport: true, // "skipping cache export for empty result"
6920+
},
69126921
}
69136922

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

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

@@ -6986,9 +6998,11 @@ COPY --link foo foo
69866998
require.Equal(t, fmt.Sprintf("%d", tm.Unix()), l.Annotations["buildkit/rewritten-timestamp"])
69876999
}
69887000
}
6989-
// Cache layers must *not* have rewritten-timestamp
6990-
for _, l := range cacheManifest.Layers {
6991-
require.Empty(t, l.Annotations["buildkit/rewritten-timestamp"])
7001+
if !tc.noCacheExport {
7002+
// Cache layers must *not* have rewritten-timestamp
7003+
for _, l := range cacheManifest.Layers {
7004+
require.Empty(t, l.Annotations["buildkit/rewritten-timestamp"])
7005+
}
69927006
}
69937007

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

0 commit comments

Comments
 (0)