@@ -43,8 +43,8 @@ const (
43
43
StatusRunning = "Running"
44
44
// ComposeDNSSidecarName name of the dns sidecar container
45
45
ComposeDNSSidecarName = "aci--dns--sidecar"
46
- dnsSidecarImage = "busybox:1.31.1"
47
46
47
+ dnsSidecarImage = "busybox:1.31.1"
48
48
azureFileDriverName = "azure_file"
49
49
volumeDriveroptsShareNameKey = "share_name"
50
50
volumeDriveroptsAccountNameKey = "storage_account_name"
@@ -93,6 +93,7 @@ func ToContainerGroup(ctx context.Context, aciContext store.AciContext, p types.
93
93
}
94
94
95
95
var groupPorts []containerinstance.Port
96
+ var dnsLabelName * string
96
97
for _ , s := range project .Services {
97
98
service := serviceConfigAciHelper (s )
98
99
containerDefinition , err := service .getAciContainer (volumesCache )
@@ -102,32 +103,29 @@ func ToContainerGroup(ctx context.Context, aciContext store.AciContext, p types.
102
103
if service .Labels != nil && len (service .Labels ) > 0 {
103
104
return containerinstance.ContainerGroup {}, errors .New ("ACI integration does not support labels in compose applications" )
104
105
}
105
- if service .Ports != nil {
106
- var containerPorts []containerinstance.ContainerPort
107
- for _ , portConfig := range service .Ports {
108
- if portConfig .Published != 0 && portConfig .Published != portConfig .Target {
109
- msg := fmt .Sprintf ("Port mapping is not supported with ACI, cannot map port %d to %d for container %s" ,
110
- portConfig .Published , portConfig .Target , service .Name )
111
- return groupDefinition , errors .New (msg )
112
- }
113
- portNumber := int32 (portConfig .Target )
114
- containerPorts = append (containerPorts , containerinstance.ContainerPort {
115
- Port : to .Int32Ptr (portNumber ),
116
- })
117
- groupPorts = append (groupPorts , containerinstance.Port {
118
- Port : to .Int32Ptr (portNumber ),
119
- Protocol : containerinstance .TCP ,
120
- })
121
- }
122
- containerDefinition .ContainerProperties .Ports = & containerPorts
123
- groupDefinition .ContainerGroupProperties .IPAddress = & containerinstance.IPAddress {
124
- Type : containerinstance .Public ,
125
- Ports : & groupPorts ,
106
+
107
+ containerPorts , serviceGroupPorts , serviceDomainName , err := convertPortsToAci (service )
108
+ if err != nil {
109
+ return groupDefinition , err
110
+ }
111
+ containerDefinition .ContainerProperties .Ports = & containerPorts
112
+ groupPorts = append (groupPorts , serviceGroupPorts ... )
113
+ if serviceDomainName != nil {
114
+ if dnsLabelName != nil && * serviceDomainName != * dnsLabelName {
115
+ return containerinstance.ContainerGroup {}, fmt .Errorf ("ACI integration does not support specifying different domain names on services in the same compose application" )
126
116
}
117
+ dnsLabelName = serviceDomainName
127
118
}
128
119
129
120
containers = append (containers , containerDefinition )
130
121
}
122
+ if len (groupPorts ) > 0 {
123
+ groupDefinition .ContainerGroupProperties .IPAddress = & containerinstance.IPAddress {
124
+ Type : containerinstance .Public ,
125
+ Ports : & groupPorts ,
126
+ DNSNameLabel : dnsLabelName ,
127
+ }
128
+ }
131
129
if len (containers ) > 1 {
132
130
dnsSideCar := getDNSSidecar (containers )
133
131
containers = append (containers , dnsSideCar )
@@ -137,6 +135,31 @@ func ToContainerGroup(ctx context.Context, aciContext store.AciContext, p types.
137
135
return groupDefinition , nil
138
136
}
139
137
138
+ func convertPortsToAci (service serviceConfigAciHelper ) ([]containerinstance.ContainerPort , []containerinstance.Port , * string , error ) {
139
+ var groupPorts []containerinstance.Port
140
+ var containerPorts []containerinstance.ContainerPort
141
+ for _ , portConfig := range service .Ports {
142
+ if portConfig .Published != 0 && portConfig .Published != portConfig .Target {
143
+ msg := fmt .Sprintf ("Port mapping is not supported with ACI, cannot map port %d to %d for container %s" ,
144
+ portConfig .Published , portConfig .Target , service .Name )
145
+ return nil , nil , nil , errors .New (msg )
146
+ }
147
+ portNumber := int32 (portConfig .Target )
148
+ containerPorts = append (containerPorts , containerinstance.ContainerPort {
149
+ Port : to .Int32Ptr (portNumber ),
150
+ })
151
+ groupPorts = append (groupPorts , containerinstance.Port {
152
+ Port : to .Int32Ptr (portNumber ),
153
+ Protocol : containerinstance .TCP ,
154
+ })
155
+ }
156
+ var dnsLabelName * string = nil
157
+ if service .DomainName != "" {
158
+ dnsLabelName = & service .DomainName
159
+ }
160
+ return containerPorts , groupPorts , dnsLabelName , nil
161
+ }
162
+
140
163
func getDNSSidecar (containers []containerinstance.Container ) containerinstance.Container {
141
164
var commands []string
142
165
for _ , container := range containers {
@@ -249,7 +272,7 @@ func (p projectAciHelper) getRestartPolicy() (containerinstance.ContainerGroupRe
249
272
restartPolicyCondition = toAciRestartPolicy (service .Deploy .RestartPolicy .Condition )
250
273
}
251
274
if alreadySpecified && restartPolicyCondition != toAciRestartPolicy (service .Deploy .RestartPolicy .Condition ) {
252
- return "" , errors .New ("ACI integration does not support specifying different restart policies on containers in the same compose application" )
275
+ return "" , errors .New ("ACI integration does not support specifying different restart policies on services in the same compose application" )
253
276
}
254
277
255
278
}
@@ -390,22 +413,30 @@ func bytesToGb(b types.UnitBytes) float64 {
390
413
}
391
414
392
415
// ContainerGroupToServiceStatus convert from an ACI container definition to service status
393
- func ContainerGroupToServiceStatus (containerID string , group containerinstance.ContainerGroup , container containerinstance.Container ) compose.ServiceStatus {
416
+ func ContainerGroupToServiceStatus (containerID string , group containerinstance.ContainerGroup , container containerinstance.Container , region string ) compose.ServiceStatus {
394
417
var replicas = 1
395
418
if GetStatus (container , group ) != StatusRunning {
396
419
replicas = 0
397
420
}
398
421
return compose.ServiceStatus {
399
422
ID : containerID ,
400
423
Name : * container .Name ,
401
- Ports : formatter .PortsToStrings (ToPorts (group .IPAddress , * container .Ports )),
424
+ Ports : formatter .PortsToStrings (ToPorts (group .IPAddress , * container .Ports ), fqdn ( group , region ) ),
402
425
Replicas : replicas ,
403
426
Desired : 1 ,
404
427
}
405
428
}
406
429
430
+ func fqdn (group containerinstance.ContainerGroup , region string ) string {
431
+ fqdn := ""
432
+ if group .IPAddress != nil && group .IPAddress .DNSNameLabel != nil && * group .IPAddress .DNSNameLabel != "" {
433
+ fqdn = * group .IPAddress .DNSNameLabel + "." + region + ".azurecontainer.io"
434
+ }
435
+ return fqdn
436
+ }
437
+
407
438
// ContainerGroupToContainer composes a Container from an ACI container definition
408
- func ContainerGroupToContainer (containerID string , cg containerinstance.ContainerGroup , cc containerinstance.Container ) containers.Container {
439
+ func ContainerGroupToContainer (containerID string , cg containerinstance.ContainerGroup , cc containerinstance.Container , region string ) containers.Container {
409
440
memLimits := 0.
410
441
if cc .Resources != nil &&
411
442
cc .Resources .Limits != nil &&
@@ -436,9 +467,9 @@ func ContainerGroupToContainer(containerID string, cg containerinstance.Containe
436
467
}
437
468
}
438
469
439
- var config * containers.RuntimeConfig = nil
470
+ var config * containers.RuntimeConfig = & containers. RuntimeConfig { FQDN : fqdn ( cg , region )}
440
471
if envVars != nil {
441
- config = & containers. RuntimeConfig { Env : envVars }
472
+ config . Env = envVars
442
473
}
443
474
c := containers.Container {
444
475
ID : containerID ,
0 commit comments