File tree Expand file tree Collapse file tree 7 files changed +44
-4
lines changed Expand file tree Collapse file tree 7 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ module.exports = class Command {
14
14
}
15
15
}
16
16
17
+ /**
18
+ * Runs all the dependencies first, then _runInternal()
19
+ * @returns singleton promise for previous operations
20
+ * */
17
21
run ( ) {
18
22
if ( ! this . executable ) {
19
23
this . executable = Promise . all ( this . dependencies . map ( command => command . run ( ) ) )
@@ -22,13 +26,19 @@ module.exports = class Command {
22
26
return this . executable ;
23
27
}
24
28
29
+ /**
30
+ * Must be implemented by child classes
31
+ * */
25
32
_runInternal ( ) {
26
- log . warn ( 'Command run on base class. Please define "_runInternal()" on the child class' ) ;
27
- return Promise . reject ( ) ;
33
+ const message = 'Command run on base class. Please define "_runInternal()" on the child class' ;
34
+ return Promise . reject ( new Error ( message ) ) ;
28
35
}
29
36
37
+ /**
38
+ * Must be implemented by child classes
39
+ * */
30
40
cleanUp ( ) {
31
- log . warn ( 'method "cleanUp()" not defined. Please define "cleanUp()" on the child class') ;
32
- return Promise . reject ( ) ;
41
+ const message = 'Method "cleanUp()" not defined. Please define "cleanUp()" on the child class';
42
+ return Promise . reject ( new Error ( message ) ) ;
33
43
}
34
44
} ;
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ const log = require('../logger');
2
2
const timer = require ( '../helpers/timer' ) ;
3
3
const BaseCommand = require ( './BaseCommand' ) ;
4
4
5
+ /**
6
+ * simulated network creation
7
+ * */
5
8
module . exports = class NetworkCommand extends BaseCommand {
6
9
constructor ( name , options ) {
7
10
super ( name , options )
Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ module.exports = class ServiceCommand extends BaseCommand {
9
9
super ( name , options )
10
10
}
11
11
12
+ /**
13
+ * 1) pulls image
14
+ * 2) creates container
15
+ * 3) runs container
16
+ * */
12
17
async _runInternal ( ) {
13
18
const { image} = this . options ;
14
19
await docker . pull ( image ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ const log = require('../logger');
2
2
const timer = require ( '../helpers/timer' ) ;
3
3
const BaseCommand = require ( './BaseCommand' ) ;
4
4
5
+ /**
6
+ * simulated volume creation
7
+ * */
5
8
module . exports = class VolumeCommand extends BaseCommand {
6
9
constructor ( name , options ) {
7
10
super ( name , options )
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ module.exports = class DockerController {
20
20
} ;
21
21
22
22
const mimetype = 'text/yaml' ;
23
+
24
+ /**
25
+ * extract first yaml from request
26
+ * */
23
27
function extractYaml ( files ) {
24
28
for ( const name in files ) {
25
29
if ( files . hasOwnProperty ( name ) && files [ name ] . mimetype === mimetype ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ class DockerClient extends Docker {
7
7
super ( options )
8
8
}
9
9
10
+ /**
11
+ * promise wrapper for docker.pull() with some improvements:
12
+ * 1) adds tag to image name, if not exists
13
+ * 2) "streams" the pulling process and returns promise
14
+ * */
10
15
async pull ( image ) {
11
16
if ( ! image . includes ( ':' ) ) {
12
17
image = `${ image } :latest` ;
Original file line number Diff line number Diff line change @@ -5,12 +5,22 @@ const ServiceCommand = require('../command/ServiceCommand');
5
5
const NetworkCommand = require ( '../command/NetworkCommand' ) ;
6
6
const VolumeCommand = require ( '../command/VolumeCommand' ) ;
7
7
8
+ /**
9
+ * Service for applying "docker-compose" files.
10
+ * */
8
11
module . exports = class DockerService {
9
12
static applyYaml ( fileContent ) {
10
13
const directives = yaml . parseSync ( fileContent ) ;
11
14
return this . applyDirectives ( directives ) ;
12
15
}
13
16
17
+ /**
18
+ * Creates and runs containers for "services".
19
+ * Runs dependencies before its` dependants.
20
+ * Removes all created containers after 5 sec.
21
+ *
22
+ * volumes and networks are yet simulated
23
+ * */
14
24
static async applyDirectives ( { services, volumes = { } , networks = { } } ) {
15
25
const commands = { } ;
16
26
You can’t perform that action at this time.
0 commit comments