@@ -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,20 +80,18 @@ 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 ) {
9896 opts . Name = serviceName ;
9997 }
@@ -122,37 +120,23 @@ module.exports = async function (docker, projectName, recipe, output) {
122120}
123121
124122//ToDo: complete the compose specification
125- var buildHostConfig = function ( service ) {
123+ var buildHostConfig = function ( service , recipe ) {
126124 var output = {
127125 'RestartPolicy' : { 'Name' : service . restart }
128126 } ;
129127
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- }
128+ if ( service . volumes_from ) {
129+ for ( var volume_from of service . volumes_from ) {
130+ var vf = volume_from . split ( ':' ) ;
131+ var svf = recipe . services [ vf [ 0 ] ] ;
132+ buildVolumesHostconfig ( svf . volumes , output , vf [ 1 ] ) ;
153133 }
154134 }
155135
136+ if ( service . volumes ) {
137+ buildVolumesHostconfig ( service . volumes , output ) ;
138+ }
139+
156140 if ( service . ports && service . ports . length > 0 ) {
157141 var ports = { } ;
158142 for ( var portb of service . ports ) {
@@ -165,6 +149,53 @@ var buildHostConfig = function (service) {
165149 return output ;
166150}
167151
152+ var buildVolumesHostconfig = function ( volumes , output , type ) {
153+ if ( output [ 'Binds' ] === undefined ) {
154+ output [ 'Binds' ] = [ ] ;
155+ }
156+ for ( var volume of volumes ) {
157+ if ( typeof volume === 'string' || volume instanceof String ) {
158+ var aux = volume ;
159+ if ( type == 'ro' ) {
160+ aux += ':ro'
161+ }
162+ output [ 'Binds' ] . push ( aux ) ;
163+ } else {
164+ var volumestr = '' ;
165+ if ( volume . source && volume . target ) {
166+ volumestr += volume . source + ':' + volume . target + ':' ;
167+ }
168+ if ( volume . read_only || type == 'ro' ) {
169+ volumestr += 'ro,' ;
170+ }
171+ if ( volume . volume && volume . volume . nocopy ) {
172+ volumestr += 'nocopy,' ;
173+ }
174+ if ( volume . bind && volume . bind . propagation ) {
175+ volumestr += volume . bind . propagation + ',' ;
176+ }
177+ volumestr = volumestr . slice ( 0 , - 1 ) ;
178+ output [ 'Binds' ] . push ( volumestr ) ;
179+ }
180+ }
181+ }
182+
183+ var buildVolumes = function ( volumes , opts ) {
184+ if ( opts [ 'Volumes' ] === undefined ) {
185+ opts [ 'Volumes' ] = { } ;
186+ }
187+ for ( var volume of volumes ) {
188+ if ( typeof volume === 'string' || volume instanceof String ) {
189+ var v = volume . split ( ':' ) ;
190+ opts [ 'Volumes' ] [ v [ 1 ] ] = { } ;
191+ } else {
192+ if ( volume . target ) {
193+ opts [ 'Volumes' ] [ volume . target ] = { } ;
194+ }
195+ }
196+ }
197+ }
198+
168199var buildEnvVars = function ( service ) {
169200 var output = [ ] ;
170201
0 commit comments