exporter: update export signature

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-07-10 11:05:22 -07:00
parent 5098434f33
commit d70d816dee
5 changed files with 36 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/util/push"
@ -100,7 +99,9 @@ func (e *imageExporterInstance) Name() string {
return "exporting to image"
}
func (e *imageExporterInstance) Export(ctx context.Context, ref cache.ImmutableRef, opt map[string][]byte) (map[string]string, error) {
func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source) (map[string]string, error) {
ref := src.Ref
opt := src.Metadata
if config, ok := opt[exporterImageConfig]; ok {
e.config = config
}

View File

@ -12,5 +12,11 @@ type Exporter interface {
type ExporterInstance interface {
Name() string
Export(context.Context, cache.ImmutableRef, map[string][]byte) (map[string]string, error)
Export(context.Context, Source) (map[string]string, error)
}
type Source struct {
Ref cache.ImmutableRef
Refs map[string]cache.ImmutableRef
Metadata map[string][]byte
}

View File

@ -6,7 +6,6 @@ import (
"os"
"time"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync"
@ -58,7 +57,8 @@ func (e *localExporterInstance) Name() string {
return "exporting to client"
}
func (e *localExporterInstance) Export(ctx context.Context, ref cache.ImmutableRef, opt map[string][]byte) (map[string]string, error) {
func (e *localExporterInstance) Export(ctx context.Context, inp exporter.Source) (map[string]string, error) {
ref := inp.Ref
var src string
var err error
if ref == nil {

View File

@ -8,7 +8,6 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/images/oci"
"github.com/docker/distribution/reference"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage"
"github.com/moby/buildkit/session"
@ -106,7 +105,9 @@ func (e *imageExporterInstance) Name() string {
return "exporting to oci image format"
}
func (e *imageExporterInstance) Export(ctx context.Context, ref cache.ImmutableRef, opt map[string][]byte) (map[string]string, error) {
func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source) (map[string]string, error) {
ref := src.Ref
opt := src.Metadata
if config, ok := opt[exporterImageConfig]; ok {
e.config = config
}

View File

@ -100,17 +100,34 @@ func (s *Solver) Solve(ctx context.Context, id string, req frontend.SolveRequest
var exporterResponse map[string]string
if exp := exp.Exporter; exp != nil {
var immutable cache.ImmutableRef
if res := res.Ref; res != nil { // FIXME(tonistiigi):
inp := exporter.Source{
Metadata: res.Metadata,
}
if res := res.Ref; res != nil {
workerRef, ok := res.Sys().(*worker.WorkerRef)
if !ok {
return nil, errors.Errorf("invalid reference: %T", res.Sys())
}
immutable = workerRef.ImmutableRef
inp.Ref = workerRef.ImmutableRef
}
if res.Refs != nil {
m := make(map[string]cache.ImmutableRef, len(res.Refs))
for k, res := range res.Refs {
if res == nil {
m[k] = nil
} else {
workerRef, ok := res.Sys().(*worker.WorkerRef)
if !ok {
return nil, errors.Errorf("invalid reference: %T", res.Sys())
}
m[k] = workerRef.ImmutableRef
}
}
inp.Refs = m
}
if err := j.Call(ctx, exp.Name(), func(ctx context.Context) error {
exporterResponse, err = exp.Export(ctx, immutable, res.Metadata)
exporterResponse, err = exp.Export(ctx, inp)
return err
}); err != nil {
return nil, err