Skip to content

exporter: export ref name in oci tarball #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
defer os.RemoveAll(destDir)

out := filepath.Join(destDir, "out.tar")
target := "example.com/buildkit/testoci:latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for going back and forth, but could you add a testcase for target := "latest", as it seems the most expected value of org.opencontainers.image.ref.name. (example.com/buildkit/testoci:latest is also correct though)

Copy link
Member Author

@tonistiigi tonistiigi Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a place I can read up for this value? I would expect "target=latest" to produce either error or docker.io/library/latest:latest. (the fix for this in #228 produces the latter)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For OCI, I'd suggest not normalizing the string. i.e. target=latest should set the annotation to latest, literally.

For OCI manifest within Docker-OCI-hybrid image, I'd suggest setting the "tag" portion of the Docker-normalized name.


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

var ociimg ocispec.Image
err = json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].data, &ociimg)
Expand Down
12 changes: 12 additions & 0 deletions exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync"
"github.com/moby/buildkit/util/progress"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)

const (
exporterImageConfig = "containerimage.config"
keyImageName = "name"
)

type Opt struct {
Expand Down Expand Up @@ -52,6 +54,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
switch k {
case exporterImageConfig:
i.config = []byte(v)
case keyImageName:
i.name = v
default:
logrus.Warnf("oci exporter: unknown option %s", k)
}
Expand All @@ -63,6 +67,7 @@ type imageExporterInstance struct {
*imageExporter
config []byte
caller session.Caller
name string
}

func (e *imageExporterInstance) Name() string {
Expand All @@ -77,6 +82,13 @@ func (e *imageExporterInstance) Export(ctx context.Context, ref cache.ImmutableR
if err != nil {
return err
}
if desc.Annotations == nil {
desc.Annotations = map[string]string{}
}
desc.Annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339)
if e.name != "" {
desc.Annotations[ocispec.AnnotationRefName] = e.name
}

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