diff --git a/solver/llbsolver/ops/exec.go b/solver/llbsolver/ops/exec.go index 12534712..3a210d62 100644 --- a/solver/llbsolver/ops/exec.go +++ b/solver/llbsolver/ops/exec.go @@ -20,7 +20,6 @@ import ( "github.com/moby/buildkit/solver/llbsolver/errdefs" "github.com/moby/buildkit/solver/llbsolver/mounts" "github.com/moby/buildkit/solver/pb" - "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/progress/logs" utilsystem "github.com/moby/buildkit/util/system" "github.com/moby/buildkit/worker" @@ -293,8 +292,11 @@ func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Resu return nil, err } - emu, err := getEmulator(e.platform, e.cm.IdentityMapping()) - if err == nil && emu != nil { + emu, err := getEmulator(ctx, e.platform, e.cm.IdentityMapping()) + if err != nil { + return nil, err + } + if emu != nil { e.op.Meta.Args = append([]string{qemuMountName}, e.op.Meta.Args...) p.Mounts = append(p.Mounts, executor.Mount{ @@ -303,9 +305,6 @@ func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Resu Dest: qemuMountName, }) } - if err != nil { - bklog.G(ctx).Warn(err.Error()) // TODO: remove this with pull support - } meta := executor.Meta{ Args: e.op.Meta.Args, diff --git a/solver/llbsolver/ops/exec_binfmt.go b/solver/llbsolver/ops/exec_binfmt.go index 7ac7b922..56433d49 100644 --- a/solver/llbsolver/ops/exec_binfmt.go +++ b/solver/llbsolver/ops/exec_binfmt.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/containerd/containerd/mount" "github.com/containerd/containerd/platforms" @@ -13,6 +14,7 @@ import ( "github.com/moby/buildkit/snapshot" "github.com/moby/buildkit/solver/pb" "github.com/moby/buildkit/util/archutil" + "github.com/moby/buildkit/util/bklog" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" copy "github.com/tonistiigi/fsutil/copy" @@ -83,7 +85,7 @@ func (m *staticEmulatorMount) IdentityMapping() *idtools.IdentityMapping { return m.idmap } -func getEmulator(p *pb.Platform, idmap *idtools.IdentityMapping) (*emulator, error) { +func getEmulator(ctx context.Context, p *pb.Platform, idmap *idtools.IdentityMapping) (*emulator, error) { all := archutil.SupportedPlatforms(false) pp := platforms.Normalize(ocispecs.Platform{ Architecture: p.Architecture, @@ -97,6 +99,18 @@ func getEmulator(p *pb.Platform, idmap *idtools.IdentityMapping) (*emulator, err } } + if pp.Architecture == "amd64" { + if pp.Variant != "" && pp.Variant != "v2" { + var supported []string + for _, p := range all { + if p.Architecture == "amd64" { + supported = append(supported, platforms.Format(p)) + } + } + return nil, errors.Errorf("no support for running processes with %s platform, supported: %s", platforms.Format(pp), strings.Join(supported, ", ")) + } + } + a, ok := qemuArchMap[pp.Architecture] if !ok { a = pp.Architecture @@ -104,7 +118,8 @@ func getEmulator(p *pb.Platform, idmap *idtools.IdentityMapping) (*emulator, err fn, err := exec.LookPath("buildkit-qemu-" + a) if err != nil { - return nil, errors.Errorf("no emulator available for %v", pp.OS) + bklog.G(ctx).Warn(err.Error()) // TODO: remove this with pull support + return nil, nil // no emulator available } return &emulator{path: fn}, nil