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,
testOCIExporter,
testWhiteoutParentDir,
testFrontendImageNameTemplating,
testFrontendImageNaming,
testDuplicateWhiteouts,
testSchema1Image,
testMountWithNoSource,
@ -114,7 +114,7 @@ func testNetworkMode(t *testing.T, sb integration.Sandbox) {
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)
t.Parallel()
c, err := New(context.TODO(), sb.Address())
@ -224,7 +224,10 @@ func testFrontendImageNameTemplating(t *testing.T, sb integration.Sandbox) {
if winner == "ctrl" {
feName = "loser:latest"
so.ExporterAttrs["name"] = imageName
} else {
so.ExporterAttrs["name"] = "%s"
}
frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
res := gateway.NewResult()
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)
}()
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)
}

View File

@ -72,9 +72,12 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
for k, v := range opt {
switch k {
case keyImageName:
i.name, err = normalize(v)
if err != nil {
return nil, err
i.name = v
if i.name != "%s" {
i.name, err = normalize(i.name)
if err != nil {
return nil, err
}
}
case ociTypes:
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)
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 {
return nil, err
}