Merge pull request #295 from AkihiroSuda/reusable-docker-exporter-

exporter/oci: split reusable dockerexporter
docker-18.09
Tõnis Tiigi 2018-02-26 08:20:11 -08:00 committed by GitHub
commit 96ad291c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/moby/buildkit/exporter/containerimage" "github.com/moby/buildkit/exporter/containerimage"
"github.com/moby/buildkit/session" "github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync" "github.com/moby/buildkit/session/filesync"
"github.com/moby/buildkit/util/dockerexporter"
"github.com/moby/buildkit/util/progress" "github.com/moby/buildkit/util/progress"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -140,7 +141,7 @@ func getExporter(variant ExporterVariant, name string) (images.Exporter, error)
case VariantOCI: case VariantOCI:
return &oci.V1Exporter{}, nil return &oci.V1Exporter{}, nil
case VariantDocker: case VariantDocker:
return &DockerExporter{name: name}, nil return &dockerexporter.DockerExporter{Name: name}, nil
default: default:
return nil, errors.Errorf("invalid variant %q", variant) return nil, errors.Errorf("invalid variant %q", variant)
} }

View File

@ -1,4 +1,4 @@
package oci package dockerexporter
import ( import (
"archive/tar" "archive/tar"
@ -16,20 +16,22 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// DockerExporter implements exporting to // DockerExporter implements containerd/images.Exporter to
// Docker Combined Image JSON + Filesystem Changeset Format v1.1 // Docker Combined Image JSON + Filesystem Changeset Format v1.1
// 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 outputed tarball is also compatible wih OCI Image Format Specification // The outputed tarball is also compatible wih OCI Image Format Specification
type DockerExporter struct { type DockerExporter struct {
name string Name string
} }
var _ images.Exporter = &DockerExporter{}
// Export exports tarball into writer. // Export exports tarball into writer.
func (de *DockerExporter) Export(ctx context.Context, store content.Provider, desc ocispec.Descriptor, writer io.Writer) error { func (de *DockerExporter) Export(ctx context.Context, store content.Provider, desc ocispec.Descriptor, writer io.Writer) error {
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.Name)
if err != nil { if err != nil {
return err return err
} }