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) {
|
ExporterDocker: func(out, imageName string, exporterResponse map[string]string) {
|
||||||
require.Contains(t, exporterResponse, "image.name")
|
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)
|
dt, err := ioutil.ReadFile(out)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package oci
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
|
@ -73,12 +74,6 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
switch k {
|
switch k {
|
||||||
case keyImageName:
|
case keyImageName:
|
||||||
i.name = v
|
i.name = v
|
||||||
if i.name != "*" {
|
|
||||||
i.name, err = normalize(i.name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ociTypes:
|
case ociTypes:
|
||||||
ot = new(bool)
|
ot = new(bool)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
@ -144,9 +139,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source)
|
||||||
resp := make(map[string]string)
|
resp := make(map[string]string)
|
||||||
|
|
||||||
if n, ok := src.Metadata["image.name"]; e.name == "*" && ok {
|
if n, ok := src.Metadata["image.name"]; e.name == "*" && ok {
|
||||||
if e.name, err = normalize(string(n)); err != nil {
|
e.name = string(n)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.name != "" {
|
if e.name != "" {
|
||||||
|
@ -195,7 +188,16 @@ func getExporter(variant ExporterVariant, name string) (images.Exporter, error)
|
||||||
}
|
}
|
||||||
return oci.ResolveV1ExportOpt(oci.WithAllPlatforms(true))
|
return oci.ResolveV1ExportOpt(oci.WithAllPlatforms(true))
|
||||||
case VariantDocker:
|
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:
|
default:
|
||||||
return nil, errors.Errorf("invalid variant %q", variant)
|
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
|
// 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
|
// The output tarball is also compatible with OCI Image Format Specification
|
||||||
type DockerExporter struct {
|
type DockerExporter struct {
|
||||||
Name string
|
Names []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ images.Exporter = &DockerExporter{}
|
var _ images.Exporter = &DockerExporter{}
|
||||||
|
@ -30,7 +30,7 @@ func (de *DockerExporter) Export(ctx context.Context, store content.Provider, de
|
||||||
tw := tar.NewWriter(writer)
|
tw := tar.NewWriter(writer)
|
||||||
defer tw.Close()
|
defer tw.Close()
|
||||||
|
|
||||||
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Name)
|
dockerManifest, err := dockerManifestRecord(ctx, store, desc, de.Names)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ type tarRecord struct {
|
||||||
CopyTo func(context.Context, io.Writer) (int64, error)
|
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 {
|
switch desc.MediaType {
|
||||||
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
|
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
|
||||||
p, err := content.ReadBlob(ctx, provider, desc)
|
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()))
|
item.Layers = append(item.Layers, path.Join("blobs", l.Digest.Algorithm().String(), l.Digest.Hex()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name != "" {
|
if len(names) > 0 {
|
||||||
item.RepoTags = append(item.RepoTags, name)
|
item.RepoTags = names
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, err := json.Marshal([]mfstItem{item})
|
dt, err := json.Marshal([]mfstItem{item})
|
||||||
|
|
Loading…
Reference in New Issue