Skip to content

Commit 68d6300

Browse files
committed
bake: multi ips support for extra hosts
Signed-off-by: CrazyMax <[email protected]>
1 parent eb43f4c commit 68d6300

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

bake/bake.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,9 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
14361436
if v == nil {
14371437
continue
14381438
}
1439-
extraHosts = append(extraHosts, fmt.Sprintf("%s=%s", k, *v))
1439+
for _, ip := range strings.Split(*v, ",") {
1440+
extraHosts = append(extraHosts, fmt.Sprintf("%s=%s", k, ip))
1441+
}
14401442
}
14411443

14421444
bo := &build.Options{

bake/compose.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
125125
extraHosts := map[string]*string{}
126126
if s.Build.ExtraHosts != nil {
127127
for k, v := range s.Build.ExtraHosts {
128-
for _, ip := range v {
129-
vv := ip
130-
extraHosts[k] = &vv
131-
}
128+
vv := strings.Join(v, ",")
129+
extraHosts[k] = &vv
132130
}
133131
}
134132

tests/bake.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,11 +2167,14 @@ func testBakeExtraHosts(t *testing.T, sb integration.Sandbox) {
21672167
dockerfile := []byte(`
21682168
FROM busybox
21692169
RUN cat /etc/hosts | grep myhost | grep 1.2.3.4
2170+
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.81
2171+
RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.82
21702172
`)
21712173
bakefile := []byte(`
21722174
target "default" {
21732175
extra-hosts = {
21742176
myhost = "1.2.3.4"
2177+
myhostmulti = "162.242.195.81,162.242.195.82"
21752178
}
21762179
}
21772180
`)

0 commit comments

Comments
 (0)