Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -126,7 +126,7 @@ func (is *imageSource) ResolveImageConfig(ctx context.Context, ref string) (dige |
| 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, "") |
|
| 129 |
+ dgst, dt, err := imageutil.Config(ctx, ref, is.getResolver(ctx), is.ContentStore, nil) |
|
| 130 | 130 |
if err != nil {
|
| 131 | 131 |
return nil, err |
| 132 | 132 |
} |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"time" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/containerd/containerd/content" |
| 13 |
+ "github.com/containerd/containerd/platforms" |
|
| 13 | 14 |
"github.com/containerd/containerd/rootfs" |
| 14 | 15 |
"github.com/docker/docker/distribution" |
| 15 | 16 |
distmetadata "github.com/docker/docker/distribution/metadata" |
| ... | ... |
@@ -122,6 +123,12 @@ func (w *Worker) Labels() map[string]string {
|
| 122 | 122 |
return w.Opt.Labels |
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 |
+// Platforms returns one or more platforms supported by the image. |
|
| 126 |
+func (w *Worker) Platforms() []ocispec.Platform {
|
|
| 127 |
+ // does not handle lcow |
|
| 128 |
+ return []ocispec.Platform{platforms.DefaultSpec()}
|
|
| 129 |
+} |
|
| 130 |
+ |
|
| 125 | 131 |
// LoadRef loads a reference by ID |
| 126 | 132 |
func (w *Worker) LoadRef(id string) (cache.ImmutableRef, error) {
|
| 127 | 133 |
return w.CacheManager.Get(context.TODO(), id) |
| ... | ... |
@@ -129,26 +136,27 @@ func (w *Worker) LoadRef(id string) (cache.ImmutableRef, error) {
|
| 129 | 129 |
|
| 130 | 130 |
// ResolveOp converts a LLB vertex into a LLB operation |
| 131 | 131 |
func (w *Worker) ResolveOp(v solver.Vertex, s frontend.FrontendLLBBridge) (solver.Op, error) {
|
| 132 |
- switch op := v.Sys().(type) {
|
|
| 133 |
- case *pb.Op_Source: |
|
| 134 |
- return ops.NewSourceOp(v, op, w.SourceManager, w) |
|
| 135 |
- case *pb.Op_Exec: |
|
| 136 |
- return ops.NewExecOp(v, op, w.CacheManager, w.MetadataStore, w.Executor, w) |
|
| 137 |
- case *pb.Op_Build: |
|
| 138 |
- return ops.NewBuildOp(v, op, s, w) |
|
| 139 |
- default: |
|
| 140 |
- return nil, errors.Errorf("could not resolve %v", v)
|
|
| 132 |
+ if baseOp, ok := v.Sys().(*pb.Op); ok {
|
|
| 133 |
+ switch op := baseOp.Op.(type) {
|
|
| 134 |
+ case *pb.Op_Source: |
|
| 135 |
+ return ops.NewSourceOp(v, op, baseOp.Platform, w.SourceManager, w) |
|
| 136 |
+ case *pb.Op_Exec: |
|
| 137 |
+ return ops.NewExecOp(v, op, w.CacheManager, w.MetadataStore, w.Executor, w) |
|
| 138 |
+ case *pb.Op_Build: |
|
| 139 |
+ return ops.NewBuildOp(v, op, s, w) |
|
| 140 |
+ } |
|
| 141 | 141 |
} |
| 142 |
+ return nil, errors.Errorf("could not resolve %v", v)
|
|
| 142 | 143 |
} |
| 143 | 144 |
|
| 144 | 145 |
// ResolveImageConfig returns image config for an image |
| 145 |
-func (w *Worker) ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) {
|
|
| 146 |
+func (w *Worker) ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) {
|
|
| 146 | 147 |
// ImageSource is typically source/containerimage |
| 147 | 148 |
resolveImageConfig, ok := w.ImageSource.(resolveImageConfig) |
| 148 | 149 |
if !ok {
|
| 149 | 150 |
return "", nil, errors.Errorf("worker %q does not implement ResolveImageConfig", w.ID())
|
| 150 | 151 |
} |
| 151 |
- return resolveImageConfig.ResolveImageConfig(ctx, ref) |
|
| 152 |
+ return resolveImageConfig.ResolveImageConfig(ctx, ref, platform) |
|
| 152 | 153 |
} |
| 153 | 154 |
|
| 154 | 155 |
// Exec executes a process directly on a worker |
| ... | ... |
@@ -319,5 +327,5 @@ func oneOffProgress(ctx context.Context, id string) func(err error) error {
|
| 319 | 319 |
} |
| 320 | 320 |
|
| 321 | 321 |
type resolveImageConfig interface {
|
| 322 |
- ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) |
|
| 322 |
+ ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) |
|
| 323 | 323 |
} |
| ... | ... |
@@ -152,12 +152,23 @@ func (d *dispatchRequest) getImageMount(imageRefOrID string) (*imageMount, error |
| 152 | 152 |
// |
| 153 | 153 |
func initializeStage(d dispatchRequest, cmd *instructions.Stage) error {
|
| 154 | 154 |
d.builder.imageProber.Reset() |
| 155 |
- //TODO(@arm64b): Leave the sanity check of the spec platform to the containerd code |
|
| 156 |
- if err := platforms.ValidatePlatform(&cmd.Platform); err != nil {
|
|
| 157 |
- return err |
|
| 158 |
- } |
|
| 159 | 155 |
|
| 160 |
- image, err := d.getFromImage(d.shlex, cmd.BaseName, cmd.Platform.OS) |
|
| 156 |
+ // TODO: pass *platform instead, allow autodetect |
|
| 157 |
+ platform := platforms.DefaultSpec() |
|
| 158 |
+ if v := cmd.Platform; v != "" {
|
|
| 159 |
+ // TODO: |
|
| 160 |
+ // v, err := shlex.ProcessWord(v, toEnvList(metaArgs, nil)) |
|
| 161 |
+ // if err != nil {
|
|
| 162 |
+ // return nil, nil, errors.Wrapf(err, "failed to process arguments for platform %s", v) |
|
| 163 |
+ // } |
|
| 164 |
+ |
|
| 165 |
+ p, err := platforms.Parse(v) |
|
| 166 |
+ if err != nil {
|
|
| 167 |
+ return errors.Wrapf(err, "failed to parse platform %s", v) |
|
| 168 |
+ } |
|
| 169 |
+ platform = p |
|
| 170 |
+ } |
|
| 171 |
+ image, err := d.getFromImage(d.shlex, cmd.BaseName, platform.OS) |
|
| 161 | 172 |
if err != nil {
|
| 162 | 173 |
return err |
| 163 | 174 |
} |