-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2307 from crazy-max/test-docker-multi-ver
tests: handle multiple docker versions
- Loading branch information
Showing
7 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,16 @@ jobs: | |
- worker: docker+containerd # same as docker, but with containerd snapshotter | ||
pkg: ./tests | ||
mode: experimental | ||
- worker: "[email protected]" | ||
pkg: ./tests | ||
- worker: "[email protected]" # same as docker, but with containerd snapshotter | ||
pkg: ./tests | ||
- worker: "[email protected]" | ||
pkg: ./tests | ||
mode: experimental | ||
- worker: "[email protected]" # same as docker, but with containerd snapshotter | ||
pkg: ./tests | ||
mode: experimental | ||
steps: | ||
- | ||
name: Prepare | ||
|
@@ -86,7 +96,7 @@ jobs: | |
fi | ||
testFlags="--run=//worker=$(echo "${{ matrix.worker }}" | sed 's/\+/\\+/g')$" | ||
case "${{ matrix.worker }}" in | ||
docker | docker+containerd) | ||
docker | docker+containerd | docker@* | docker+containerd@*) | ||
echo "TESTFLAGS=${{ env.TESTFLAGS_DOCKER }} $testFlags" >> $GITHUB_ENV | ||
;; | ||
*) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ ARG XX_VERSION=1.5.0 | |
|
||
# for testing | ||
ARG DOCKER_VERSION=27.4.0-rc.2 | ||
ARG DOCKER_VERSION_ALT_26=26.1.3 | ||
ARG DOCKER_CLI_VERSION=${DOCKER_VERSION} | ||
ARG GOTESTSUM_VERSION=v1.12.0 | ||
ARG REGISTRY_VERSION=2.8.3 | ||
|
@@ -15,6 +16,8 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx | |
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest | ||
FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine | ||
FROM dockereng/cli-bin:$DOCKER_CLI_VERSION AS docker-cli | ||
FROM moby/moby-bin:$DOCKER_VERSION_ALT_26 AS docker-engine-alt | ||
FROM dockereng/cli-bin:$DOCKER_VERSION_ALT_26 AS docker-cli-alt | ||
FROM registry:$REGISTRY_VERSION AS registry | ||
FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit | ||
FROM crazymax/undock:$UNDOCK_VERSION AS undock | ||
|
@@ -123,10 +126,13 @@ COPY --link --from=gotestsum /out /usr/bin/ | |
COPY --link --from=registry /bin/registry /usr/bin/ | ||
COPY --link --from=docker-engine / /usr/bin/ | ||
COPY --link --from=docker-cli / /usr/bin/ | ||
COPY --link --from=docker-engine-alt / /opt/docker-alt-26/ | ||
COPY --link --from=docker-cli-alt / /opt/docker-alt-26/ | ||
COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/ | ||
COPY --link --from=buildkit /usr/bin/buildctl /usr/bin/ | ||
COPY --link --from=undock /usr/local/bin/undock /usr/bin/ | ||
COPY --link --from=binaries /buildx /usr/bin/ | ||
ENV TEST_DOCKER_EXTRA="[email protected]=/opt/docker-alt-26" | ||
|
||
FROM integration-test-base AS integration-test | ||
COPY . . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,76 @@ package workers | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/moby/buildkit/identity" | ||
"github.com/moby/buildkit/util/testutil/dockerd" | ||
"github.com/moby/buildkit/util/testutil/integration" | ||
bkworkers "github.com/moby/buildkit/util/testutil/workers" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func InitDockerWorker() { | ||
integration.Register(&dockerWorker{ | ||
id: "docker", | ||
id: "docker", | ||
binary: dockerd.DefaultDockerdBinary, | ||
}) | ||
integration.Register(&dockerWorker{ | ||
id: "docker+containerd", | ||
binary: dockerd.DefaultDockerdBinary, | ||
containerdSnapshotter: true, | ||
}) | ||
// e.g. `[email protected]=/opt/docker-26.0,[email protected]=/opt/docker-25.0` | ||
if s := os.Getenv("TEST_DOCKER_EXTRA"); s != "" { | ||
entries := strings.Split(s, ",") | ||
for _, entry := range entries { | ||
ver, bin, err := func(entry string) (string, string, error) { | ||
p1 := strings.Split(strings.TrimSpace(entry), "=") | ||
if len(p1) != 2 { | ||
return "", "", errors.Errorf("invalid entry: %q", entry) | ||
} | ||
name, bin := p1[0], p1[1] | ||
if _, err := os.Stat(bin); err != nil { | ||
return "", "", errors.Wrapf(err, "bin not found: %q", bin) | ||
} | ||
p2 := strings.Split(strings.TrimSpace(name), "@") | ||
if len(p2) != 2 { | ||
return "", "", errors.Errorf("invalid name: %q", name) | ||
} | ||
_, ver := p2[0], p2[1] | ||
if ver == "" { | ||
return "", "", errors.New("empty version") | ||
} | ||
return ver, bin, nil | ||
}(entry) | ||
if err != nil { | ||
panic(errors.Wrapf(err, "unexpected TEST_DOCKER_EXTRA: %q", s)) | ||
} | ||
integration.Register(&dockerWorker{ | ||
id: fmt.Sprintf("docker@%s", ver), | ||
binary: filepath.Join(bin, "dockerd"), | ||
extraEnv: []string{fmt.Sprintf("PATH=%s:%s", bin, os.Getenv("PATH"))}, | ||
}) | ||
integration.Register(&dockerWorker{ | ||
id: fmt.Sprintf("docker+containerd@%s", ver), | ||
binary: filepath.Join(bin, "dockerd"), | ||
containerdSnapshotter: true, | ||
extraEnv: []string{fmt.Sprintf("PATH=%s:%s", bin, os.Getenv("PATH"))}, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
type dockerWorker struct { | ||
id string | ||
binary string | ||
containerdSnapshotter bool | ||
unsupported []string | ||
extraEnv []string | ||
} | ||
|
||
func (c dockerWorker) Name() string { | ||
|
@@ -42,7 +89,9 @@ func (c *dockerWorker) NetNSDetached() bool { | |
func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (b integration.Backend, cl func() error, err error) { | ||
moby := bkworkers.Moby{ | ||
ID: c.id, | ||
Binary: c.binary, | ||
ContainerdSnapshotter: c.containerdSnapshotter, | ||
ExtraEnv: c.extraEnv, | ||
} | ||
bk, bkclose, err := moby.New(ctx, cfg) | ||
if err != nil { | ||
|