Skip to content

Commit 5937ba0

Browse files
authored
Merge pull request docker#2307 from crazy-max/test-docker-multi-ver
tests: handle multiple docker versions
2 parents 21fb026 + a69d857 commit 5937ba0

File tree

7 files changed

+81
-12
lines changed

7 files changed

+81
-12
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ jobs:
7676
- worker: docker+containerd # same as docker, but with containerd snapshotter
7777
pkg: ./tests
7878
mode: experimental
79+
- worker: "[email protected]"
80+
pkg: ./tests
81+
- worker: "[email protected]" # same as docker, but with containerd snapshotter
82+
pkg: ./tests
83+
- worker: "[email protected]"
84+
pkg: ./tests
85+
mode: experimental
86+
- worker: "[email protected]" # same as docker, but with containerd snapshotter
87+
pkg: ./tests
88+
mode: experimental
7989
steps:
8090
-
8191
name: Prepare
@@ -86,7 +96,7 @@ jobs:
8696
fi
8797
testFlags="--run=//worker=$(echo "${{ matrix.worker }}" | sed 's/\+/\\+/g')$"
8898
case "${{ matrix.worker }}" in
89-
docker | docker+containerd)
99+
docker | docker+containerd | docker@* | docker+containerd@*)
90100
echo "TESTFLAGS=${{ env.TESTFLAGS_DOCKER }} $testFlags" >> $GITHUB_ENV
91101
;;
92102
*)

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARG XX_VERSION=1.5.0
55

66
# for testing
77
ARG DOCKER_VERSION=27.4.0-rc.2
8+
ARG DOCKER_VERSION_ALT_26=26.1.3
89
ARG DOCKER_CLI_VERSION=${DOCKER_VERSION}
910
ARG GOTESTSUM_VERSION=v1.12.0
1011
ARG REGISTRY_VERSION=2.8.3
@@ -15,6 +16,8 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
1516
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest
1617
FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine
1718
FROM dockereng/cli-bin:$DOCKER_CLI_VERSION AS docker-cli
19+
FROM moby/moby-bin:$DOCKER_VERSION_ALT_26 AS docker-engine-alt
20+
FROM dockereng/cli-bin:$DOCKER_VERSION_ALT_26 AS docker-cli-alt
1821
FROM registry:$REGISTRY_VERSION AS registry
1922
FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit
2023
FROM crazymax/undock:$UNDOCK_VERSION AS undock
@@ -123,10 +126,13 @@ COPY --link --from=gotestsum /out /usr/bin/
123126
COPY --link --from=registry /bin/registry /usr/bin/
124127
COPY --link --from=docker-engine / /usr/bin/
125128
COPY --link --from=docker-cli / /usr/bin/
129+
COPY --link --from=docker-engine-alt / /opt/docker-alt-26/
130+
COPY --link --from=docker-cli-alt / /opt/docker-alt-26/
126131
COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/
127132
COPY --link --from=buildkit /usr/bin/buildctl /usr/bin/
128133
COPY --link --from=undock /usr/local/bin/undock /usr/bin/
129134
COPY --link --from=binaries /buildx /usr/bin/
135+
ENV TEST_DOCKER_EXTRA="[email protected]=/opt/docker-alt-26"
130136

131137
FROM integration-test-base AS integration-test
132138
COPY . .

