Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amd64 variants support #2588

Merged
merged 4 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ func setDefaultConfig(cfg *config.Config) {
}

if cfg.Workers.OCI.Platforms == nil {
cfg.Workers.OCI.Platforms = archutil.SupportedPlatforms(false)
cfg.Workers.OCI.Platforms = formatPlatforms(archutil.SupportedPlatforms(false))
}
if cfg.Workers.Containerd.Platforms == nil {
cfg.Workers.Containerd.Platforms = archutil.SupportedPlatforms(false)
cfg.Workers.Containerd.Platforms = formatPlatforms(archutil.SupportedPlatforms(false))
}

cfg.Workers.OCI.NetworkConfig = setDefaultNetworkConfig(cfg.Workers.OCI.NetworkConfig)
Expand Down Expand Up @@ -700,8 +700,8 @@ func newWorkerController(c *cli.Context, wiOpt workerInitializerOpt) (*worker.Co
return nil, err
}
for _, w := range ws {
p := formatPlatforms(w.Platforms(false))
logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), p)
p := w.Platforms(false)
logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), formatPlatforms(p))
archutil.WarnIfUnsupported(p)
if err = wc.Add(w); err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/agext/levenshtein v1.2.3
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.0-rc.1
github.com/containerd/containerd v1.6.0-rc.1.0.20220127150749-a43703fcba54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to use v1.6.0-rc.2 now, which has your commit

github.com/containerd/continuity v0.2.2
github.com/containerd/fuse-overlayfs-snapshotter v1.0.2
github.com/containerd/go-cni v1.1.1
Expand Down Expand Up @@ -54,6 +54,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tonistiigi/fsutil v0.0.0-20211208180946-61a57076b9b0
github.com/tonistiigi/go-actions-cache v0.0.0-20211202175116-9642704158ff
github.com/tonistiigi/go-archvariant v1.0.0
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f
github.com/urfave/cli v1.22.4
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoT
github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c=
github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s=
github.com/containerd/containerd v1.6.0-rc.1 h1:bFSTay5ZHCSmAE/hzubBXX+eUpptHprbXi0QELuUk0Y=
github.com/containerd/containerd v1.6.0-rc.1/go.mod h1:jdeOXdXovU4bWF2Bd2hJjqpcOrrpSC1wmFCTtf6LD+A=
github.com/containerd/containerd v1.6.0-rc.1.0.20220127150749-a43703fcba54 h1:ZQqTZnRLXn44/VOq0LBjnH3vMOgGoEUic+8b1a1TBx4=
github.com/containerd/containerd v1.6.0-rc.1.0.20220127150749-a43703fcba54/go.mod h1:jdeOXdXovU4bWF2Bd2hJjqpcOrrpSC1wmFCTtf6LD+A=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down Expand Up @@ -1234,6 +1235,8 @@ github.com/tonistiigi/fsutil v0.0.0-20211208180946-61a57076b9b0 h1:1s9pEdOzN6AuO
github.com/tonistiigi/fsutil v0.0.0-20211208180946-61a57076b9b0/go.mod h1:oPAfvw32vlUJSjyDcQ3Bu0nb2ON2B+G0dtVN/SZNJiA=
github.com/tonistiigi/go-actions-cache v0.0.0-20211202175116-9642704158ff h1:n8i1G5sBFmY8aDteg5Kf2rdU15KnFcS807QrYRM9/yQ=
github.com/tonistiigi/go-actions-cache v0.0.0-20211202175116-9642704158ff/go.mod h1:qqvyZqkfwkoJuPU/bw61bItaoO0SJ8YSW0vSVRRvsRg=
github.com/tonistiigi/go-archvariant v1.0.0 h1:5LC1eDWiBNflnTF1prCiX09yfNHIxDC/aukdhCdTyb0=
github.com/tonistiigi/go-archvariant v1.0.0/go.mod h1:TxFmO5VS6vMq2kvs3ht04iPXtu2rUT/erOnGFYfk5Ho=
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/v/cCndK0AMpt1wiVFb/YYmqB3/QG0=
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6cRcDZSUvVmezrxJPkiO87ThFYsoUiMwWNDJk=
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f h1:DLpt6B5oaaS8jyXHa9VA4rrZloBVPVXeCtrOsrFauxc=
Expand Down
11 changes: 5 additions & 6 deletions solver/llbsolver/ops/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions solver/llbsolver/ops/exec_binfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/platforms"
"github.com/docker/docker/pkg/idtools"
"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"
Expand Down Expand Up @@ -83,19 +85,29 @@ 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,
OS: p.OS,
Variant: p.Variant,
})

