mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-20 10:27:46 +08:00
test: docker host-gateway
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
05af608774
commit
6c32a8c4c1
@ -3,7 +3,7 @@
|
|||||||
ARG GO_VERSION=1.20.8
|
ARG GO_VERSION=1.20.8
|
||||||
ARG XX_VERSION=1.2.1
|
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 GOTESTSUM_VERSION=v1.9.0
|
||||||
ARG REGISTRY_VERSION=2.8.0
|
ARG REGISTRY_VERSION=2.8.0
|
||||||
ARG BUILDKIT_VERSION=v0.11.6
|
ARG BUILDKIT_VERSION=v0.11.6
|
||||||
|
@ -47,6 +47,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
|
|||||||
testBuildCacheExportNotSupported,
|
testBuildCacheExportNotSupported,
|
||||||
testBuildOCIExportNotSupported,
|
testBuildOCIExportNotSupported,
|
||||||
testBuildMultiPlatformNotSupported,
|
testBuildMultiPlatformNotSupported,
|
||||||
|
testDockerHostGateway,
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBuild(t *testing.T, sb integration.Sandbox) {
|
func testBuild(t *testing.T, sb integration.Sandbox) {
|
||||||
@ -415,3 +416,19 @@ func testBuildMultiPlatformNotSupported(t *testing.T, sb integration.Sandbox) {
|
|||||||
require.Error(t, err, string(out))
|
require.Error(t, err, string(out))
|
||||||
require.Contains(t, string(out), "Multi-platform build is not supported")
|
require.Contains(t, string(out), "Multi-platform build is not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testDockerHostGateway(t *testing.T, sb integration.Sandbox) {
|
||||||
|
dockerfile := []byte(`
|
||||||
|
FROM busybox
|
||||||
|
RUN ping -c 1 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ func testInspect(t *testing.T, sb integration.Sandbox) {
|
|||||||
|
|
||||||
var name string
|
var name string
|
||||||
var driver string
|
var driver string
|
||||||
|
var hostGatewayIP string
|
||||||
for _, line := range strings.Split(out, "\n") {
|
for _, line := range strings.Split(out, "\n") {
|
||||||
if v, ok := strings.CutPrefix(line, "Name:"); ok && name == "" {
|
if v, ok := strings.CutPrefix(line, "Name:"); ok && name == "" {
|
||||||
name = strings.TrimSpace(v)
|
name = strings.TrimSpace(v)
|
||||||
@ -32,9 +33,17 @@ func testInspect(t *testing.T, sb integration.Sandbox) {
|
|||||||
if v, ok := strings.CutPrefix(line, "Driver:"); ok && driver == "" {
|
if v, ok := strings.CutPrefix(line, "Driver:"); ok && driver == "" {
|
||||||
driver = strings.TrimSpace(v)
|
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)
|
require.Equal(t, sb.Address(), name)
|
||||||
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
|
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
|
||||||
require.Equal(t, sbDriver, driver)
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user