From 48b93419dcc3dc71584d674f045c30793b890395 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 26 Jun 2018 11:30:19 -0700 Subject: [PATCH] builder: buildkit rebase update Signed-off-by: Tonis Tiigi --- .../adapters/containerimage/pull.go | 2 +- builder/builder-next/worker/worker.go | 32 ++++++++++++------- builder/dockerfile/dispatchers.go | 21 +++++++++--- pkg/system/lcow.go | 1 + 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/builder/builder-next/adapters/containerimage/pull.go b/builder/builder-next/adapters/containerimage/pull.go index b84d2e8589..dd23304951 100644 --- a/builder/builder-next/adapters/containerimage/pull.go +++ b/builder/builder-next/adapters/containerimage/pull.go @@ -126,7 +126,7 @@ func (is *imageSource) ResolveImageConfig(ctx context.Context, ref string) (dige dt []byte } res, err := is.g.Do(ctx, ref, func(ctx context.Context) (interface{}, error) { - dgst, dt, err := imageutil.Config(ctx, ref, is.getResolver(ctx), is.ContentStore, "") + dgst, dt, err := imageutil.Config(ctx, ref, is.getResolver(ctx), is.ContentStore, nil) if err != nil { return nil, err } diff --git a/builder/builder-next/worker/worker.go b/builder/builder-next/worker/worker.go index 28e16368ce..29e8095c32 100644 --- a/builder/builder-next/worker/worker.go +++ b/builder/builder-next/worker/worker.go @@ -10,6 +10,7 @@ import ( "time" "github.com/containerd/containerd/content" + "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/rootfs" "github.com/docker/docker/distribution" distmetadata "github.com/docker/docker/distribution/metadata" @@ -122,6 +123,12 @@ func (w *Worker) Labels() map[string]string { return w.Opt.Labels } +// Platforms returns one or more platforms supported by the image. +func (w *Worker) Platforms() []ocispec.Platform { + // does not handle lcow + return []ocispec.Platform{platforms.DefaultSpec()} +} + // LoadRef loads a reference by ID func (w *Worker) LoadRef(id string) (cache.ImmutableRef, error) { return w.CacheManager.Get(context.TODO(), id) @@ -129,26 +136,27 @@ func (w *Worker) LoadRef(id string) (cache.ImmutableRef, error) { // ResolveOp converts a LLB vertex into a LLB operation func (w *Worker) ResolveOp(v solver.Vertex, s frontend.FrontendLLBBridge) (solver.Op, error) { - switch op := v.Sys().(type) { - case *pb.Op_Source: - return ops.NewSourceOp(v, op, w.SourceManager, w) - case *pb.Op_Exec: - return ops.NewExecOp(v, op, w.CacheManager, w.MetadataStore, w.Executor, w) - case *pb.Op_Build: - return ops.NewBuildOp(v, op, s, w) - default: - return nil, errors.Errorf("could not resolve %v", v) + if baseOp, ok := v.Sys().(*pb.Op); ok { + switch op := baseOp.Op.(type) { + case *pb.Op_Source: + return ops.NewSourceOp(v, op, baseOp.Platform, w.SourceManager, w) + case *pb.Op_Exec: + return ops.NewExecOp(v, op, w.CacheManager, w.MetadataStore, w.Executor, w) + case *pb.Op_Build: + return ops.NewBuildOp(v, op, s, w) + } } + return nil, errors.Errorf("could not resolve %v", v) } // ResolveImageConfig returns image config for an image -func (w *Worker) ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) { +func (w *Worker) ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) { // ImageSource is typically source/containerimage resolveImageConfig, ok := w.ImageSource.(resolveImageConfig) if !ok { return "", nil, errors.Errorf("worker %q does not implement ResolveImageConfig", w.ID()) } - return resolveImageConfig.ResolveImageConfig(ctx, ref) + return resolveImageConfig.ResolveImageConfig(ctx, ref, platform) } // Exec executes a process directly on a worker @@ -319,5 +327,5 @@ func oneOffProgress(ctx context.Context, id string) func(err error) error { } type resolveImageConfig interface { - ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) + ResolveImageConfig(ctx context.Context, ref string, platform *ocispec.Platform) (digest.Digest, []byte, error) } diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index 65d93139f1..c30c010ece 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -152,12 +152,23 @@ func (d *dispatchRequest) getImageMount(imageRefOrID string) (*imageMount, error // func initializeStage(d dispatchRequest, cmd *instructions.Stage) error { d.builder.imageProber.Reset() - //TODO(@arm64b): Leave the sanity check of the spec platform to the containerd code - if err := platforms.ValidatePlatform(&cmd.Platform); err != nil { - return err - } - image, err := d.getFromImage(d.shlex, cmd.BaseName, cmd.Platform.OS) + // TODO: pass *platform instead, allow autodetect + platform := platforms.DefaultSpec() + if v := cmd.Platform; v != "" { + // TODO: + // v, err := shlex.ProcessWord(v, toEnvList(metaArgs, nil)) + // if err != nil { + // return nil, nil, errors.Wrapf(err, "failed to process arguments for platform %s", v) + // } + + p, err := platforms.Parse(v) + if err != nil { + return errors.Wrapf(err, "failed to parse platform %s", v) + } + platform = p + } + image, err := d.getFromImage(d.shlex, cmd.BaseName, platform.OS) if err != nil { return err } diff --git a/pkg/system/lcow.go b/pkg/system/lcow.go index 786811df74..630e973145 100644 --- a/pkg/system/lcow.go +++ b/pkg/system/lcow.go @@ -2,6 +2,7 @@ package system // import "github.com/docker/docker/pkg/system" import ( "runtime" + "strings" ) // IsOSSupported determines if an operating system is supported by the host