exports: require caller to request frontend-based naming, by passing name of `%s`.

Signed-off-by: Ian Campbell <ijc@docker.com>
docker-18.09
Ian Campbell 2018-08-30 14:52:19 +01:00
parent fa39d134ee
commit 8d114533c2
3 changed files with 13 additions and 7 deletions

View File

@ -46,7 +46,7 @@ func TestClientIntegration(t *testing.T) {
testUser, testUser,
testOCIExporter, testOCIExporter,
testWhiteoutParentDir, testWhiteoutParentDir,
testFrontendImageNameTemplating, testFrontendImageNaming,
testDuplicateWhiteouts, testDuplicateWhiteouts,
testSchema1Image, testSchema1Image,
testMountWithNoSource, testMountWithNoSource,
@ -114,7 +114,7 @@ func testNetworkMode(t *testing.T, sb integration.Sandbox) {
require.Contains(t, err.Error(), "network.host is not allowed") require.Contains(t, err.Error(), "network.host is not allowed")
} }
func testFrontendImageNameTemplating(t *testing.T, sb integration.Sandbox) { func testFrontendImageNaming(t *testing.T, sb integration.Sandbox) {
requiresLinux(t) requiresLinux(t)
t.Parallel() t.Parallel()
c, err := New(context.TODO(), sb.Address()) c, err := New(context.TODO(), sb.Address())
@ -224,7 +224,10 @@ func testFrontendImageNameTemplating(t *testing.T, sb integration.Sandbox) {
if winner == "ctrl" { if winner == "ctrl" {
feName = "loser:latest" feName = "loser:latest"
so.ExporterAttrs["name"] = imageName so.ExporterAttrs["name"] = imageName
} else {
so.ExporterAttrs["name"] = "%s"
} }
frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) { frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
res := gateway.NewResult() res := gateway.NewResult()
res.AddMeta("image.name", []byte(feName)) res.AddMeta("image.name", []byte(feName))

View File

@ -115,7 +115,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest) e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest)
}() }()
if n, ok := src.Metadata["image.name"]; e.targetName == "" && ok { if n, ok := src.Metadata["image.name"]; e.targetName == "%s" && ok {
e.targetName = string(n) e.targetName = string(n)
} }

View File

@ -72,9 +72,12 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
for k, v := range opt { for k, v := range opt {
switch k { switch k {
case keyImageName: case keyImageName:
i.name, err = normalize(v) i.name = v
if err != nil { if i.name != "%s" {
return nil, err i.name, err = normalize(i.name)
if err != nil {
return nil, err
}
} }
case ociTypes: case ociTypes:
ot = new(bool) ot = new(bool)
@ -138,7 +141,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
} }
desc.Annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339) desc.Annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339)
if n, ok := src.Metadata["image.name"]; e.name == "" && ok { if n, ok := src.Metadata["image.name"]; e.name == "%s" && ok {
if e.name, err = normalize(string(n)); err != nil { if e.name, err = normalize(string(n)); err != nil {
return nil, err return nil, err
} }