Skip to content

Commit 489d348

Browse files
committed
tests: run remote worker on tcp and container endpoints
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 0c72c95 commit 489d348

File tree

5 files changed

+92
-32
lines changed

5 files changed

+92
-32
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ jobs:
4848
- v0.11.6
4949
worker:
5050
- docker-container
51-
- remote
51+
- remote+docker-container
52+
- remote+tcp
5253
pkg:
5354
- ./tests
5455
include:
5556
- worker: docker
5657
pkg: ./tests
57-
- worker: docker\+containerd # same as docker, but with containerd snapshotter
58+
- worker: docker+containerd # same as docker, but with containerd snapshotter
5859
pkg: ./tests
5960
steps:
6061
-
@@ -64,6 +65,18 @@ jobs:
6465
if [ -n "${{ matrix.buildkit }}" ]; then
6566
echo "TEST_BUILDKIT_TAG=${{ matrix.buildkit }}" >> $GITHUB_ENV
6667
fi
68+
testFlags="--run=//worker=$(echo "${{ matrix.worker }}" | sed 's/\+/\\+/g')$"
69+
case "${{ matrix.worker }}" in
70+
docker | docker+containerd | docker@* | docker+containerd@* | remote*)
71+
echo "TESTFLAGS=${{ env.TESTFLAGS_DOCKER }} $testFlags" >> $GITHUB_ENV
72+
;;
73+
*)
74+
echo "TESTFLAGS=${{ env.TESTFLAGS }} $testFlags" >> $GITHUB_ENV
75+
;;
76+
esac
77+
if [[ "${{ matrix.worker }}" == "docker"* ]]; then
78+
echo "TEST_DOCKERD=1" >> $GITHUB_ENV
79+
fi
6780
-
6881
name: Checkout
6982
uses: actions/checkout@v4
@@ -92,8 +105,6 @@ jobs:
92105
./hack/test
93106
env:
94107
TEST_REPORT_SUFFIX: "-${{ env.TESTREPORTS_NAME }}"
95-
TEST_DOCKERD: "${{ startsWith(matrix.worker, 'docker') && '1' || '0' }}"
96-
TESTFLAGS: "${{ (matrix.worker == 'docker' || matrix.worker == 'docker\\+containerd') && env.TESTFLAGS_DOCKER || env.TESTFLAGS }} --run=//worker=${{ matrix.worker }}$"
97108
TESTPKGS: "${{ matrix.pkg }}"
98109
-
99110
name: Send to Codecov

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ ARG XX_VERSION=1.4.0
77
ARG DOCKER_VERSION=25.0.2
88
ARG GOTESTSUM_VERSION=v1.9.0
99
ARG REGISTRY_VERSION=2.8.0
10-
ARG BUILDKIT_VERSION=v0.13.0
1110
ARG UNDOCK_VERSION=0.7.0
1211

1312
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
1413
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest
1514
FROM moby/moby-bin:$DOCKER_VERSION AS docker-engine
1615
FROM dockereng/cli-bin:$DOCKER_VERSION AS docker-cli
1716
FROM registry:$REGISTRY_VERSION AS registry
18-
FROM moby/buildkit:$BUILDKIT_VERSION AS buildkit
1917
FROM crazymax/undock:$UNDOCK_VERSION AS undock
2018

2119
FROM golatest AS gobase
@@ -92,8 +90,6 @@ COPY --link --from=gotestsum /out/gotestsum /usr/bin/
9290
COPY --link --from=registry /bin/registry /usr/bin/
9391
COPY --link --from=docker-engine / /usr/bin/
9492
COPY --link --from=docker-cli / /usr/bin/
95-
COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/
96-
COPY --link --from=buildkit /usr/bin/buildctl /usr/bin/
9793
COPY --link --from=undock /usr/local/bin/undock /usr/bin/
9894
COPY --link --from=binaries /buildx /usr/bin/
9995

