Skip to content

Commit

Permalink
test: docker host-gateway
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Oct 17, 2023
1 parent 05af608 commit 168a0c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ARG GO_VERSION=1.20.8
ARG XX_VERSION=1.2.1

ARG DOCKER_VERSION=24.0.2
ARG DOCKER_VERSION=24.0.6
ARG GOTESTSUM_VERSION=v1.9.0
ARG REGISTRY_VERSION=2.8.0
ARG BUILDKIT_VERSION=v0.11.6
Expand Down
17 changes: 17 additions & 0 deletions tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
testBuildCacheExportNotSupported,
testBuildOCIExportNotSupported,
testBuildMultiPlatformNotSupported,
testDockerHostGateway,
}

func testBuild(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -415,3 +416,19 @@ func testBuildMultiPlatformNotSupported(t *testing.T, sb integration.Sandbox) {
require.Error(t, err, string(out))
require.Contains(t, string(out), "Multi-platform build is not supported")
}

func testDockerHostGateway(t *testing.T, sb integration.Sandbox) {
dockerfile := []byte(`
FROM busybox
RUN nslookup buildx.host-gateway-ip.local
`)
dir := tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))
cmd := buildxCmd(sb, withArgs("build", "--add-host=buildx.host-gateway-ip.local:host-gateway", "--output=type=cacheonly", dir))
out, err := cmd.CombinedOutput()
if !isDockerWorker(sb) {
require.Error(t, err, string(out))
require.Contains(t, string(out), "host-gateway is not supported")
} else {
require.NoError(t, err, string(out))

Check failure on line 432 in tests/build.go

View workflow job for this annotation

GitHub Actions / test (docker, ./tests)

Failed: tests/TestIntegration/TestDockerHostGateway/worker=docker

=== RUN TestIntegration/TestDockerHostGateway/worker=docker === PAUSE TestIntegration/TestDockerHostGateway/worker=docker === CONT TestIntegration/TestDockerHostGateway/worker=docker build.go:432: Error Trace: /src/tests/build.go:432 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:91 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:205 Error: Received unexpected error: exit status 1 Test: TestIntegration/TestDockerHostGateway/worker=docker Messages: #0 building with "integration-3t702zr392304nyrr9jwpi24y" instance using docker driver #1 [internal] load build definition from Dockerfile #1 transferring dockerfile: 93B done #1 DONE 0.0s #2 [internal] load .dockerignore #2 transferring context: 2B done #2 DONE 0.0s #3 [internal] load metadata for docker.io/library/busybox:latest #3 DONE 0.0s #4 [1/2] FROM docker.io/library/busybox@sha256:023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee #4 resolve docker.io/library/busybox@sha256:023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee done #4 extracting sha256:3f4d90098f5b5a6f6a76e9d217da85aa39b2081e30fa1f7d287138d6e7bf0ad7 #4 sha256:023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee 528B / 528B done #4 sha256:a416a98b71e224a31ee99cff8e16063554498227d2b696152a9c3e0aa65e5824 1.46kB / 1.46kB done #4 sha256:3f4d90098f5b5a6f6a76e9d217da85aa39b2081e30fa1f7d287138d6e7bf0ad7 2.22MB / 2.22MB 0.0s done #4 extracting sha256:3f4d90098f5b5a6f6a76e9d217da85aa39b2081e30fa1f7d287138d6e7bf0ad7 0.1s done #4 DONE 0.1s #5 [2/2] RUN nslookup buildx.host-gateway-ip.local #5 0.200 Server: 168.63.129.16 #5 0.200 Address: 168.63.129.16:53 #5 0.200 #5 0.200 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN #5 0.200 #5 0.200 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN #5 0.200 #5 ERROR: process "/bin/sh -c nslookup buildx.host-gateway-ip.local" did not complete successfully: exit code: 1 ------ > [2/2] RUN nslookup buildx.host-gateway-ip.local: 0.200 Server: 168.63.129.16 0.200 Address: 168.63.129.16:53 0.200 0.200 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN 0.200 0.200 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN 0.200 ------ Dockerfile:3 -------------------- 1 | 2 | FROM busybox 3 | >>> RUN nslookup buildx.host-gateway-ip.local 4 | -------------------- ERROR: failed to solve: process "/bin/sh -c nslookup buildx.host-gateway-ip.local" did not complete successfully: exit code: 1 sandbox.go:128: stdout: /usr/bin/dockerd sandbox.go:131: Server: 168.63.129.16 sandbox.go:131: Address: 168.63.129.16:53 sandbox.go:131: sandbox.go:131: ** server can't find buildx.host-gateway-ip.local: NXDOMAIN sandbox.go:131: sandbox.go:131: ** server can't find buildx.host-gateway-ip.local: NXDOMAIN sandbox.go:131: sandbox.go:128: stderr: /usr

Check failure on line 432 in tests/build.go

View workflow job for this annotation

GitHub Actions / test (docker\+containerd, ./tests)

Failed: tests/TestIntegration/TestDockerHostGateway/worker=docker+containerd

=== RUN TestIntegration/TestDockerHostGateway/worker=docker+containerd === PAUSE TestIntegration/TestDockerHostGateway/worker=docker+containerd === CONT TestIntegration/TestDockerHostGateway/worker=docker+containerd build.go:432: Error Trace: /src/tests/build.go:432 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:91 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:205 Error: Received unexpected error: exit status 1 Test: TestIntegration/TestDockerHostGateway/worker=docker+containerd Messages: #0 building with "integration-xezunaysmdtgjbs1fyqwjt9pl" instance using docker driver #1 [internal] load build definition from Dockerfile #1 transferring dockerfile: 93B done #1 DONE 0.0s #2 [internal] load .dockerignore #2 transferring context: 2B done #2 DONE 0.0s #3 [internal] load metadata for docker.io/library/busybox:latest #3 DONE 0.0s #4 [1/2] FROM docker.io/library/busybox@sha256:023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee #4 resolve docker.io/library/busybox@sha256:023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee done #4 sha256:3f4d90098f5b5a6f6a76e9d217da85aa39b2081e30fa1f7d287138d6e7bf0ad7 2.22MB / 2.22MB 0.0s done #4 extracting sha256:3f4d90098f5b5a6f6a76e9d217da85aa39b2081e30fa1f7d287138d6e7bf0ad7 0.1s done #4 DONE 0.1s #5 [2/2] RUN nslookup buildx.host-gateway-ip.local #5 0.183 Server: 168.63.129.16 #5 0.183 Address: 168.63.129.16:53 #5 0.183 #5 0.183 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN #5 0.183 #5 0.183 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN #5 0.183 #5 ERROR: process "/bin/sh -c nslookup buildx.host-gateway-ip.local" did not complete successfully: exit code: 1 ------ > [2/2] RUN nslookup buildx.host-gateway-ip.local: 0.183 Server: 168.63.129.16 0.183 Address: 168.63.129.16:53 0.183 0.183 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN 0.183 0.183 ** server can't find buildx.host-gateway-ip.local: NXDOMAIN 0.183 ------ Dockerfile:3 -------------------- 1 | 2 | FROM busybox 3 | >>> RUN nslookup buildx.host-gateway-ip.local 4 | -------------------- ERROR: failed to solve: process "/bin/sh -c nslookup buildx.host-gateway-ip.local" did not complete successfully: exit code: 1 sandbox.go:128: stdout: /usr/bin/dockerd sandbox.go:131: Server: 168.63.129.16 sandbox.go:131: Address: 168.63.129.16:53 sandbox.go:131: sandbox.go:131: ** server can't find buildx.host-gateway-ip.local: NXDOMAIN sandbox.go:131: sandbox.go:131: ** server can't find buildx.host-gateway-ip.local: NXDOMAIN sandbox.go:131: sandbox.go:128: stderr: /usr/bin/dockerd sandbox.go:131: > startCmd 2023-10-17 09:06:03.024154311 +0000 UTC m=+7.268437554 /usr/bin/dockerd --data-root /tmp/integration3070350915/dfjxzmt6j50lh/root --exec-root /tmp/dxr/dfjxzmt6j50lh --pidfile /tmp/integration3070350915/dfjxzmt6j50lh/docker.pid --containerd-namespace df
}
}
9 changes: 9 additions & 0 deletions tests/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ func testInspect(t *testing.T, sb integration.Sandbox) {

var name string
var driver string
var hostGatewayIP string
for _, line := range strings.Split(out, "\n") {
if v, ok := strings.CutPrefix(line, "Name:"); ok && name == "" {
name = strings.TrimSpace(v)
}
if v, ok := strings.CutPrefix(line, "Driver:"); ok && driver == "" {
driver = strings.TrimSpace(v)
}
if v, ok := strings.CutPrefix(line, " org.mobyproject.buildkit.worker.moby.host-gateway-ip:"); ok {
hostGatewayIP = strings.TrimSpace(v)
}
}

require.Equal(t, sb.Address(), name)
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
require.Equal(t, sbDriver, driver)
if isDockerWorker(sb) {
require.NotEmpty(t, hostGatewayIP, "host-gateway-ip worker label should be set with docker driver")
} else {
require.Empty(t, hostGatewayIP, "host-gateway-ip worker label should not be set with non-docker driver")
}
}

0 comments on commit 168a0c9

Please sign in to comment.