Skip to content

Commit cbe4cf0

Browse files
committed
exporter: export ref name in oci tarball
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 8c9d66f commit cbe4cf0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

client/client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
280280
defer os.RemoveAll(destDir)
281281

282282
out := filepath.Join(destDir, "out.tar")
283+
target := "docker.io/buildkit/testoci:latest"
283284

284285
err = c.Solve(context.TODO(), def, SolveOpt{
285286
Exporter: ExporterOCI,
286287
ExporterAttrs: map[string]string{
287288
"output": out,
289+
"name": target,
288290
},
289291
}, nil)
290292
require.NoError(t, err)
@@ -308,6 +310,7 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
308310
err = json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].data, &mfst)
309311
require.NoError(t, err)
310312
require.Equal(t, 2, len(mfst.Layers))
313+
require.Equal(t, target, index.Manifests[0].Annotations["org.opencontainers.image.ref.name"])
311314

312315
var ociimg ocispec.Image
313316
err = json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].data, &ociimg)

exporter/oci/export.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111
"github.com/moby/buildkit/session"
1212
"github.com/moby/buildkit/session/filesync"
1313
"github.com/moby/buildkit/util/progress"
14+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1415
"github.com/sirupsen/logrus"
1516
"golang.org/x/net/context"
1617
)
1718

1819
const (
1920
exporterImageConfig = "containerimage.config"
21+
keyImageName = "name"
2022
)
2123

2224
type Opt struct {
@@ -52,6 +54,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
5254
switch k {
5355
case exporterImageConfig:
5456
i.config = []byte(v)
57+
case keyImageName:
58+
i.name = v
5559
default:
5660
logrus.Warnf("oci exporter: unknown option %s", k)
5761
}
@@ -63,6 +67,7 @@ type imageExporterInstance struct {
6367
*imageExporter
6468
config []byte
6569
caller session.Caller
70+
name string
6671
}
6772

6873
func (e *imageExporterInstance) Name() string {
@@ -77,6 +82,13 @@ func (e *imageExporterInstance) Export(ctx context.Context, ref cache.ImmutableR
7782
if err != nil {
7883
return err
7984
}
85+
if desc.Annotations == nil {
86+
desc.Annotations = map[string]string{}
87+
}
88+
desc.Annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339)
89+
if e.name != "" {
90+
desc.Annotations[ocispec.AnnotationRefName] = e.name
91+
}
8092

8193
w, err := filesync.CopyFileWriter(ctx, e.caller)
8294
if err != nil {

0 commit comments

Comments
 (0)