diff --git a/builder/node.go b/builder/node.go index ee600017578a..99e1400b3317 100644 --- a/builder/node.go +++ b/builder/node.go @@ -14,11 +14,9 @@ import ( "github.com/docker/buildx/util/imagetools" "github.com/docker/buildx/util/platformutil" "github.com/moby/buildkit/client" - "github.com/moby/buildkit/util/grpcerrors" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "golang.org/x/sync/errgroup" - "google.golang.org/grpc/codes" ) type Node struct { @@ -267,15 +265,9 @@ func (n *Node) loadData(ctx context.Context, clientOpt ...client.ClientOpt) erro n.Platforms = platformutil.Dedupe(n.Platforms) inf, err := driverClient.Info(ctx) if err != nil { - if st, ok := grpcerrors.AsGRPCStatus(err); ok && st.Code() == codes.Unimplemented { - n.Version, err = n.Driver.Version(ctx) - if err != nil { - return errors.Wrap(err, "getting version") - } - } - } else { - n.Version = inf.BuildkitVersion.Version + return errors.Wrap(err, "getting version") } + n.Version = inf.BuildkitVersion.Version } return nil } diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index 8283672b307e..1d3d0fd75165 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -369,22 +369,6 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) { }, nil } -func (d *Driver) Version(ctx context.Context) (string, error) { - bufStdout := &bytes.Buffer{} - bufStderr := &bytes.Buffer{} - if err := d.run(ctx, []string{"buildkitd", "--version"}, bufStdout, bufStderr); err != nil { - if bufStderr.Len() > 0 { - return "", errors.Wrap(err, bufStderr.String()) - } - return "", err - } - version := strings.Fields(bufStdout.String()) - if len(version) != 4 { - return "", errors.Errorf("unexpected version format: %s", bufStdout.String()) - } - return version[2], nil -} - func (d *Driver) Stop(ctx context.Context, force bool) error { info, err := d.Info(ctx) if err != nil { diff --git a/driver/docker/driver.go b/driver/docker/driver.go index 787f323d5175..61e4eeb98639 100644 --- a/driver/docker/driver.go +++ b/driver/docker/driver.go @@ -3,7 +3,6 @@ package docker import ( "context" "net" - "strings" "sync" "github.com/docker/buildx/driver" @@ -38,19 +37,6 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) { }, nil } -func (d *Driver) Version(ctx context.Context) (string, error) { - v, err := d.DockerAPI.ServerVersion(ctx, dockerclient.ServerVersionOptions{}) - if err != nil { - return "", errors.Wrap(driver.ErrNotConnecting{}, err.Error()) - } - // TODO(thaJeztah): this code is only used for docker <= v23.0, which are deprecated. - if bkversion, _ := resolveBuildKitVersion(v.Version); bkversion != "" { - return bkversion, nil - } - // https://github.com/moby/moby/blob/efc7a2abc3ab6dfa7d8d5d8c1c3b99138989b0f1/builder/builder-next/worker/worker.go#L176 - return strings.TrimSuffix(v.Version, "-moby"), nil -} - func (d *Driver) Stop(ctx context.Context, force bool) error { return nil } diff --git a/driver/docker/version.go b/driver/docker/version.go deleted file mode 100644 index e71608d107cd..000000000000 --- a/driver/docker/version.go +++ /dev/null @@ -1,185 +0,0 @@ -package docker - -import ( - "github.com/Masterminds/semver/v3" -) - -type mobyBuildkitVersion struct { - MobyVersionConstraint string - BuildkitVersion string -} - -// https://gist.github.com/crazy-max/780cb6878c37cb79ec3f7699706cf83f -// constraint syntax: https://github.com/Masterminds/semver#checking-version-constraints -var mobyBuildkitVersions = []mobyBuildkitVersion{ - { - MobyVersionConstraint: ">= 18.06.0-0, < 18.06.1-0", - BuildkitVersion: "v0.0.0+9acf51e", - }, - { - MobyVersionConstraint: ">= 18.06.1-0, < 18.09.0-0", - BuildkitVersion: "v0.0.0+98f1604", - }, - { - MobyVersionConstraint: ">= 18.09.0-0, < 18.09.1-0", - BuildkitVersion: "v0.0.0+c7bb575", - }, - { - MobyVersionConstraint: "~18.09.1-0", - BuildkitVersion: "v0.3.3", - }, - { - MobyVersionConstraint: "> 18.09.1-0, < 18.09.6-0", - BuildkitVersion: "v0.3.3+d9f7592", - }, - { - MobyVersionConstraint: ">= 18.09.6-0, < 18.09.7-0", - BuildkitVersion: "v0.4.0+ed4da8b", - }, - { - MobyVersionConstraint: ">= 18.09.7-0, < 19.03.0-0", - BuildkitVersion: "v0.4.0+05766c5", - }, - { - MobyVersionConstraint: "<= 19.03.0-beta2", - BuildkitVersion: "v0.4.0+b302896", - }, - { - MobyVersionConstraint: "<= 19.03.0-beta3", - BuildkitVersion: "v0.4.0+8818c67", - }, - { - MobyVersionConstraint: "<= 19.03.0-beta5", - BuildkitVersion: "v0.5.1+f238f1e", - }, - { - MobyVersionConstraint: "< 19.03.2-0", - BuildkitVersion: "v0.5.1+1f89ec1", - }, - { - MobyVersionConstraint: "<= 19.03.2-beta1", - BuildkitVersion: "v0.6.1", - }, - { - MobyVersionConstraint: ">= 19.03.2-0, < 19.03.3-0", - BuildkitVersion: "v0.6.1+588c73e", - }, - { - MobyVersionConstraint: ">= 19.03.3-0, < 19.03.5-beta2", - BuildkitVersion: "v0.6.2", - }, - { - MobyVersionConstraint: "<= 19.03.5-rc1", - BuildkitVersion: "v0.6.2+ff93519", - }, - { - MobyVersionConstraint: "<= 19.03.5", - BuildkitVersion: "v0.6.3+928f3b4", - }, - { - MobyVersionConstraint: "<= 19.03.6-rc1", - BuildkitVersion: "v0.6.3+926935b", - }, - { - MobyVersionConstraint: ">= 19.03.6-rc2, < 19.03.7-0", - BuildkitVersion: "v0.6.3+57e8ad5", - }, - { - MobyVersionConstraint: ">= 19.03.7-0, < 19.03.9-0", - BuildkitVersion: "v0.6.4", - }, - { - MobyVersionConstraint: ">= 19.03.9-0, < 19.03.13-0", - BuildkitVersion: "v0.6.4+a7d7b7f", - }, - { - MobyVersionConstraint: "<= 19.03.13-beta2", - BuildkitVersion: "v0.6.4+da1f4bf", - }, - { - MobyVersionConstraint: "<= 19.03.14", - BuildkitVersion: "v0.6.4+df89d4d", - }, - { - MobyVersionConstraint: "< 20.10.0", - BuildkitVersion: "v0.6.4+396bfe2", - }, - { - MobyVersionConstraint: "20.10.0-0 - 20.10.2-0", - BuildkitVersion: "v0.8.1", - }, - { - MobyVersionConstraint: ">= 20.10.3-0, < 20.10.4-0", - BuildkitVersion: "v0.8.1+68bb095", - }, - { - MobyVersionConstraint: "20.10.4-0 - 20.10.6", - BuildkitVersion: "v0.8.2", - }, - { - MobyVersionConstraint: "20.10.7-0 - 20.10.10-0", - BuildkitVersion: "v0.8.2+244e8cde", - }, - { - MobyVersionConstraint: "20.10.11-0 - 20.10.18-0", - BuildkitVersion: "v0.8.2+bc07b2b8", - }, - { - MobyVersionConstraint: ">= 20.10.19-0, < 20.10.20-0", - BuildkitVersion: "v0.8.2+3a1eeca5", - }, - { - MobyVersionConstraint: ">= 20.10.20-0, < 20.10.21-0", - BuildkitVersion: "v0.8.2+c0149372", - }, - { - MobyVersionConstraint: ">= 20.10.21-0, <= 20.10.23", - BuildkitVersion: "v0.8.2+eeb7b65", - }, - { - MobyVersionConstraint: "~20.10-0", - BuildkitVersion: "v0.8+unknown", - }, - { - MobyVersionConstraint: "~22.06-0", - BuildkitVersion: "v0.10.3", - }, - { - MobyVersionConstraint: ">= 23.0.0-0, < 23.0.1-0", - BuildkitVersion: "v0.10.6", - }, - { - MobyVersionConstraint: "23.0.1", - BuildkitVersion: "v0.10.6+4f0ee09", - }, - { - MobyVersionConstraint: ">= 23.0.2-0, < 23.0.4-0", - BuildkitVersion: "v0.10.6+70f2ad5", - }, - { - MobyVersionConstraint: ">= 23.0.4-0, < 23.0.7-0", - BuildkitVersion: "v0.10.6+d52b2d5", - }, - { - MobyVersionConstraint: "~23-0", - BuildkitVersion: "v0.10+unknown", - }, -} - -func resolveBuildKitVersion(ver string) (string, error) { - mobyVersion, err := semver.NewVersion(ver) - if err != nil { - return "", err - } - for _, m := range mobyBuildkitVersions { - c, err := semver.NewConstraint(m.MobyVersionConstraint) - if err != nil { - return "", err - } - if !c.Check(mobyVersion) { - continue - } - return m.BuildkitVersion, nil - } - return "", nil -} diff --git a/driver/docker/version_test.go b/driver/docker/version_test.go index c342ba86222a..166dbf9c98da 100644 --- a/driver/docker/version_test.go +++ b/driver/docker/version_test.go @@ -7,6 +7,168 @@ import ( "github.com/stretchr/testify/require" ) +type mobyBuildkitVersion struct { + MobyVersionConstraint string + BuildkitVersion string +} + +// https://gist.github.com/crazy-max/780cb6878c37cb79ec3f7699706cf83f +// constraint syntax: https://github.com/Masterminds/semver#checking-version-constraints +var mobyBuildkitVersions = []mobyBuildkitVersion{ + { + MobyVersionConstraint: ">= 18.06.0-0, < 18.06.1-0", + BuildkitVersion: "v0.0.0+9acf51e", + }, + { + MobyVersionConstraint: ">= 18.06.1-0, < 18.09.0-0", + BuildkitVersion: "v0.0.0+98f1604", + }, + { + MobyVersionConstraint: ">= 18.09.0-0, < 18.09.1-0", + BuildkitVersion: "v0.0.0+c7bb575", + }, + { + MobyVersionConstraint: "~18.09.1-0", + BuildkitVersion: "v0.3.3", + }, + { + MobyVersionConstraint: "> 18.09.1-0, < 18.09.6-0", + BuildkitVersion: "v0.3.3+d9f7592", + }, + { + MobyVersionConstraint: ">= 18.09.6-0, < 18.09.7-0", + BuildkitVersion: "v0.4.0+ed4da8b", + }, + { + MobyVersionConstraint: ">= 18.09.7-0, < 19.03.0-0", + BuildkitVersion: "v0.4.0+05766c5", + }, + { + MobyVersionConstraint: "<= 19.03.0-beta2", + BuildkitVersion: "v0.4.0+b302896", + }, + { + MobyVersionConstraint: "<= 19.03.0-beta3", + BuildkitVersion: "v0.4.0+8818c67", + }, + { + MobyVersionConstraint: "<= 19.03.0-beta5", + BuildkitVersion: "v0.5.1+f238f1e", + }, + { + MobyVersionConstraint: "< 19.03.2-0", + BuildkitVersion: "v0.5.1+1f89ec1", + }, + { + MobyVersionConstraint: "<= 19.03.2-beta1", + BuildkitVersion: "v0.6.1", + }, + { + MobyVersionConstraint: ">= 19.03.2-0, < 19.03.3-0", + BuildkitVersion: "v0.6.1+588c73e", + }, + { + MobyVersionConstraint: ">= 19.03.3-0, < 19.03.5-beta2", + BuildkitVersion: "v0.6.2", + }, + { + MobyVersionConstraint: "<= 19.03.5-rc1", + BuildkitVersion: "v0.6.2+ff93519", + }, + { + MobyVersionConstraint: "<= 19.03.5", + BuildkitVersion: "v0.6.3+928f3b4", + }, + { + MobyVersionConstraint: "<= 19.03.6-rc1", + BuildkitVersion: "v0.6.3+926935b", + }, + { + MobyVersionConstraint: ">= 19.03.6-rc2, < 19.03.7-0", + BuildkitVersion: "v0.6.3+57e8ad5", + }, + { + MobyVersionConstraint: ">= 19.03.7-0, < 19.03.9-0", + BuildkitVersion: "v0.6.4", + }, + { + MobyVersionConstraint: ">= 19.03.9-0, < 19.03.13-0", + BuildkitVersion: "v0.6.4+a7d7b7f", + }, + { + MobyVersionConstraint: "<= 19.03.13-beta2", + BuildkitVersion: "v0.6.4+da1f4bf", + }, + { + MobyVersionConstraint: "<= 19.03.14", + BuildkitVersion: "v0.6.4+df89d4d", + }, + { + MobyVersionConstraint: "< 20.10.0", + BuildkitVersion: "v0.6.4+396bfe2", + }, + { + MobyVersionConstraint: "20.10.0-0 - 20.10.2-0", + BuildkitVersion: "v0.8.1", + }, + { + MobyVersionConstraint: ">= 20.10.3-0, < 20.10.4-0", + BuildkitVersion: "v0.8.1+68bb095", + }, + { + MobyVersionConstraint: "20.10.4-0 - 20.10.6", + BuildkitVersion: "v0.8.2", + }, + { + MobyVersionConstraint: "20.10.7-0 - 20.10.10-0", + BuildkitVersion: "v0.8.2+244e8cde", + }, + { + MobyVersionConstraint: "20.10.11-0 - 20.10.18-0", + BuildkitVersion: "v0.8.2+bc07b2b8", + }, + { + MobyVersionConstraint: ">= 20.10.19-0, < 20.10.20-0", + BuildkitVersion: "v0.8.2+3a1eeca5", + }, + { + MobyVersionConstraint: ">= 20.10.20-0, < 20.10.21-0", + BuildkitVersion: "v0.8.2+c0149372", + }, + { + MobyVersionConstraint: ">= 20.10.21-0, <= 20.10.23", + BuildkitVersion: "v0.8.2+eeb7b65", + }, + { + MobyVersionConstraint: "~20.10-0", + BuildkitVersion: "v0.8+unknown", + }, + { + MobyVersionConstraint: "~22.06-0", + BuildkitVersion: "v0.10.3", + }, + { + MobyVersionConstraint: ">= 23.0.0-0, < 23.0.1-0", + BuildkitVersion: "v0.10.6", + }, + { + MobyVersionConstraint: "23.0.1", + BuildkitVersion: "v0.10.6+4f0ee09", + }, + { + MobyVersionConstraint: ">= 23.0.2-0, < 23.0.4-0", + BuildkitVersion: "v0.10.6+70f2ad5", + }, + { + MobyVersionConstraint: ">= 23.0.4-0, < 23.0.7-0", + BuildkitVersion: "v0.10.6+d52b2d5", + }, + { + MobyVersionConstraint: "~23-0", + BuildkitVersion: "v0.10+unknown", + }, +} + func TestConstraint(t *testing.T) { for _, tt := range mobyBuildkitVersions { t.Run(tt.MobyVersionConstraint, func(t *testing.T) { @@ -15,119 +177,3 @@ func TestConstraint(t *testing.T) { }) } } - -func TestResolveBuildKitVersion(t *testing.T) { - cases := []struct { - mobyVersion string - expected string - err bool - }{ - { - mobyVersion: "18.06.1-ce", - expected: "v0.0.0+98f1604", - }, - { - mobyVersion: "18.09.1-beta1", - expected: "v0.3.3", - }, - { - mobyVersion: "19.03.0-beta1", - expected: "v0.4.0+b302896", - }, - { - mobyVersion: "19.03.5-beta2", - expected: "v0.6.2+ff93519", - }, - { - mobyVersion: "19.03.13-beta1", - expected: "v0.6.4+da1f4bf", - }, - { - mobyVersion: "19.03.13-beta2", - expected: "v0.6.4+da1f4bf", - }, - { - mobyVersion: "19.03.13", - expected: "v0.6.4+df89d4d", - }, - { - mobyVersion: "20.10.3-rc.1", - expected: "v0.8.1+68bb095", - }, - { - mobyVersion: "20.10.3", - expected: "v0.8.1+68bb095", - }, - { - mobyVersion: "20.10.4", - expected: "v0.8.2", - }, - { - mobyVersion: "20.10.16", - expected: "v0.8.2+bc07b2b8", - }, - { - mobyVersion: "20.10.19", - expected: "v0.8.2+3a1eeca5", - }, - { - mobyVersion: "20.10.23", - expected: "v0.8.2+eeb7b65", - }, - { - mobyVersion: "20.10.24", - expected: "v0.8+unknown", - }, - { - mobyVersion: "20.10.50", - expected: "v0.8+unknown", - }, - { - mobyVersion: "22.06.0-beta.0", - expected: "v0.10.3", - }, - { - mobyVersion: "22.06.0", - expected: "v0.10.3", - }, - { - mobyVersion: "23.0.0-rc.4", - expected: "v0.10.6", - }, - { - mobyVersion: "23.0.0", - expected: "v0.10.6", - }, - { - mobyVersion: "23.0.1", - expected: "v0.10.6+4f0ee09", - }, - { - mobyVersion: "23.0.2-rc.1", - expected: "v0.10.6+70f2ad5", - }, - { - mobyVersion: "23.0.3", - expected: "v0.10.6+70f2ad5", - }, - { - mobyVersion: "23.0.5", - expected: "v0.10.6+d52b2d5", - }, - { - mobyVersion: "23.0.7", - expected: "v0.10+unknown", - }, - } - for _, tt := range cases { - t.Run(tt.mobyVersion, func(t *testing.T) { - bkVersion, err := resolveBuildKitVersion(tt.mobyVersion) - if tt.err { - require.Error(t, err) - return - } - require.NoError(t, err) - require.Equal(t, tt.expected, bkVersion) - }) - } -} diff --git a/driver/driver.go b/driver/driver.go index c82852cd8fc1..43430867b8b5 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -66,7 +66,6 @@ type Driver interface { Factory() Factory Bootstrap(context.Context, progress.Logger) error Info(context.Context) (*Info, error) - Version(context.Context) (string, error) Stop(ctx context.Context, force bool) error Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error Dial(ctx context.Context) (net.Conn, error) diff --git a/driver/kubernetes/driver.go b/driver/kubernetes/driver.go index 3bfe568a5802..2be21bd3e969 100644 --- a/driver/kubernetes/driver.go +++ b/driver/kubernetes/driver.go @@ -168,10 +168,6 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) { }, nil } -func (d *Driver) Version(ctx context.Context) (string, error) { - return "", nil -} - func (d *Driver) Stop(ctx context.Context, force bool) error { // future version may scale the replicas to zero here return nil diff --git a/driver/remote/driver.go b/driver/remote/driver.go index 495a487e04d1..75f64b2ff185 100644 --- a/driver/remote/driver.go +++ b/driver/remote/driver.go @@ -73,10 +73,6 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) { }, nil } -func (d *Driver) Version(ctx context.Context) (string, error) { - return "", nil -} - func (d *Driver) Stop(ctx context.Context, force bool) error { return nil }