tests/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ RUN exit 1`)
505505

506506
func testBuildProgress(t *testing.T, sb integration.Sandbox) {
507507
dir := createTestProject(t)
508-
sbDriver, _ := driverName(sb.Name())
508+
sbDriver, _, _ := driverName(sb.Name())
509509
name := sb.Address()
510510

511511
// progress=tty

tests/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func testInspect(t *testing.T, sb integration.Sandbox) {
4545
}
4646

4747
require.Equal(t, sb.Address(), name)
48-
sbDriver, _ := driverName(sb.Name())
48+
sbDriver, _, _ := driverName(sb.Name())
4949
require.Equal(t, sbDriver, driver)
5050
if isDockerWorker(sb) {
5151
require.NotEmpty(t, hostGatewayIP, "host-gateway-ip worker label should be set with docker driver")

tests/integration.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,37 @@ func buildxConfig(sb integration.Sandbox) string {
9595
}
9696

9797
func isMobyWorker(sb integration.Sandbox) bool {
98-
name, hasFeature := driverName(sb.Name())
98+
name, _, hasFeature := driverName(sb.Name())
9999
return name == "docker" && !hasFeature
100100
}
101101

102102
func isMobyContainerdSnapWorker(sb integration.Sandbox) bool {
103-
name, hasFeature := driverName(sb.Name())
103+
name, _, hasFeature := driverName(sb.Name())
104104
return name == "docker" && hasFeature
105105
}
106106

107107
func isDockerWorker(sb integration.Sandbox) bool {
108-
name, _ := driverName(sb.Name())
108+
name, _, _ := driverName(sb.Name())
109109
return name == "docker"
110110
}
111111

112112
func isDockerContainerWorker(sb integration.Sandbox) bool {
113-
name, _ := driverName(sb.Name())
113+
name, _, _ := driverName(sb.Name())
114114
return name == "docker-container"
115115
}
116116

117-
func driverName(sbName string) (string, bool) {
117+
func driverName(sbName string) (string, bool, bool) {
118118
name := sbName
119-
var hasFeature bool
119+
var hasVersion, hasFeature bool
120+
if b, _, ok := strings.Cut(sbName, "@"); ok {
121+
name = b
122+
hasVersion = true
123+
}
120124
if b, _, ok := strings.Cut(name, "+"); ok {
121125
name = b
122126
hasFeature = true
123127
}
124-
return name, hasFeature
128+
return name, hasVersion, hasFeature
125129
}
126130

127131
func isExperimental() bool {

tests/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func testLs(t *testing.T, sb integration.Sandbox) {
3434
},
3535
}
3636

37-
sbDriver, _ := driverName(sb.Name())
37+
sbDriver, _, _ := driverName(sb.Name())
3838
for _, tt := range tests {
3939
tt := tt
4040
t.Run(tt.name, func(t *testing.T) {

tests/workers/docker.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,76 @@ package workers
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"os/exec"
8+
"path/filepath"
9+
"strings"
710

811
"github.com/moby/buildkit/identity"
12+
"github.com/moby/buildkit/util/testutil/dockerd"
913
"github.com/moby/buildkit/util/testutil/integration"
1014
bkworkers "github.com/moby/buildkit/util/testutil/workers"
1115
"github.com/pkg/errors"
1216
)
1317

1418
func InitDockerWorker() {
1519
integration.Register(&dockerWorker{
16-
id: "docker",
20+
id: "docker",
21+
binary: dockerd.DefaultDockerdBinary,
1722
})
1823
integration.Register(&dockerWorker{
1924
id: "docker+containerd",
25+
binary: dockerd.DefaultDockerdBinary,
2026
containerdSnapshotter: true,
2127
})
28+
// e.g. `[email protected]=/opt/docker-26.0,[email protected]=/opt/docker-25.0`
29+
if s := os.Getenv("TEST_DOCKER_EXTRA"); s != "" {
30+
entries := strings.Split(s, ",")
31+
for _, entry := range entries {
32+
ver, bin, err := func(entry string) (string, string, error) {
33+
p1 := strings.Split(strings.TrimSpace(entry), "=")
34+
if len(p1) != 2 {
35+
return "", "", errors.Errorf("invalid entry: %q", entry)
36+
}
37+
name, bin := p1[0], p1[1]
38+
if _, err := os.Stat(bin); err != nil {
39+
return "", "", errors.Wrapf(err, "bin not found: %q", bin)
40+
}
41+
p2 := strings.Split(strings.TrimSpace(name), "@")
42+
if len(p2) != 2 {
43+
return "", "", errors.Errorf("invalid name: %q", name)
44+
}
45+
_, ver := p2[0], p2[1]
46+
if ver == "" {
47+
return "", "", errors.New("empty version")
48+
}
49+
return ver, bin, nil
50+
}(entry)
51+
if err != nil {
52+
panic(errors.Wrapf(err, "unexpected TEST_DOCKER_EXTRA: %q", s))
53+
}
54+
integration.Register(&dockerWorker{
55+
id: fmt.Sprintf("docker@%s", ver),
56+
binary: filepath.Join(bin, "dockerd"),
57+
extraEnv: []string{fmt.Sprintf("PATH=%s:%s", bin, os.Getenv("PATH"))},
58+
})
59+
integration.Register(&dockerWorker{
60+
id: fmt.Sprintf("docker+containerd@%s", ver),
61+
binary: filepath.Join(bin, "dockerd"),
62+
containerdSnapshotter: true,
63+
extraEnv: []string{fmt.Sprintf("PATH=%s:%s", bin, os.Getenv("PATH"))},
64+
})
65+
}
66+
}
2267
}
2368

2469
type dockerWorker struct {
2570
id string
71+
binary string
2672
containerdSnapshotter bool
2773
unsupported []string
74+
extraEnv []string
2875
}
2976

3077
func (c dockerWorker) Name() string {
@@ -42,7 +89,9 @@ func (c *dockerWorker) NetNSDetached() bool {
4289
func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (b integration.Backend, cl func() error, err error) {
4390
moby := bkworkers.Moby{
4491
ID: c.id,
92+
Binary: c.binary,
4593
ContainerdSnapshotter: c.containerdSnapshotter,
94+
ExtraEnv: c.extraEnv,
4695
}
4796
bk, bkclose, err := moby.New(ctx, cfg)
4897
if err != nil {

0 commit comments

Comments
 (0)