Skip to content

Commit 107e282

Browse files
committed
feat(compose): add ipv6-address parsing
fixes #4597 Signed-off-by: Frits <[email protected]>
1 parent 2165e30 commit 107e282

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pkg/composer/serviceparser/serviceparser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ func newContainer(project *types.Project, parsed *Service, i int) (*Container, e
597597
if value != nil && value.Ipv4Address != "" {
598598
c.RunArgs = append(c.RunArgs, "--ip="+value.Ipv4Address)
599599
}
600+
if value != nil && value.Ipv6Address != "" {
601+
c.RunArgs = append(c.RunArgs, "--ip6="+value.Ipv6Address)
602+
}
600603
if value != nil && value.MacAddress != "" {
601604
c.RunArgs = append(c.RunArgs, "--mac-address="+value.MacAddress)
602605
}

pkg/composer/serviceparser/serviceparser_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,44 @@ services:
482482

483483
}
484484

485+
func TestParseDualStackAddress(t *testing.T) {
486+
t.Parallel()
487+
const dockerComposeYAML = `
488+
services:
489+
foo:
490+
image: nginx:alpine
491+
networks:
492+
default:
493+
ipv4_address: "172.30.0.100"
494+
ipv6_address: "2001:db8:abc:123::42"
495+
networks:
496+
default:
497+
driver: bridge
498+
ipam:
499+
driver: default
500+
config:
501+
- subnet: "172.30.0.0/24"
502+
- subnet: "2001:db8:abc:123::/64"
503+
`
504+
comp := testutil.NewComposeDir(t, dockerComposeYAML)
505+
defer comp.CleanUp()
506+
507+
project, err := testutil.LoadProject(comp.YAMLFullPath(), comp.ProjectName(), nil)
508+
assert.NilError(t, err)
509+
510+
fooSvc, err := project.GetService("foo")
511+
assert.NilError(t, err)
512+
513+
foo, err := Parse(project, fooSvc)
514+
assert.NilError(t, err)
515+
516+
t.Logf("foo: %+v", foo)
517+
for _, c := range foo.Containers {
518+
assert.Assert(t, in(c.RunArgs, "--ip=172.30.0.100"))
519+
assert.Assert(t, in(c.RunArgs, "--ip6=2001:db8:abc:123::42"))
520+
}
521+
}
522+
485523
func TestParseConfigs(t *testing.T) {
486524
t.Parallel()
487525
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)