bake: multi ips support for extra hosts

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-06-16 11:55:17 +02:00
parent eb43f4c237
commit 989978a42b
6 changed files with 47 additions and 15 deletions
+3
View File
@@ -2167,11 +2167,14 @@ func testBakeExtraHosts(t *testing.T, sb integration.Sandbox) {
dockerfile := []byte(`
FROM busybox
RUN cat /etc/hosts | grep myhost | grep 1.2.3.4
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.81
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.82
`)
bakefile := []byte(`
target "default" {
extra-hosts = {
myhost = "1.2.3.4"
myhostmulti = "162.242.195.81,162.242.195.82"
}
}
`)
+19
View File
@@ -77,6 +77,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
testBuildDefaultLoad,
testBuildCall,
testCheckCallOutput,
testBuildExtraHosts,
}
func testBuild(t *testing.T, sb integration.Sandbox) {
@@ -1322,6 +1323,24 @@ cOpy Dockerfile .
})
}
func testBuildExtraHosts(t *testing.T, sb integration.Sandbox) {
dockerfile := []byte(`
FROM busybox
RUN cat /etc/hosts | grep myhost | grep 1.2.3.4
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.81
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.82
`)
dir := tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))
cmd := buildxCmd(sb, withArgs("build",
"--add-host=myhost=1.2.3.4",
"--add-host=myhostmulti=162.242.195.81",
"--add-host=myhostmulti=162.242.195.82",
"--output=type=cacheonly", dir),
)
out, err := cmd.CombinedOutput()
require.NoError(t, err, string(out))
}
func createTestProject(t *testing.T) string {
dockerfile := []byte(`
FROM busybox:latest AS base