@@ -10,7 +10,7 @@ module.exports = async function (docker, projectName, recipe, output) {
1010 var opts = {
1111 'name' : projectName + '_' + serviceName ,
1212 'Image' : service . image ,
13- 'HostConfig' : buildHostConfig ( service ) ,
13+ 'HostConfig' : buildHostConfig ( service , recipe ) ,
1414 'Env' : buildEnvVars ( service ) ,
1515 'NetworkingConfig' : {
1616 'EndpointsConfig' : {
@@ -80,22 +80,29 @@ module.exports = async function (docker, projectName, recipe, output) {
8080 } ;
8181 }
8282
83- if ( service . volumes ) {
84- opts [ 'Volumes' ] = { } ;
85- for ( var volume of service . volumes ) {
86- if ( typeof volume === 'string' || volume instanceof String ) {
87- var v = volume . split ( ':' ) ;
88- opts [ 'Volumes' ] [ v [ 1 ] ] = { } ;
89- } else {
90- if ( volume . target ) {
91- opts [ 'Volumes' ] [ volume . target ] = { } ;
92- }
93- }
83+ if ( service . volumes_from ) {
84+ for ( var volume_from of service . volumes_from ) {
85+ var vf = volume_from . split ( ':' ) ;
86+ var svf = recipe . services [ vf [ 0 ] ] ;
87+ buildVolumes ( svf . volumes , opts ) ;
9488 }
9589 }
9690
91+ if ( service . volumes ) {
92+ buildVolumes ( service . volumes , opts ) ;
93+ }
94+
9795 if ( service . name !== undefined ) {
98- opts . Name = serviceName ;
96+ opts . Name = service . container_name || serviceName ;
97+ }
98+ if ( service . domainname !== undefined ) {
99+ opts . Domainname = service . domainname ;
100+ }
101+ if ( service . hostname !== undefined ) {
102+ opts . Hostname = service . hostname ;
103+ }
104+ if ( service . mac_address !== undefined ) {
105+ opts . MacAddress = service . mac_address ;
99106 }
100107 try {
101108 var container = await docker . createContainer ( opts ) ;
@@ -122,37 +129,23 @@ module.exports = async function (docker, projectName, recipe, output) {
122129}
123130
124131//ToDo: complete the compose specification
125- var buildHostConfig = function ( service ) {
132+ var buildHostConfig = function ( service , recipe ) {
126133 var output = {
127134 'RestartPolicy' : { 'Name' : service . restart }
128135 } ;
129136
130- if ( service . volumes ) {
131- output [ 'Binds' ] = [ ] ;
132-
133- for ( var volume of service . volumes ) {
134- if ( typeof volume === 'string' || volume instanceof String ) {
135- output [ 'Binds' ] . push ( volume ) ;
136- } else {
137- var volumestr = '' ;
138- if ( volume . source && volume . target ) {
139- volumestr += volume . source + ':' + volume . target + ':' ;
140- }
141- if ( volume . read_only ) {
142- volumestr += 'ro,' ;
143- }
144- if ( volume . volume && volume . volume . nocopy ) {
145- volumestr += 'nocopy,' ;
146- }
147- if ( volume . bind && volume . bind . propagation ) {
148- volumestr += volume . bind . propagation + ',' ;
149- }
150- volumestr = volumestr . slice ( 0 , - 1 ) ;
151- output [ 'Binds' ] . push ( volumestr ) ;
152- }
137+ if ( service . volumes_from ) {
138+ for ( var volume_from of service . volumes_from ) {
139+ var vf = volume_from . split ( ':' ) ;
140+ var svf = recipe . services [ vf [ 0 ] ] ;
141+ buildVolumesHostconfig ( svf . volumes , output , vf [ 1 ] ) ;
153142 }
154143 }
155144
145+ if ( service . volumes ) {
146+ buildVolumesHostconfig ( service . volumes , output ) ;
147+ }
148+
156149 if ( service . ports && service . ports . length > 0 ) {
157150 var ports = { } ;
158151 for ( var portb of service . ports ) {
@@ -162,9 +155,132 @@ var buildHostConfig = function (service) {
162155 output [ 'PortBindings' ] = ports ;
163156 }
164157
158+ if ( service . cpu_count !== undefined ) {
159+ opts . CpuCount = service . cpu_count ;
160+ }
161+ if ( service . cpu_percent !== undefined ) {
162+ opts . CpuPercent = service . cpu_percent ;
163+ }
164+ if ( service . cpu_shares !== undefined ) {
165+ opts . CpuShares = service . cpu_shares ;
166+ }
167+ if ( service . cpu_period !== undefined ) {
168+ opts . CpuPeriod = service . cpu_period ;
169+ }
170+ if ( service . cpu_quota !== undefined ) {
171+ opts . CpuQuota = service . cpu_quota ;
172+ }
173+ if ( service . cpu_rt_runtime !== undefined ) {
174+ opts . CpuRealtimeRuntime = service . cpu_rt_runtime ;
175+ }
176+ if ( service . cpu_rt_period !== undefined ) {
177+ opts . CpuRealtimePeriod = service . cpu_rt_period ;
178+ }
179+ if ( service . cpuset !== undefined ) {
180+ opts . CpusetCpus = service . cpuset ;
181+ }
182+ if ( service . cap_add !== undefined ) {
183+ opts . CapAdd = service . cap_add ;
184+ }
185+ if ( service . cap_drop !== undefined ) {
186+ opts . CapDrop = service . cap_drop ;
187+ }
188+ if ( service . cgroup_parent !== undefined ) {
189+ opts . CgroupParent = service . cgroup_parent ;
190+ }
191+ if ( service . device_cgroup_rules !== undefined ) {
192+ opts . DeviceCgroupRules = service . device_cgroup_rules ;
193+ }
194+ if ( service . dns !== undefined ) {
195+ opts . Dns = service . dns ;
196+ }
197+ if ( service . dns_opt !== undefined ) {
198+ opts . DnsOptions = service . dns_opt ;
199+ }
200+ if ( service . dns_search !== undefined ) {
201+ opts . DnsSearch = service . dns_search ;
202+ }
203+ if ( service . extra_hosts !== undefined ) {
204+ opts . ExtraHosts = service . extra_hosts ;
205+ }
206+ if ( service . group_add !== undefined ) {
207+ opts . GroupAdd = service . group_add ;
208+ }
209+ if ( service . init !== undefined ) {
210+ opts . Init = service . init ;
211+ }
212+ if ( service . ipc !== undefined ) {
213+ opts . IpcMode = service . ipc ;
214+ }
215+ if ( service . isolation !== undefined ) {
216+ opts . Isolation = service . isolation ;
217+ }
218+ if ( service . mem_swappiness !== undefined ) {
219+ opts . MemorySwappiness = service . mem_swappiness ;
220+ }
221+ if ( service . oom_kill_disable !== undefined ) {
222+ opts . OomKillDisable = service . oom_kill_disable ;
223+ }
224+ if ( service . oom_score_adj !== undefined ) {
225+ opts . OomScoreAdj = service . oom_score_adj ;
226+ }
227+ if ( service . pid !== undefined ) {
228+ opts . PidMode = service . pid ;
229+ }
230+ if ( service . pids_limit !== undefined ) {
231+ opts . PidsLimit = service . pids_limit ;
232+ }
233+
165234 return output ;
166235}
167236
237+ var buildVolumesHostconfig = function ( volumes , output , type ) {
238+ if ( output [ 'Binds' ] === undefined ) {
239+ output [ 'Binds' ] = [ ] ;
240+ }
241+ for ( var volume of volumes ) {
242+ if ( typeof volume === 'string' || volume instanceof String ) {
243+ var aux = volume ;
244+ if ( type == 'ro' ) {
245+ aux += ':ro'
246+ }
247+ output [ 'Binds' ] . push ( aux ) ;
248+ } else {
249+ var volumestr = '' ;
250+ if ( volume . source && volume . target ) {
251+ volumestr += volume . source + ':' + volume . target + ':' ;
252+ }
253+ if ( volume . read_only || type == 'ro' ) {
254+ volumestr += 'ro,' ;
255+ }
256+ if ( volume . volume && volume . volume . nocopy ) {
257+ volumestr += 'nocopy,' ;
258+ }
259+ if ( volume . bind && volume . bind . propagation ) {
260+ volumestr += volume . bind . propagation + ',' ;
261+ }
262+ volumestr = volumestr . slice ( 0 , - 1 ) ;
263+ output [ 'Binds' ] . push ( volumestr ) ;
264+ }
265+ }
266+ }
267+
268+ var buildVolumes = function ( volumes , opts ) {
269+ if ( opts [ 'Volumes' ] === undefined ) {
270+ opts [ 'Volumes' ] = { } ;
271+ }
272+ for ( var volume of volumes ) {
273+ if ( typeof volume === 'string' || volume instanceof String ) {
274+ var v = volume . split ( ':' ) ;
275+ opts [ 'Volumes' ] [ v [ 1 ] ] = { } ;
276+ } else {
277+ if ( volume . target ) {
278+ opts [ 'Volumes' ] [ volume . target ] = { } ;
279+ }
280+ }
281+ }
282+ }
283+
168284var buildEnvVars = function ( service ) {
169285 var output = [ ] ;
170286
0 commit comments