diff --git a/azure/convert/convert.go b/azure/convert/convert.go index 672df83a4..ba8510995 100644 --- a/azure/convert/convert.go +++ b/azure/convert/convert.go @@ -81,6 +81,7 @@ func ToContainerGroup(aciContext store.AciContext, p compose.Project) (container }, } + var groupPorts []containerinstance.Port for _, s := range project.Services { service := serviceConfigAciHelper(s) containerDefinition, err := service.getAciContainer(volumesCache) @@ -89,7 +90,6 @@ func ToContainerGroup(aciContext store.AciContext, p compose.Project) (container } if service.Ports != nil { var containerPorts []containerinstance.ContainerPort - var groupPorts []containerinstance.Port for _, portConfig := range service.Ports { if portConfig.Published != 0 && portConfig.Published != portConfig.Target { msg := fmt.Sprintf("Port mapping is not supported with ACI, cannot map port %d to %d for container %s", diff --git a/azure/convert/convert_test.go b/azure/convert/convert_test.go index ba583fce8..b4e950b99 100644 --- a/azure/convert/convert_test.go +++ b/azure/convert/convert_test.go @@ -160,6 +160,57 @@ func (suite *ConvertTestSuite) TestComposeSingleContainerGroupToContainerNoDnsSi Expect(*(*group.Containers)[0].Image).To(Equal("image1")) } +func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerMultiplePorts() { + project := compose.Project{ + Name: "", + Config: types.Config{ + Services: []types.ServiceConfig{ + { + Name: "service1", + Image: "image1", + Ports: []types.ServicePortConfig{ + { + Published: 80, + Target: 80, + }, + }, + }, + { + Name: "service2", + Image: "image2", + Ports: []types.ServicePortConfig{ + { + Published: 8080, + Target: 8080, + }, + }, + }, + }, + }, + } + + group, err := ToContainerGroup(suite.ctx, project) + Expect(err).To(BeNil()) + Expect(len(*group.Containers)).To(Equal(3)) + + container1 := (*group.Containers)[0] + container2 := (*group.Containers)[1] + Expect(*container1.Name).To(Equal("service1")) + Expect(*container1.Image).To(Equal("image1")) + portsC1 := *container1.Ports + Expect(*portsC1[0].Port).To(Equal(int32(80))) + + Expect(*container2.Name).To(Equal("service2")) + Expect(*container2.Image).To(Equal("image2")) + portsC2 := *container2.Ports + Expect(*portsC2[0].Port).To(Equal(int32(8080))) + + groupPorts := *group.IPAddress.Ports + Expect(len(groupPorts)).To(Equal(2)) + Expect(*groupPorts[0].Port).To(Equal(int32(80))) + Expect(*groupPorts[1].Port).To(Equal(int32(8080))) +} + func TestConvertTestSuite(t *testing.T) { RegisterTestingT(t) suite.Run(t, new(ConvertTestSuite)) diff --git a/tests/composefiles/aci-demo/aci_demo_multi_port.yaml b/tests/composefiles/aci-demo/aci_demo_multi_port.yaml new file mode 100644 index 000000000..c4b6f4f81 --- /dev/null +++ b/tests/composefiles/aci-demo/aci_demo_multi_port.yaml @@ -0,0 +1,17 @@ +version: '3.3' + +services: + db: + build: db + image: gtardif/sentences-db + + words: + build: words + image: gtardif/sentences-api + ports: + - "8080:8080" + web: + build: web + image: gtardif/sentences-web + ports: + - "80:80" \ No newline at end of file