Signed-off-by: Tibor Vass <tibor@docker.com>
| ... | ... |
@@ -27,6 +27,7 @@ import ( |
| 27 | 27 |
pkgprogress "github.com/docker/docker/pkg/progress" |
| 28 | 28 |
"github.com/docker/docker/reference" |
| 29 | 29 |
"github.com/moby/buildkit/cache" |
| 30 |
+ gw "github.com/moby/buildkit/frontend/gateway/client" |
|
| 30 | 31 |
"github.com/moby/buildkit/session" |
| 31 | 32 |
"github.com/moby/buildkit/session/auth" |
| 32 | 33 |
"github.com/moby/buildkit/source" |
| ... | ... |
@@ -113,7 +114,7 @@ func (is *imageSource) resolveLocal(refStr string) ([]byte, error) {
|
| 113 | 113 |
return img.RawJSON(), nil |
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 |
-func (is *imageSource) ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) {
|
|
| 116 |
+func (is *imageSource) ResolveImageConfig(ctx context.Context, ref string, opt gw.ResolveImageConfigOpt) (digest.Digest, []byte, error) {
|
|
| 117 | 117 |
if preferLocal {
|
| 118 | 118 |
dt, err := is.resolveLocal(ref) |
| 119 | 119 |
if err == nil {
|
| ... | ... |
@@ -126,7 +127,7 @@ func (is *imageSource) ResolveImageConfig(ctx context.Context, ref string, platf |
| 126 | 126 |
dt []byte |
| 127 | 127 |
} |
| 128 | 128 |
res, err := is.g.Do(ctx, ref, func(ctx context.Context) (interface{}, error) {
|
| 129 |
- dgst, dt, err := imageutil.Config(ctx, ref, is.getResolver(ctx), is.ContentStore, platform) |
|
| 129 |
+ dgst, dt, err := imageutil.Config(ctx, ref, is.getResolver(ctx), is.ContentStore, opt.Platform) |
|
| 130 | 130 |
if err != nil {
|
| 131 | 131 |
return nil, err |
| 132 | 132 |
} |
| ... | ... |
@@ -257,7 +258,7 @@ func (p *puller) resolve(ctx context.Context) error {
|
| 257 | 257 |
return |
| 258 | 258 |
} |
| 259 | 259 |
|
| 260 |
- _, dt, err := p.is.ResolveImageConfig(ctx, ref.String(), &p.platform) |
|
| 260 |
+ _, dt, err := p.is.ResolveImageConfig(ctx, ref.String(), gw.ResolveImageConfigOpt{Platform: &p.platform})
|
|
| 261 | 261 |
if err != nil {
|
| 262 | 262 |
p.resolveErr = err |
| 263 | 263 |
resolveProgressDone(err) |
| ... | ... |
@@ -2,6 +2,7 @@ package containerimage |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "encoding/json" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"strings" |
| 7 | 8 |
|
| ... | ... |
@@ -9,15 +10,15 @@ import ( |
| 9 | 9 |
"github.com/docker/docker/image" |
| 10 | 10 |
"github.com/docker/docker/layer" |
| 11 | 11 |
"github.com/docker/docker/reference" |
| 12 |
- "github.com/moby/buildkit/cache" |
|
| 13 | 12 |
"github.com/moby/buildkit/exporter" |
| 13 |
+ "github.com/moby/buildkit/exporter/containerimage/exptypes" |
|
| 14 | 14 |
digest "github.com/opencontainers/go-digest" |
| 15 |
+ "github.com/pkg/errors" |
|
| 15 | 16 |
"github.com/sirupsen/logrus" |
| 16 | 17 |
) |
| 17 | 18 |
|
| 18 | 19 |
const ( |
| 19 |
- keyImageName = "name" |
|
| 20 |
- exporterImageConfig = "containerimage.config" |
|
| 20 |
+ keyImageName = "name" |
|
| 21 | 21 |
) |
| 22 | 22 |
|
| 23 | 23 |
// Differ can make a moby layer from a snapshot |
| ... | ... |
@@ -54,8 +55,11 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp |
| 54 | 54 |
} |
| 55 | 55 |
i.targetNames = append(i.targetNames, ref) |
| 56 | 56 |
} |
| 57 |
- case exporterImageConfig: |
|
| 58 |
- i.config = []byte(v) |
|
| 57 |
+ case exptypes.ExporterImageConfigKey: |
|
| 58 |
+ if i.meta == nil {
|
|
| 59 |
+ i.meta = make(map[string][]byte) |
|
| 60 |
+ } |
|
| 61 |
+ i.meta[k] = []byte(v) |
|
| 59 | 62 |
default: |
| 60 | 63 |
logrus.Warnf("image exporter: unknown option %s", k)
|
| 61 | 64 |
} |
| ... | ... |
@@ -66,18 +70,47 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp |
| 66 | 66 |
type imageExporterInstance struct {
|
| 67 | 67 |
*imageExporter |
| 68 | 68 |
targetNames []distref.Named |
| 69 |
- config []byte |
|
| 69 |
+ meta map[string][]byte |
|
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
func (e *imageExporterInstance) Name() string {
|
| 73 | 73 |
return "exporting to image" |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 |
-func (e *imageExporterInstance) Export(ctx context.Context, ref cache.ImmutableRef, opt map[string][]byte) (map[string]string, error) {
|
|
| 77 |
- if config, ok := opt[exporterImageConfig]; ok {
|
|
| 78 |
- e.config = config |
|
| 76 |
+func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source) (map[string]string, error) {
|
|
| 77 |
+ |
|
| 78 |
+ if len(inp.Refs) > 1 {
|
|
| 79 |
+ return nil, fmt.Errorf("exporting multiple references to image store is currently unsupported")
|
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ ref := inp.Ref |
|
| 83 |
+ if ref != nil && len(inp.Refs) == 1 {
|
|
| 84 |
+ return nil, fmt.Errorf("invalid exporter input: Ref and Refs are mutually exclusive")
|
|
| 85 |
+ } |
|
| 86 |
+ |
|
| 87 |
+ // only one loop |
|
| 88 |
+ for _, v := range inp.Refs {
|
|
| 89 |
+ ref = v |
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 92 |
+ var config []byte |
|
| 93 |
+ switch len(inp.Refs) {
|
|
| 94 |
+ case 0: |
|
| 95 |
+ config = inp.Metadata[exptypes.ExporterImageConfigKey] |
|
| 96 |
+ case 1: |
|
| 97 |
+ platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey] |
|
| 98 |
+ if !ok {
|
|
| 99 |
+ return nil, fmt.Errorf("cannot export image, missing platforms mapping")
|
|
| 100 |
+ } |
|
| 101 |
+ var p exptypes.Platforms |
|
| 102 |
+ if err := json.Unmarshal(platformsBytes, &p); err != nil {
|
|
| 103 |
+ return nil, errors.Wrapf(err, "failed to parse platforms passed to exporter") |
|
| 104 |
+ } |
|
| 105 |
+ if len(p.Platforms) != len(inp.Refs) {
|
|
| 106 |
+ return nil, errors.Errorf("number of platforms does not match references %d %d", len(p.Platforms), len(inp.Refs))
|
|
| 107 |
+ } |
|
| 108 |
+ config = inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.Platforms[0].ID)]
|
|
| 79 | 109 |
} |
| 80 |
- config := e.config |
|
| 81 | 110 |
|
| 82 | 111 |
var diffs []digest.Digest |
| 83 | 112 |
if ref != nil {
|
| ... | ... |
@@ -24,6 +24,7 @@ import ( |
| 24 | 24 |
"github.com/moby/buildkit/executor" |
| 25 | 25 |
"github.com/moby/buildkit/exporter" |
| 26 | 26 |
"github.com/moby/buildkit/frontend" |
| 27 |
+ gw "github.com/moby/buildkit/frontend/gateway/client" |
|
| 27 | 28 |
"github.com/moby/buildkit/session" |
| 28 | 29 |
"github.com/moby/buildkit/snapshot" |
| 29 | 30 |
"github.com/moby/buildkit/solver" |
| ... | ... |
@@ -141,7 +142,7 @@ func (w *Worker) ResolveOp(v solver.Vertex, s frontend.FrontendLLBBridge) (solve |
| 141 | 141 |
case *pb.Op_Source: |
| 142 | 142 |
return ops.NewSourceOp(v, op, baseOp.Platform, w.SourceManager, w) |
| 143 | 143 |
case *pb.Op_Exec: |
| 144 |
- return ops.NewExecOp(v, op, w.CacheManager, w.MetadataStore, w.Executor, w) |
|
| 144 |
+ return ops.NewExecOp(v, op, w.CacheManager, w.Opt.SessionManager, w.MetadataStore, w.Executor, w) |
|
| 145 | 145 |
case *pb.Op_Build: |
| 146 | 146 |
return ops.NewBuildOp(v, op, s, w) |
| 147 | 147 |
} |
| ... | ... |
@@ -150,13 +151,13 @@ func (w *Worker) ResolveOp(v solver.Vertex, s frontend.FrontendLLBBridge) (solve |
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 | 152 |
// ResolveImageConfig returns image config for an image |
| 153 |
-func (w *Worker) ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) {
|
|
| 153 |
+func (w *Worker) ResolveImageConfig(ctx context.Context, ref string, opt gw.ResolveImageConfigOpt) (digest.Digest, []byte, error) {
|
|
| 154 | 154 |
// ImageSource is typically source/containerimage |
| 155 | 155 |
resolveImageConfig, ok := w.ImageSource.(resolveImageConfig) |
| 156 | 156 |
if !ok {
|
| 157 | 157 |
return "", nil, errors.Errorf("worker %q does not implement ResolveImageConfig", w.ID())
|
| 158 | 158 |
} |
| 159 |
- return resolveImageConfig.ResolveImageConfig(ctx, ref, platform) |
|
| 159 |
+ return resolveImageConfig.ResolveImageConfig(ctx, ref, opt) |
|
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
// Exec executes a process directly on a worker |
| ... | ... |
@@ -175,8 +176,8 @@ func (w *Worker) DiskUsage(ctx context.Context, opt client.DiskUsageInfo) ([]*cl |
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 | 177 |
// Prune deletes reclaimable build cache |
| 178 |
-func (w *Worker) Prune(ctx context.Context, ch chan client.UsageInfo) error {
|
|
| 179 |
- return w.CacheManager.Prune(ctx, ch) |
|
| 178 |
+func (w *Worker) Prune(ctx context.Context, ch chan client.UsageInfo, info client.PruneInfo) error {
|
|
| 179 |
+ return w.CacheManager.Prune(ctx, ch, info) |
|
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 | 182 |
// Exporter returns exporter by name |
| ... | ... |
@@ -327,5 +328,5 @@ func oneOffProgress(ctx context.Context, id string) func(err error) error {
|
| 327 | 327 |
} |
| 328 | 328 |
|
| 329 | 329 |
type resolveImageConfig interface {
|
| 330 |
- ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) |
|
| 330 |
+ ResolveImageConfig(ctx context.Context, ref string, opt gw.ResolveImageConfigOpt) (digest.Digest, []byte, error) |
|
| 331 | 331 |
} |