docker-bake.hcl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,13 @@ variable "HTTPS_PROXY" {
180180
variable "NO_PROXY" {
181181
default = ""
182182
}
183-
variable "TEST_BUILDKIT_TAG" {
184-
default = null
185-
}
186183

187184
target "integration-test-base" {
188185
inherits = ["_common"]
189186
args = {
190187
HTTP_PROXY = HTTP_PROXY
191188
HTTPS_PROXY = HTTPS_PROXY
192189
NO_PROXY = NO_PROXY
193-
BUILDKIT_VERSION = TEST_BUILDKIT_TAG
194190
}
195191
target = "integration-test-base"
196192
output = ["type=cacheonly"]

tests/workers/docker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ func InitDockerWorker() {
2424
type dockerWorker struct {
2525
id string
2626
containerdSnapshotter bool
27-
unsupported []string
27+
28+
unsupported []string
2829
}
2930

3031
func (c dockerWorker) Name() string {

tests/workers/remote.go

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@ package workers
22

33
import (
44
"context"
5+
"fmt"
6+
"net"
57
"os"
68
"os/exec"
9+
"sync"
710

811
"github.com/moby/buildkit/identity"
912
"github.com/moby/buildkit/util/testutil/integration"
10-
bkworkers "github.com/moby/buildkit/util/testutil/workers"
1113
"github.com/pkg/errors"
1214
)
1315

16+
var protos = []string{
17+
"docker-container",
18+
"tcp",
19+
}
20+
1421
func InitRemoteWorker() {
15-
integration.Register(&remoteWorker{
16-
id: "remote",
17-
})
22+
for _, p := range protos {
23+
integration.Register(&remoteWorker{
24+
id: "remote+" + p,
25+
proto: p,
26+
})
27+
}
1828
}
1929

2030
type remoteWorker struct {
21-
id string
31+
id string
32+
proto string
33+
2234
unsupported []string
35+
36+
docker integration.Backend
37+
dockerClose func() error
38+
dockerErr error
39+
dockerOnce sync.Once
2340
}
2441

2542
func (w remoteWorker) Name() string {
@@ -35,32 +52,71 @@ func (w remoteWorker) NetNSDetached() bool {
3552
}
3653

3754
func (w remoteWorker) New(ctx context.Context, cfg *integration.BackendConfig) (b integration.Backend, cl func() error, err error) {
38-
oci := bkworkers.OCI{ID: w.id}
39-
bk, bkclose, err := oci.New(ctx, cfg)
40-
if err != nil {
41-
return bk, cl, err
55+
w.dockerOnce.Do(func() {
56+
w.docker, w.dockerClose, w.dockerErr = dockerWorker{id: w.id}.New(ctx, cfg)
57+
})
58+
if w.dockerErr != nil {
59+
return w.docker, w.dockerClose, w.dockerErr
4260
}
4361

62+
bkCtnName := "buildkit-integration-" + identity.NewID()
4463
name := "integration-remote-" + identity.NewID()
64+
envs := append(
65+
os.Environ(),
66+
"BUILDX_CONFIG=/tmp/buildx-"+name,
67+
"DOCKER_CONTEXT="+w.docker.DockerAddress(),
68+
)
69+
70+
// random host port for buildkit container
71+
l, _ := net.Listen("tcp", ":0") //nolint:gosec
72+
_ = l.Close()
73+
bkPort := l.Addr().(*net.TCPAddr).Port
74+
75+
// create buildkit container
76+
bkCtnCmd := exec.Command("docker", "run",
77+
"-d", "--rm",
78+
"--privileged",
79+
"-p", fmt.Sprintf("%d:1234", bkPort),
80+
"--name="+bkCtnName,
81+
"moby/buildkit:buildx-stable-1",
82+
"--addr=tcp://0.0.0.0:1234",
83+
)
84+
bkCtnCmd.Env = envs
85+
if out, err := bkCtnCmd.CombinedOutput(); err != nil {
86+
return nil, nil, errors.Wrapf(err, "failed to create buildkit container %s: %s", bkCtnName, string(out))
87+
}
88+
89+
// create builder
90+
var endpoint string
91+
switch w.proto {
92+
case "docker-container":
93+
endpoint = fmt.Sprintf("docker-container://%s", bkCtnName)
94+
case "tcp":
95+
endpoint = fmt.Sprintf("tcp://localhost:%d", bkPort)
96+
default:
97+
return nil, nil, errors.Errorf("unsupported protocol %s", w.proto)
98+
}
4599
cmd := exec.Command("buildx", "create",
46100
"--bootstrap",
47101
"--name="+name,
48102
"--driver=remote",
49-
bk.Address(),
103+
endpoint,
50104
)
51-
cmd.Env = append(os.Environ(), "BUILDX_CONFIG=/tmp/buildx-"+name)
52-
if err := cmd.Run(); err != nil {
53-
return nil, nil, errors.Wrapf(err, "failed to create buildx instance %s", name)
105+
cmd.Env = envs
106+
if out, err := cmd.CombinedOutput(); err != nil {
107+
return nil, nil, errors.Wrapf(err, "failed to create buildx instance %s: %s", name, string(out))
54108
}
55109

56110
cl = func() error {
57-
var err error
58-
if err1 := bkclose(); err == nil {
59-
err = err1
111+
cmd := exec.Command("docker", "container", "rm", "-f", name)
112+
cmd.Env = envs
113+
if err1 := cmd.Run(); err1 != nil {
114+
err = errors.Wrapf(err1, "failed to remove buildkit container %s", bkCtnName)
60115
}
61-
cmd := exec.Command("buildx", "rm", "-f", name)
62-
if err1 := cmd.Run(); err == nil {
63-
err = err1
116+
cmd = exec.Command("buildx", "rm", "-f", name)
117+
cmd.Env = envs
118+
if err1 := cmd.Run(); err1 != nil {
119+
err = errors.Wrapf(err1, "failed to remove buildx instance %s", name)
64120
}
65121
return err
66122
}

0 commit comments

Comments
 (0)