for _, ps := range all {
if p, err := platforms.Parse(ps); err == nil {
if platforms.Only(p).Match(pp) {
return nil, nil
for _, p := range all {
if platforms.Only(p).Match(pp) {
return nil, nil
}
}

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, ", "))
}
}

Expand All @@ -106,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not error anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log was previously in ops/exec.go . Previously we ignored all errors. Now only ignore this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it I missed the one in exec.

bklog.G(ctx).Warn(err.Error()) // TODO: remove this with pull support
return nil, nil // no emulator available
}

return &emulator{path: fn}, nil
Expand Down
4 changes: 2 additions & 2 deletions util/archutil/386_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func i386Supported() error {
return check(Binary386)
func i386Supported() (string, error) {
return check("386", Binary386)
}
4 changes: 2 additions & 2 deletions util/archutil/386_check_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func i386Supported() error {
return nil
func i386Supported() (string, error) {
return "", nil
}
6 changes: 3 additions & 3 deletions util/archutil/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM debian:bullseye-slim AS base
RUN apt-get update && apt-get --no-install-recommends install -y \
gcc-x86-64-linux-gnu \
binutils-arm-linux-gnueabihf \
binutils-aarch64-linux-gnu \
binutils-x86-64-linux-gnu \
binutils-i686-linux-gnu \
binutils-riscv64-linux-gnu \
binutils-s390x-linux-gnu \
Expand All @@ -13,8 +13,8 @@ WORKDIR /src


FROM base AS exit-amd64
COPY fixtures/exit.amd64.s .
RUN x86_64-linux-gnu-as --noexecstack -o exit.o exit.amd64.s && x86_64-linux-gnu-ld -o exit -s exit.o
COPY fixtures/exit.amd64.S .
RUN x86_64-linux-gnu-gcc -static -nostdlib -o exit exit.amd64.S

FROM base AS exit-386
COPY fixtures/exit.386.s .
Expand Down
2 changes: 1 addition & 1 deletion util/archutil/amd64_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ package archutil
// This file is generated by running make inside the archutil package.
// Do not edit manually.

const Binaryamd64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaa\x77\xf5\x71\x63\x62\x64\x64\x80\x01\x26\x06\x3b\x06\x30\x4f\xc0\x01\xcc\x77\x80\x8a\x2b\x08\xc0\x95\x30\x38\x30\x58\x30\x30\x33\x38\x30\x30\x33\x30\x81\xd5\xb2\x30\x20\x03\x07\x14\xfa\x05\x94\x07\xa3\x19\xa0\xe6\x80\xf4\xb1\x22\xf1\x61\xf6\xc1\x68\x1e\xa8\x30\x0f\x9a\xbe\xc0\xa7\x25\x29\x6c\x0c\xc4\x03\x01\x86\x51\x30\x0a\x46\xc1\x28\x18\x05\xa3\x60\x14\x8c\x82\x51\x30\x0a\x46\xc1\x28\x18\x05\xa3\x60\x14\x78\x1c\x3f\x60\x03\xa2\x0c\xff\xf3\xb3\x32\xe8\x15\x67\x14\x97\x14\x95\x24\x26\x31\xe8\x95\xa4\x56\x94\x50\xc3\x7c\x6e\x68\x5f\x1f\xde\x67\x87\xf7\xf3\xd1\xfa\xf7\x0c\x88\x71\x01\x74\x3e\x33\x16\x73\x79\xa0\xfa\x05\x09\xe8\x07\x04\x00\x00\xff\xff\x6d\x7a\x0b\x2f\xe0\x10\x00\x00"
const Binaryamd64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xec\x98\x3f\x8b\x13\x41\x18\xc6\x9f\xd9\x6c\xee\x0f\x08\xb9\xe0\x81\xc2\x59\xa8\x58\xd8\xb8\xe1\x54\x38\x05\x95\x55\x50\x07\xf1\xec\xce\xd2\x65\x93\x5d\xce\x80\x97\x5b\xb2\xb3\xe7\x0a\x07\x77\x47\xbe\x83\x58\x07\x14\x0b\x4b\xc1\x94\xa9\x5c\x2c\x6d\xac\x4d\x21\x04\xad\xec\x0c\x28\xca\x6e\xde\x49\xb2\x63\xa2\x82\xdd\x31\x3f\x08\xcf\xbc\xcf\xbe\x33\xef\x90\xa4\xd9\x67\xef\xe6\xdd\x5b\x06\x63\x90\x18\xb8\x86\xac\x5a\xb2\xb3\xda\x26\xff\x63\x79\xd4\x02\x1b\x97\x50\x80\x8d\x39\x14\xb3\x5e\x13\x93\xd8\x39\x3d\x42\x47\x4b\xc5\xd2\x50\xd2\xb2\x38\x51\xcb\x79\x52\x03\xb2\xa5\xca\x3e\x93\x3e\x7d\xb2\xfb\x34\x47\xea\x19\xf2\xa5\x9a\x13\xba\x0c\xa0\x00\xe0\xf6\xbd\x0d\xf8\xcf\xdf\x5c\xfe\xf0\xf2\xd3\xfd\xf5\x1f\x4f\x8f\x7e\x7f\xf1\x79\xef\xed\x85\xf7\xaf\xa1\xd1\x68\x34\x1a\x8d\x46\xa3\xd1\x68\x34\x1a\xcd\x21\x85\xaf\x76\x4b\x6d\xde\xfa\x36\xbf\x7b\x87\x77\x00\xec\xa7\x66\xa9\x7d\x95\x01\xfb\xbb\x6b\x3c\xe9\xb2\xac\xe9\x5d\xa9\xcd\x0f\x7a\xec\xf4\x33\xf0\x83\x41\x2a\xd1\x0a\xef\x30\x6a\x1f\x3e\x6e\xf5\x18\x6f\x0d\x58\x64\x7c\x59\xe4\x49\x72\x1d\x40\xb6\xb8\x91\x2e\xc0\x93\xee\x95\xf4\xe0\xe2\x9f\xee\x52\x00\x1b\xbd\xc7\xe7\x7d\x63\x9c\x0f\x60\x9c\x1f\x98\xf8\xfa\x53\xed\x2d\x53\x8a\xb1\xa1\xf4\x2f\x93\xff\x40\xf1\x8f\x91\xbf\xa9\xf8\xa7\xb2\xc8\xe1\xf7\xb9\x27\xa4\x7f\x32\xef\x9f\x9d\xe1\x57\x66\xf8\xa8\x88\xad\xa0\x52\xab\xc5\xb5\xb5\xc7\xcd\x75\x6b\x1b\x3b\xab\xd8\x39\x0f\x3f\xae\x0b\x38\x4e\x35\x0c\x9d\x50\xb8\x4d\x01\xc7\xf7\x5c\xe1\xc2\xf1\x1b\x1e\x60\x85\x4f\xb6\x84\x5b\x85\x15\x8a\xe6\x50\x1f\xca\x55\x63\x5b\xf8\xd6\x66\x23\xb2\xaa\x51\xfd\x91\x77\xae\xee\xc1\x12\x7e\x2c\xfe\xfb\xff\xb1\x02\x60\x3e\xfb\x86\xd4\xbc\x25\x9f\xb3\x40\xc9\x5b\x24\x16\xfd\x56\x73\xa3\x1c\xc7\xce\xe5\x39\x81\xd2\xcf\xa6\xd4\xc6\x94\x7b\x05\xb4\x7f\x81\x8d\xe7\xa6\xf7\x5c\xa0\xe7\xc7\x49\x17\x29\xf3\x51\x89\x29\xcf\xba\xf8\x97\xf9\xe5\x19\xfb\x5f\xfd\xe3\xfe\x5f\x01\x00\x00\xff\xff\xa5\x58\xb1\x16\x60\x13\x00\x00"
Copy link
Member

@crazy-max crazy-max Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the bullseye one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 changes: 2 additions & 2 deletions util/archutil/amd64_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func amd64Supported() error {
return check(Binaryamd64)
func amd64Supported() (string, error) {
return check("amd64", Binaryamd64)
}
8 changes: 6 additions & 2 deletions util/archutil/amd64_check_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

package archutil

func amd64Supported() error {
return nil
import (
archvariant "github.com/tonistiigi/go-archvariant"
)

func amd64Supported() (string, error) {
return archvariant.AMD64Variant(), nil
}
4 changes: 2 additions & 2 deletions util/archutil/arm64_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func arm64Supported() error {
return check(Binaryarm64)
func arm64Supported() (string, error) {
return check("arm64", Binaryarm64)
}
4 changes: 2 additions & 2 deletions util/archutil/arm64_check_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func arm64Supported() error {
return nil
func arm64Supported() (string, error) {
return "", nil
}
4 changes: 2 additions & 2 deletions util/archutil/arm_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func armSupported() error {
return check(Binaryarm)
func armSupported() (string, error) {
return check("arm", Binaryarm)
}
4 changes: 2 additions & 2 deletions util/archutil/arm_check_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

package archutil

func armSupported() error {
return nil
func armSupported() (string, error) {
return "", nil
}
30 changes: 24 additions & 6 deletions util/archutil/check_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"os/exec"
"path/filepath"
"syscall"

"github.com/pkg/errors"
)

func withChroot(cmd *exec.Cmd, dir string) {
Expand All @@ -20,33 +22,49 @@ func withChroot(cmd *exec.Cmd, dir string) {
}
}

func check(bin string) error {
func check(arch, bin string) (string, error) {
tmpdir, err := ioutil.TempDir("", "qemu-check")
if err != nil {
return err
return "", err
}
defer os.RemoveAll(tmpdir)
pp := filepath.Join(tmpdir, "check")

r, err := gzip.NewReader(bytes.NewReader([]byte(bin)))
if err != nil {
return err
return "", err
}
defer r.Close()

f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700)
if err != nil {
return err
return "", err
}

if _, err := io.Copy(f, r); err != nil {
f.Close()
return err
return "", err
}
f.Close()

cmd := exec.Command("/check")
withChroot(cmd, tmpdir)
err = cmd.Run()
return err
if arch != "amd64" {
return "", err
}

// special handling for amd64. Exit code is 64 + amd64 variant
if err == nil {
return "", errors.Errorf("invalid zero exit code")
}
if exitError, ok := err.(*exec.ExitError); ok {
switch exitError.ExitCode() {
case 65:
return "v1", nil
case 66:
return "v2", nil
}
}
return "", err
}
4 changes: 2 additions & 2 deletions util/archutil/check_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import (
func withChroot(cmd *exec.Cmd, dir string) {
}

func check(bin string) error {
return errors.New("binfmt is not supported on Windows")
func check(arch, bin string) (string, error) {
return "", errors.New("binfmt is not supported on Windows")
}
Loading