From f4a67d7e9cb5391bc8c7b0610be3dc50a597d23a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 15 Jul 2021 20:42:30 +0200 Subject: [PATCH] Exporter config digest typo Signed-off-by: CrazyMax --- client/client_test.go | 17 +++++++++-------- cmd/buildctl/build_test.go | 3 ++- exporter/containerimage/export.go | 7 ++++--- exporter/containerimage/exptypes/types.go | 11 ++++++++--- exporter/containerimage/writer.go | 2 +- exporter/oci/export.go | 9 +++++---- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 8ec5da8a..9f9c3449 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -31,6 +31,7 @@ import ( "github.com/containerd/containerd/snapshots" "github.com/containerd/continuity/fs/fstest" "github.com/moby/buildkit/client/llb" + "github.com/moby/buildkit/exporter/containerimage/exptypes" gateway "github.com/moby/buildkit/frontend/gateway/client" "github.com/moby/buildkit/identity" "github.com/moby/buildkit/session" @@ -591,10 +592,10 @@ func testPushByDigest(t *testing.T, sb integration.Sandbox) { _, _, err = contentutil.ProviderFromRef(name + ":latest") require.Error(t, err) - desc, _, err := contentutil.ProviderFromRef(name + "@" + resp.ExporterResponse["containerimage.digest"]) + desc, _, err := contentutil.ProviderFromRef(name + "@" + resp.ExporterResponse[exptypes.ExporterImageDigestKey]) require.NoError(t, err) - require.Equal(t, resp.ExporterResponse["containerimage.digest"], desc.Digest.String()) + require.Equal(t, resp.ExporterResponse[exptypes.ExporterImageDigestKey], desc.Digest.String()) require.Equal(t, images.MediaTypeDockerSchema2Manifest, desc.MediaType) require.True(t, desc.Size > 0) } @@ -1861,19 +1862,19 @@ func testExporterTargetExists(t *testing.T, sb integration.Sandbox) { Type: ExporterOCI, Attrs: map[string]string{}, Output: func(m map[string]string) (io.WriteCloser, error) { - mdDgst = m["containerimage.digest"] + mdDgst = m[exptypes.ExporterImageDigestKey] return nil, nil }, }, }, }, nil) require.NoError(t, err) - dgst := res.ExporterResponse["containerimage.digest"] + dgst := res.ExporterResponse[exptypes.ExporterImageDigestKey] require.True(t, strings.HasPrefix(dgst, "sha256:")) require.Equal(t, dgst, mdDgst) - require.True(t, strings.HasPrefix(res.ExporterResponse["containerimage.config.digest"], "sha256:")) + require.True(t, strings.HasPrefix(res.ExporterResponse[exptypes.ExporterImageConfigDigestKey], "sha256:")) } func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) { @@ -2792,7 +2793,7 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) { }, nil) require.NoError(t, err) - dgst, ok := resp.ExporterResponse["containerimage.digest"] + dgst, ok := resp.ExporterResponse[exptypes.ExporterImageDigestKey] require.Equal(t, ok, true) unique, err := readFileInImage(sb.Context(), c, target+"@"+dgst, "/unique") @@ -2831,7 +2832,7 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) { }, nil) require.NoError(t, err) - dgst2, ok := resp.ExporterResponse["containerimage.digest"] + dgst2, ok := resp.ExporterResponse[exptypes.ExporterImageDigestKey] require.Equal(t, ok, true) require.Equal(t, dgst, dgst2) @@ -2862,7 +2863,7 @@ func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) { }, nil) require.NoError(t, err) - dgst3, ok := resp.ExporterResponse["containerimage.digest"] + dgst3, ok := resp.ExporterResponse[exptypes.ExporterImageDigestKey] require.Equal(t, ok, true) // dgst3 != dgst, because inline cache is not exported for dgst3 diff --git a/cmd/buildctl/build_test.go b/cmd/buildctl/build_test.go index 6b5ccfb3..7df12f12 100644 --- a/cmd/buildctl/build_test.go +++ b/cmd/buildctl/build_test.go @@ -17,6 +17,7 @@ import ( "github.com/containerd/containerd/namespaces" "github.com/containerd/continuity/fs/fstest" "github.com/moby/buildkit/client/llb" + "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/util/testutil/integration" "github.com/stretchr/testify/require" ) @@ -147,7 +148,7 @@ func testBuildMetadataFile(t *testing.T, sb integration.Sandbox) { require.Equal(t, imageName, metadata["image.name"]) - digest := metadata["containerimage.digest"] + digest := metadata[exptypes.ExporterImageDigestKey] require.NotEmpty(t, digest) cdAddress := sb.ContainerdAddress() diff --git a/exporter/containerimage/export.go b/exporter/containerimage/export.go index defdd95e..e5dc59fe 100644 --- a/exporter/containerimage/export.go +++ b/exporter/containerimage/export.go @@ -16,6 +16,7 @@ import ( "github.com/containerd/containerd/rootfs" "github.com/moby/buildkit/cache" "github.com/moby/buildkit/exporter" + "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/session" "github.com/moby/buildkit/snapshot" "github.com/moby/buildkit/util/compression" @@ -284,9 +285,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source, resp["image.name"] = e.targetName } - resp["containerimage.digest"] = desc.Digest.String() - if v, ok := desc.Annotations["config.digest"]; ok { - resp["containerimage.config.digest"] = v + resp[exptypes.ExporterImageDigestKey] = desc.Digest.String() + if v, ok := desc.Annotations[exptypes.ExporterConfigDigestKey]; ok { + resp[exptypes.ExporterImageConfigDigestKey] = v } return resp, nil } diff --git a/exporter/containerimage/exptypes/types.go b/exporter/containerimage/exptypes/types.go index b428afd0..48ab6cfb 100644 --- a/exporter/containerimage/exptypes/types.go +++ b/exporter/containerimage/exptypes/types.go @@ -5,9 +5,14 @@ import ( specs "github.com/opencontainers/image-spec/specs-go/v1" ) -const ExporterImageConfigKey = "containerimage.config" -const ExporterInlineCache = "containerimage.inlinecache" -const ExporterPlatformsKey = "refs.platforms" +const ( + ExporterConfigDigestKey = "config.digest" + ExporterImageDigestKey = "containerimage.digest" + ExporterImageConfigKey = "containerimage.config" + ExporterImageConfigDigestKey = "containerimage.config.digest" + ExporterInlineCache = "containerimage.inlinecache" + ExporterPlatformsKey = "refs.platforms" +) const EmptyGZLayer = digest.Digest("sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1") diff --git a/exporter/containerimage/writer.go b/exporter/containerimage/writer.go index d2e6825e..d7454da2 100644 --- a/exporter/containerimage/writer.go +++ b/exporter/containerimage/writer.go @@ -67,7 +67,7 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp exporter.Source, oci bool if mfstDesc.Annotations == nil { mfstDesc.Annotations = make(map[string]string) } - mfstDesc.Annotations["config.digest"] = configDesc.Digest.String() + mfstDesc.Annotations[exptypes.ExporterConfigDigestKey] = configDesc.Digest.String() return mfstDesc, nil } diff --git a/exporter/oci/export.go b/exporter/oci/export.go index 69bc8f9a..e8908796 100644 --- a/exporter/oci/export.go +++ b/exporter/oci/export.go @@ -12,6 +12,7 @@ import ( "github.com/moby/buildkit/cache" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage" + "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/session" "github.com/moby/buildkit/session/filesync" "github.com/moby/buildkit/util/compression" @@ -150,10 +151,10 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source, desc.Annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339) resp := make(map[string]string) - resp["containerimage.digest"] = desc.Digest.String() - if v, ok := desc.Annotations["config.digest"]; ok { - resp["containerimage.config.digest"] = v - delete(desc.Annotations, "config.digeest") + resp[exptypes.ExporterImageDigestKey] = desc.Digest.String() + if v, ok := desc.Annotations[exptypes.ExporterConfigDigestKey]; ok { + resp[exptypes.ExporterImageConfigDigestKey] = v + delete(desc.Annotations, exptypes.ExporterConfigDigestKey) } if n, ok := src.Metadata["image.name"]; e.name == "*" && ok {