Skip to content

Commit 0e9f882

Browse files
committed
docs
1 parent fe81de1 commit 0e9f882

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed

command/BaseCommand.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ module.exports = class Command {
1414
}
1515
}
1616

17+
/**
18+
* Runs all the dependencies first, then _runInternal()
19+
* @returns singleton promise for previous operations
20+
* */
1721
run() {
1822
if (!this.executable) {
1923
this.executable = Promise.all(this.dependencies.map(command => command.run()))
@@ -22,13 +26,19 @@ module.exports = class Command {
2226
return this.executable;
2327
}
2428

29+
/**
30+
* Must be implemented by child classes
31+
* */
2532
_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));
2835
}
2936

37+
/**
38+
* Must be implemented by child classes
39+
* */
3040
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));
3343
}
3444
};

command/NetworkCommand.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const log = require('../logger');
22
const timer = require('../helpers/timer');
33
const BaseCommand = require('./BaseCommand');
44

5+
/**
6+
* simulated network creation
7+
* */
58
module.exports = class NetworkCommand extends BaseCommand {
69
constructor(name, options) {
710
super(name, options)

command/ServiceCommand.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ module.exports = class ServiceCommand extends BaseCommand {
99
super(name, options)
1010
}
1111

12+
/**
13+
* 1) pulls image
14+
* 2) creates container
15+
* 3) runs container
16+
* */
1217
async _runInternal() {
1318
const {image} = this.options;
1419
await docker.pull(image);

command/VolumeCommand.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const log = require('../logger');
22
const timer = require('../helpers/timer');
33
const BaseCommand = require('./BaseCommand');
44

5+
/**
6+
* simulated volume creation
7+
* */
58
module.exports = class VolumeCommand extends BaseCommand {
69
constructor(name, options) {
710
super(name, options)

controllers/DockerController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = class DockerController {
2020
};
2121

2222
const mimetype = 'text/yaml';
23+
24+
/**
25+
* extract first yaml from request
26+
* */
2327
function extractYaml(files) {
2428
for (const name in files) {
2529
if (files.hasOwnProperty(name) && files[name].mimetype === mimetype) {

docker/client.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class DockerClient extends Docker {
77
super(options)
88
}
99

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+
* */
1015
async pull(image) {
1116
if (!image.includes(':')) {
1217
image = `${image}:latest`;

services/DockerService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ const ServiceCommand = require('../command/ServiceCommand');
55
const NetworkCommand = require('../command/NetworkCommand');
66
const VolumeCommand = require('../command/VolumeCommand');
77

8+
/**
9+
* Service for applying "docker-compose" files.
10+
* */
811
module.exports = class DockerService {
912
static applyYaml(fileContent) {
1013
const directives = yaml.parseSync(fileContent);
1114
return this.applyDirectives(directives);
1215
}
1316

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+
* */
1424
static async applyDirectives({services, volumes = {}, networks = {}}) {
1525
const commands = {};
1626

0 commit comments

Comments
 (0)