Skip to content

Commit

Permalink
Merge pull request #3152 from AkihiroSuda/override-annotation-image-c…
Browse files Browse the repository at this point in the history
…reated

exporter/oci: allow overriding `org.opencontainers.image.created`
  • Loading branch information
tonistiigi authored Oct 12, 2022
2 parents 0dfd726 + 6f16c6d commit 59ffd2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
34 changes: 20 additions & 14 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6179,17 +6179,20 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {

target := registry + "/buildkit/testannotations:latest"

const created = "2022-01-23T12:34:56Z"

_, err = c.Build(sb.Context(), SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterImage,
Attrs: map[string]string{
"name": target,
"push": "true",
"annotation-index.gio": "generic index opt",
"annotation-manifest.gmo": "generic manifest opt",
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
"name": target,
"push": "true",
"annotation-index.gio": "generic index opt",
"annotation-index." + ocispecs.AnnotationCreated: created,
"annotation-manifest.gmo": "generic manifest opt",
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
"annotation-manifest[linux/arm64].mo": "arm64 manifest opt",
"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
Expand All @@ -6207,6 +6210,7 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {

require.Equal(t, "generic index", imgs.Index.Annotations["gi"])
require.Equal(t, "generic index opt", imgs.Index.Annotations["gio"])
require.Equal(t, created, imgs.Index.Annotations[ocispecs.AnnotationCreated])
for _, desc := range imgs.Index.Manifests {
require.Equal(t, "generic manifest descriptor", desc.Annotations["gmd"])
require.Equal(t, "generic manifest descriptor opt", desc.Annotations["gmdo"])
Expand Down Expand Up @@ -6250,14 +6254,15 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {
Type: ExporterOCI,
Output: fixedWriteCloser(outW),
Attrs: map[string]string{
"annotation-index.gio": "generic index opt",
"annotation-index-descriptor.gido": "generic index descriptor opt",
"annotation-manifest.gmo": "generic manifest opt",
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
"annotation-manifest[linux/arm64].mo": "arm64 manifest opt",
"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
"annotation-index.gio": "generic index opt",
"annotation-index-descriptor.gido": "generic index descriptor opt",
"annotation-index-descriptor." + ocispecs.AnnotationCreated: created,
"annotation-manifest.gmo": "generic manifest opt",
"annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt",
"annotation-manifest[linux/amd64].mo": "amd64 manifest opt",
"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
"annotation-manifest[linux/arm64].mo": "arm64 manifest opt",
"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
},
},
},
Expand All @@ -6274,6 +6279,7 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) {
err = json.Unmarshal(m["index.json"].Data, &layout)
require.Equal(t, "generic index descriptor", layout.Manifests[0].Annotations["gid"])
require.Equal(t, "generic index descriptor opt", layout.Manifests[0].Annotations["gido"])
require.Equal(t, created, layout.Manifests[0].Annotations[ocispecs.AnnotationCreated])
require.NoError(t, err)

var index ocispecs.Index
Expand Down
4 changes: 3 additions & 1 deletion exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
if desc.Annotations == nil {
desc.Annotations = map[string]string{}
}
desc.Annotations[ocispecs.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339)
if _, ok := desc.Annotations[ocispecs.AnnotationCreated]; !ok {
desc.Annotations[ocispecs.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339)
}

resp := make(map[string]string)

Expand Down

0 comments on commit 59ffd2e

Please sign in to comment.