Added support for mutiple tags - docker build
Signed-off-by: hpandeycodeit <hpandey@pivotal.io>docker-19.03
parent
a67ba78d9e
commit
271f59fe60
|
@ -355,7 +355,7 @@ func testFrontendImageNaming(t *testing.T, sb integration.Sandbox) {
|
|||
},
|
||||
ExporterDocker: func(out, imageName string, exporterResponse map[string]string) {
|
||||
require.Contains(t, exporterResponse, "image.name")
|
||||
require.Equal(t, exporterResponse["image.name"], "docker.io/library/"+imageName)
|
||||
require.Equal(t, exporterResponse["image.name"], imageName)
|
||||
|
||||
dt, err := ioutil.ReadFile(out)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -3,6 +3,7 @@ package oci
|
|||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/images"
|
||||
|
@ -73,12 +74,6 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
|||
switch k {
|
||||
case keyImageName:
|
||||
i.name = v
|
||||
if i.name != "*" {
|
||||
i.name, err = normalize(i.name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
case ociTypes:
|
||||
ot = new(bool)
|
||||
if v == "" {
|
||||
|
@ -144,9 +139,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
|
|||
resp := make(map[string]string)
|
||||
|
||||
if n, ok := src.Metadata["image.name"]; e.name == "*" && ok {
|
||||
if e.name, err = normalize(string(n)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.name = string(n)
|
||||
}
|
||||
|
||||
if e.name != "" {
|
||||
|
@ -195,7 +188,16 @@ func getExporter(variant ExporterVariant, name string) (images.Exporter, error)
|
|||
}
|
||||
return oci.ResolveV1ExportOpt(oci.WithAllPlatforms(true))
|
||||
case VariantDocker:
|
||||
return &dockerexporter.DockerExporter{Name: name}, nil
|
||||
names := strings.Split(name, ",")
|
||||
var tagNames = make([]string, len(names))
|
||||
var err error
|
||||
for i, nm := range names {
|
||||
tagNames[i], err = normalize(nm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &dockerexporter.DockerExporter{Names: tagNames}, nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid variant %q", variant)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
// https://github.com/moby/moby/blob/master/image/spec/v1.1.md#combined-image-json--filesystem-changeset-format
|
||||
// The output tarball is also compatible with OCI Image Format Specification
|
||||
type DockerExporter struct {
|
||||
Name string
|
||||
Names []string
|
||||
}
|
||||
|
||||
var _ images.Exporter = &DockerExporter{}
|
||||
|
@ -30,7 +30,7 @@ func (de *DockerExporter) Export(ctx context.Context, store content.Provider, de
|
|||
tw := tar.NewWriter(writer)
|
||||
defer tw.Close()
|
||||
|
||||
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Name)
|
||||
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Names)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ type tarRecord struct {
|
|||
CopyTo func(context.Context, io.Writer) (int64, error)
|
||||
}
|
||||
|
||||
func dockerManifestRecord(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, name string) (*tarRecord, error) {
|
||||
func dockerManifestRecord(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, names []string) (*tarRecord, error) {
|
||||
switch desc.MediaType {
|
||||
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
|
||||
p, err := content.ReadBlob(ctx, provider, desc)
|
||||
|
@ -101,8 +101,9 @@ func dockerManifestRecord(ctx context.Context, provider content.Provider, desc o
|
|||
item.Layers = append(item.Layers, path.Join("blobs", l.Digest.Algorithm().String(), l.Digest.Hex()))
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
item.RepoTags = append(item.RepoTags, name)
|
||||
if len(names) > 0 {
|
||||
item.RepoTags = names
|
||||
|
||||
}
|
||||
|
||||
dt, err := json.Marshal([]mfstItem{item})
|
||||
|
|
Loading…
Reference in New Issue