@@ -6,31 +6,54 @@ const volumes = require('./lib/volumes');
66const configs = require ( './lib/configs' ) ;
77const networks = require ( './lib/networks' ) ;
88const services = require ( './lib/services' ) ;
9+ const tools = require ( './lib/tools' ) ;
910
1011class Compose {
11- constructor ( dockerode ) {
12+ constructor ( dockerode , file , projectName ) {
1213 this . docker = dockerode ;
14+
15+ if ( file === undefined || projectName === undefined ) {
16+ throw new Error ( 'please specify a file and a project name' ) ;
17+ }
18+
19+ this . file = file ;
20+ this . projectName = projectName ;
21+
22+ try {
23+ this . recipe = yaml . load ( fs . readFileSync ( file , 'utf8' ) ) ;
24+ } catch ( e ) {
25+ throw e ;
26+ }
1327 }
1428
15- async up ( file , projectName ) {
16- var self = this ;
29+ async up ( ) {
1730 var output = { } ;
18- if ( projectName === undefined ) {
19- throw new Error ( 'please specify a project name' ) ;
20- }
21- self . projectName = projectName ;
2231 try {
23- self . recipe = yaml . load ( fs . readFileSync ( file , 'utf8' ) ) ;
24- output . secrets = await secrets ( self . docker , self . projectName , self . recipe , output ) ;
25- output . volumes = await volumes ( self . docker , self . projectName , self . recipe , output ) ;
26- output . configs = await configs ( self . docker , self . projectName , self . recipe , output ) ;
27- output . networks = await networks ( self . docker , self . projectName , self . recipe , output ) ;
28- output . services = await services ( self . docker , self . projectName , self . recipe , output ) ;
32+ output . secrets = await secrets ( this . docker , this . projectName , this . recipe , output ) ;
33+ output . volumes = await volumes ( this . docker , this . projectName , this . recipe , output ) ;
34+ output . configs = await configs ( this . docker , this . projectName , this . recipe , output ) ;
35+ output . networks = await networks ( this . docker , this . projectName , this . recipe , output ) ;
36+ output . services = await services ( this . docker , this . projectName , this . recipe , output ) ;
2937 return output ;
3038 } catch ( e ) {
3139 throw e ;
3240 }
3341 }
42+
43+ //ToDo: create a version with followprogress with onFinished
44+ async pull ( serviceN ) {
45+ var streams = [ ] ;
46+ var serviceNames = ( serviceN !== undefined ) ? [ serviceN ] : tools . sortServices ( this . recipe ) ;
47+ for ( var serviceName of serviceNames ) {
48+ var service = this . recipe . services [ serviceName ] ;
49+ try {
50+ streams . push ( await this . docker . pull ( service . image ) ) ;
51+ } catch ( e ) {
52+ throw e ;
53+ }
54+ }
55+ return streams ;
56+ }
3457}
3558
3659module . exports = Compose ;
0 commit comments