@@ -21,122 +21,60 @@ module.exports = async function (docker, projectName, recipe) {
2121
2222 if ( service . networks !== undefined ) {
2323 console . log ( service . networks )
24+ //if netowrks > 1 (It doesnt seem possible to start a container by connecting to multiple networks at once.)
25+ // To connect multiple networks "docker network connect" is used to connect additional networks.
26+ // have to attach the network after container creation
27+ // https://github.com/moby/moby/issues/29265
2428 if ( Array . isArray ( service . networks ) ) {
25- if ( service . networks . length > 1 ) {
26- //if netowrks > 1 (It doesnt seem possible to start a container by connecting to multiple networks at once.)
27- // To connect multiple networks "docker network connect" is used to connect additional networks.
28- // have to attach the network after container creation
29- // https://github.com/moby/moby/issues/29265
30- for ( let index = 0 ; index < service . networks . length ; index ++ ) {
31- let networkName = projectName + '_' + service . networks [ index ]
32- if ( index === 0 ) {
33- opts . NetworkingConfig . EndpointsConfig [ networkName ] = { } ;
34- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = [ serviceName ]
35- } else {
36- let networkTemplate = {
37- 'NetworkingConfig' : {
38- 'EndpointsConfig' : {
39- }
40- }
29+ for ( let index = 0 ; index < service . networks . length ; index ++ ) {
30+ let networkName = projectName + '_' + service . networks [ index ]
31+ let networkTemplate = {
32+ 'NetworkingConfig' : {
33+ 'EndpointsConfig' : {
4134 }
42- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] = { } ;
43- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = [ serviceName ]
44- networksToAttach . push ( networkTemplate )
4535 }
4636 }
47- } else {
48- let networkName = projectName + '_' + service . networks [ 0 ]
49- opts . NetworkingConfig . EndpointsConfig [ networkName ] = { } ;
50- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = [ serviceName ]
37+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] = { } ;
38+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = [ serviceName ]
39+ if ( index === 0 ) {
40+ opts . NetworkingConfig = networkTemplate . NetworkingConfig
41+ } else {
42+ networksToAttach . push ( networkTemplate )
43+ }
5144 }
5245 } else {
53- // ToDo: Simplify this code block
5446 let networkNames = Object . keys ( service . networks ) ;
55- if ( networkNames . length > 1 ) {
56- //if netowrks > 1 (It doesnt seem possible to start a container by connecting to multiple networks at once.)
57- // To connect multiple networks "docker network connect" is used to connect additional networks.
58- // have to attach the network after container creations
59- // https://github.com/moby/moby/issues/29265
60- for ( let index = 0 ; index < networkNames . length ; index ++ ) {
61- let network = service . networks [ networkNames [ index ] ] ;
62- let networkName = projectName + '_' + networkNames [ index ]
63- console . log ( network )
64- console . log ( networkName )
65- if ( index === 0 ) {
66- opts . NetworkingConfig . EndpointsConfig [ networkName ] = { }
67- if ( network . aliases !== undefined ) {
68- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = network . aliases
69- }
70-
71- if ( network . ipv4_address !== undefined ) {
72- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv4Address' ] = network . ipv4_address
73- }
74-
75- if ( network . ipv6_address !== undefined ) {
76- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv6Address' ] = network . ipv6_address
77- }
78-
79- if ( network . link_local_ips !== undefined ) {
80- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'LinkLocalIPs' ] = network . link_local_ips
81- }
82-
83- if ( network . priority !== undefined ) {
84- //priority ??? - priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.
85- }
86- } else {
87- let networkTemplate = {
88- 'NetworkingConfig' : {
89- 'EndpointsConfig' : {
90- }
91- }
92- }
93- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] = { }
94- if ( network . aliases !== undefined ) {
95- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = network . aliases
96- }
97-
98- if ( network . ipv4_address !== undefined ) {
99- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv4Address' ] = network . ipv4_address
100- }
101-
102- if ( network . ipv6_address !== undefined ) {
103- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv6Address' ] = network . ipv6_address
104- }
105-
106- if ( network . link_local_ips !== undefined ) {
107- networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'LinkLocalIPs' ] = network . link_local_ips
47+ for ( let index = 0 ; index < networkNames . length ; index ++ ) {
48+ let network = service . networks [ networkNames [ index ] ] ;
49+ let networkName = projectName + '_' + networkNames [ index ]
50+ console . log ( network )
51+ console . log ( networkName )
52+ let networkTemplate = {
53+ 'NetworkingConfig' : {
54+ 'EndpointsConfig' : {
10855 }
109-
110- if ( network . priority !== undefined ) {
111- //priority ??? - priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.
112- }
113- networksToAttach . push ( networkTemplate )
11456 }
11557 }
116- } else {
117- for ( var networkName of networkNames ) {
118- let network = service . networks [ networkName ] ;
119- networkName = projectName + '_' + networkName
120- opts . NetworkingConfig . EndpointsConfig [ networkName ] = { }
121- if ( network . aliases !== undefined ) {
122- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = network . aliases
123- }
124-
125- if ( network . ipv4_address !== undefined ) {
126- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv4Address' ] = network . ipv4_address
127- }
128-
129- if ( network . ipv6_address !== undefined ) {
130- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv6Address' ] = network . ipv6_address
131- }
132-
133- if ( network . link_local_ips !== undefined ) {
134- opts . NetworkingConfig . EndpointsConfig [ networkName ] [ 'LinkLocalIPs' ] = network . link_local_ips
135- }
136-
137- if ( network . priority !== undefined ) {
138- //priority ??? - priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.
139- }
58+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] = { }
59+ if ( network . aliases !== undefined ) {
60+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'Aliases' ] = network . aliases
61+ }
62+ if ( network . ipv4_address !== undefined ) {
63+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv4Address' ] = network . ipv4_address
64+ }
65+ if ( network . ipv6_address !== undefined ) {
66+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'IPv6Address' ] = network . ipv6_address
67+ }
68+ if ( network . link_local_ips !== undefined ) {
69+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] [ 'LinkLocalIPs' ] = network . link_local_ips
70+ }
71+ if ( network . priority !== undefined ) {
72+ //priority ??? - priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.
73+ }
74+ if ( index === 0 ) {
75+ opts . NetworkingConfig = networkTemplate . NetworkingConfig
76+ } else {
77+ networksToAttach . push ( networkTemplate )
14078 }
14179 }
14280 }
0 commit comments