File tree Expand file tree Collapse file tree 6 files changed +36
-12
lines changed Expand file tree Collapse file tree 6 files changed +36
-12
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,12 @@ module.exports = class Command {
23
23
}
24
24
25
25
_runInternal ( ) {
26
- log . warn ( 'Command run on base class' ) ;
26
+ log . warn ( 'Command run on base class. Please define "_runInternal()" on the child class' ) ;
27
+ return Promise . reject ( ) ;
28
+ }
29
+
30
+ cleanUp ( ) {
31
+ log . warn ( 'method "cleanUp()" not defined. Please define "cleanUp()" on the child class' ) ;
27
32
return Promise . reject ( ) ;
28
33
}
29
34
} ;
Original file line number Diff line number Diff line change 1
1
const log = require ( '../logger' ) ;
2
+ const timer = require ( '../helpers/timer' ) ;
2
3
const BaseCommand = require ( './BaseCommand' ) ;
3
4
4
5
module . exports = class NetworkCommand extends BaseCommand {
@@ -7,7 +8,12 @@ module.exports = class NetworkCommand extends BaseCommand {
7
8
}
8
9
9
10
_runInternal ( ) {
10
- return new Promise ( resolve => setTimeout ( resolve , 1000 ) )
11
+ return timer ( 1000 )
11
12
. then ( ( ) => log . info ( `network created: '${ this . name } '` ) ) ;
12
13
}
14
+
15
+ cleanUp ( ) {
16
+ return timer ( 5000 )
17
+ . then ( ( ) => log . info ( `network removed: '${ this . name } '` ) ) ;
18
+ }
13
19
} ;
Original file line number Diff line number Diff line change 1
1
const log = require ( '../logger' ) ;
2
+ const timer = require ( '../helpers/timer' ) ;
2
3
const BaseCommand = require ( './BaseCommand' ) ;
3
4
const docker = require ( '../docker/client' ) ;
4
5
@@ -11,25 +12,28 @@ module.exports = class ServiceCommand extends BaseCommand {
11
12
_runInternal ( ) {
12
13
const { image} = this . options ;
13
14
return docker
14
- . pull ( image )
15
+ . pull ( image , { repo : 'library' } )
15
16
. then ( ( ) => docker . createContainer ( {
16
- 'Hostname' : '' ,
17
- 'User' : '' ,
18
17
'AttachStdin' : false ,
19
18
'AttachStdout' : false ,
20
19
'AttachStderr' : false ,
21
- 'Tty' : false ,
22
20
'OpenStdin' : false ,
23
21
'StdinOnce' : false ,
24
- 'Env' : null ,
25
22
'Cmd' : [ ] ,
26
23
'Image' : image ,
27
- 'Volumes' : { } ,
28
- 'VolumesFrom' : [ ] ,
29
24
'name' : this . name
30
25
} ) )
31
- . then ( container => container . start ( ) )
26
+ . then ( container => {
27
+ this . container = container ;
28
+ return container . start ( )
29
+ } )
32
30
. then ( ( ) => log . info ( `service created: '${ this . name } '` ) ) ;
31
+ }
33
32
33
+ cleanUp ( ) {
34
+ return timer ( 5000 )
35
+ . then ( ( ) => this . container . stop ( ) )
36
+ . then ( ( ) => this . container . remove ( ) )
37
+ . then ( ( ) => log . info ( `service removed: '${ this . name } '` ) ) ;
34
38
}
35
39
} ;
Original file line number Diff line number Diff line change 1
1
const log = require ( '../logger' ) ;
2
+ const timer = require ( '../helpers/timer' ) ;
2
3
const BaseCommand = require ( './BaseCommand' ) ;
3
4
4
5
module . exports = class VolumeCommand extends BaseCommand {
@@ -7,7 +8,12 @@ module.exports = class VolumeCommand extends BaseCommand {
7
8
}
8
9
9
10
_runInternal ( ) {
10
- return new Promise ( resolve => setTimeout ( resolve , 1000 ) )
11
+ return timer ( 1000 )
11
12
. then ( ( ) => log . info ( `volume created: '${ this . name } '` ) ) ;
12
13
}
14
+
15
+ cleanUp ( ) {
16
+ return timer ( 5000 )
17
+ . then ( ( ) => log . info ( `volume removed: '${ this . name } '` ) ) ;
18
+ }
13
19
} ;
Original file line number Diff line number Diff line change
1
+ module . exports = millis => new Promise ( resolve => setTimeout ( resolve , millis ) ) ;
Original file line number Diff line number Diff line change @@ -53,7 +53,9 @@ module.exports = class DockerService {
53
53
}
54
54
}
55
55
56
- await Promise . all ( Object . values ( commands ) . map ( c => c . run ( ) ) ) ;
56
+ const runnable = Object . values ( commands ) ;
57
+ await Promise . all ( runnable . map ( c => c . run ( ) ) ) ;
58
+ runnable . forEach ( c => c . cleanUp ( ) ) ;
57
59
return { ok : true }
58
60
}
59
61
} ;
You can’t perform that action at this time.
0 commit comments