Merge pull request #268 from docker/compose_expose_miltiple_ports

Allow ACI compose to expose several ports
This commit is contained in:
Guillaume Tardif 2020-06-23 16:17:39 +02:00 committed by GitHub
commit 9789ce119b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 1 deletions

View File

@ -81,6 +81,7 @@ func ToContainerGroup(aciContext store.AciContext, p compose.Project) (container
}, },
} }
var groupPorts []containerinstance.Port
for _, s := range project.Services { for _, s := range project.Services {
service := serviceConfigAciHelper(s) service := serviceConfigAciHelper(s)
containerDefinition, err := service.getAciContainer(volumesCache) containerDefinition, err := service.getAciContainer(volumesCache)
@ -89,7 +90,6 @@ func ToContainerGroup(aciContext store.AciContext, p compose.Project) (container
} }
if service.Ports != nil { if service.Ports != nil {
var containerPorts []containerinstance.ContainerPort var containerPorts []containerinstance.ContainerPort
var groupPorts []containerinstance.Port
for _, portConfig := range service.Ports { for _, portConfig := range service.Ports {
if portConfig.Published != 0 && portConfig.Published != portConfig.Target { 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", msg := fmt.Sprintf("Port mapping is not supported with ACI, cannot map port %d to %d for container %s",

View File

@ -160,6 +160,57 @@ func (suite *ConvertTestSuite) TestComposeSingleContainerGroupToContainerNoDnsSi
Expect(*(*group.Containers)[0].Image).To(Equal("image1")) 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) { func TestConvertTestSuite(t *testing.T) {
RegisterTestingT(t) RegisterTestingT(t)
suite.Run(t, new(ConvertTestSuite)) suite.Run(t, new(ConvertTestSuite))

View File

@ -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"