mirror of https://github.com/docker/compose.git
ACI: Allow setting protocol when publishing ports
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
59a94a0a8e
commit
5f730436d4
|
@ -32,6 +32,7 @@ func ContainerToComposeProject(r containers.ContainerConfig) (types.Project, err
|
||||||
ports = append(ports, types.ServicePortConfig{
|
ports = append(ports, types.ServicePortConfig{
|
||||||
Target: p.ContainerPort,
|
Target: p.ContainerPort,
|
||||||
Published: p.HostPort,
|
Published: p.HostPort,
|
||||||
|
Protocol: p.Protocol,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,25 @@ func convertPortsToAci(service serviceConfigAciHelper) ([]containerinstance.Cont
|
||||||
return nil, nil, nil, errors.New(msg)
|
return nil, nil, nil, errors.New(msg)
|
||||||
}
|
}
|
||||||
portNumber := int32(portConfig.Target)
|
portNumber := int32(portConfig.Target)
|
||||||
|
var groupProtocol containerinstance.ContainerGroupNetworkProtocol
|
||||||
|
var containerProtocol containerinstance.ContainerNetworkProtocol
|
||||||
|
switch portConfig.Protocol {
|
||||||
|
case "tcp", "":
|
||||||
|
groupProtocol = containerinstance.TCP
|
||||||
|
containerProtocol = containerinstance.ContainerNetworkProtocolTCP
|
||||||
|
case "udp":
|
||||||
|
groupProtocol = containerinstance.UDP
|
||||||
|
containerProtocol = containerinstance.ContainerNetworkProtocolUDP
|
||||||
|
default:
|
||||||
|
return nil, nil, nil, fmt.Errorf("unknown protocol %q in exposed port for service %q", portConfig.Protocol, service.Name)
|
||||||
|
}
|
||||||
containerPorts = append(containerPorts, containerinstance.ContainerPort{
|
containerPorts = append(containerPorts, containerinstance.ContainerPort{
|
||||||
Port: to.Int32Ptr(portNumber),
|
Port: to.Int32Ptr(portNumber),
|
||||||
|
Protocol: containerProtocol,
|
||||||
})
|
})
|
||||||
groupPorts = append(groupPorts, containerinstance.Port{
|
groupPorts = append(groupPorts, containerinstance.Port{
|
||||||
Port: to.Int32Ptr(portNumber),
|
Port: to.Int32Ptr(portNumber),
|
||||||
Protocol: containerinstance.TCP,
|
Protocol: groupProtocol,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
var dnsLabelName *string = nil
|
var dnsLabelName *string = nil
|
||||||
|
|
|
@ -173,3 +173,85 @@ func TestPortConvert(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertTCPPortsToAci(t *testing.T) {
|
||||||
|
service := types.ServiceConfig{
|
||||||
|
Name: "myService",
|
||||||
|
Ports: []types.ServicePortConfig{
|
||||||
|
{
|
||||||
|
Protocol: "",
|
||||||
|
Target: 80,
|
||||||
|
Published: 80,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
Target: 90,
|
||||||
|
Published: 90,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
containerPorts, groupPports, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.DeepEqual(t, containerPorts, []containerinstance.ContainerPort{
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
Protocol: containerinstance.ContainerNetworkProtocolTCP,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(90),
|
||||||
|
Protocol: containerinstance.ContainerNetworkProtocolTCP,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.DeepEqual(t, groupPports, []containerinstance.Port{
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
Protocol: containerinstance.TCP,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(90),
|
||||||
|
Protocol: containerinstance.TCP,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertUDPPortsToAci(t *testing.T) {
|
||||||
|
service := types.ServiceConfig{
|
||||||
|
Name: "myService",
|
||||||
|
Ports: []types.ServicePortConfig{
|
||||||
|
{
|
||||||
|
Protocol: "udp",
|
||||||
|
Target: 80,
|
||||||
|
Published: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
containerPorts, groupPports, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.DeepEqual(t, containerPorts, []containerinstance.ContainerPort{
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
Protocol: containerinstance.ContainerNetworkProtocolUDP,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.DeepEqual(t, groupPports, []containerinstance.Port{
|
||||||
|
{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
Protocol: containerinstance.UDP,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConvertErrorOnMappingPorts(t *testing.T) {
|
||||||
|
service := types.ServiceConfig{
|
||||||
|
Name: "myService",
|
||||||
|
Ports: []types.ServicePortConfig{
|
||||||
|
{
|
||||||
|
Protocol: "",
|
||||||
|
Target: 80,
|
||||||
|
Published: 90,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, _, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||||
|
assert.Error(t, err, "Port mapping is not supported with ACI, cannot map port 90 to 80 for container myService")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue