Skip to content

Commit 6c93186

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main
2 parents 1769c05 + 37738e4 commit 6c93186

File tree

18 files changed

+2703
-69
lines changed

18 files changed

+2703
-69
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ var docker = new Dockerode();
2929
var compose = new DockerodeCompose(docker);
3030

3131
(async () => {
32-
var state = await compose.compose('./test/wordpress.yml', 'wordpress');
32+
var state = await compose.up('./test/wordpress.yml', 'wordpress');
3333
console.log(state);
3434
})();
3535
```
3636

37+
## Documentation
38+
39+
- compose.up(file, project_name)
40+
- compose.pull(service)
41+
3742
## Tests
3843

39-
* `docker pull ubuntu:latest` to prepare your system for the tests.
4044
* Tests are implemented using `mocha` and `chai`. Run them with `npm test`.
4145

4246
## Examples

compose.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const yaml = require('js-yaml');
2+
const fs = require('fs');
3+
4+
const secrets = require('./lib/secrets');
5+
const volumes = require('./lib/volumes');
6+
const configs = require('./lib/configs');
7+
const networks = require('./lib/networks');
8+
const services = require('./lib/services');
9+
const tools = require('./lib/tools');
10+
11+
class Compose {
12+
constructor(dockerode, file, projectName) {
13+
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+
}
27+
}
28+
29+
async up() {
30+
var output = {};
31+
try {
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);
37+
return output;
38+
} catch (e) {
39+
throw e;
40+
}
41+
}
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+
}
57+
}
58+
59+
module.exports = Compose;

examples/compose.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/pull.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var Dockerode = require('dockerode');
2+
var DockerodeCompose = require('../compose');
3+
4+
var docker = new Dockerode();
5+
var compose = new DockerodeCompose(docker, './test/assets/wordpress.yml', 'wordpress');
6+
7+
(async () => {
8+
console.log(await compose.pull());
9+
})();

examples/up.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var Dockerode = require('dockerode');
2+
var DockerodeCompose = require('../compose');
3+
4+
var docker = new Dockerode();
5+
var compose = new DockerodeCompose(docker, './test/assets/wordpress.yml', 'wordpress');
6+
7+
(async () => {
8+
var state = await compose.up();
9+
console.log(state);
10+
})();

lib/compose.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

lib/configs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = async function (docker, projectName, recipe) {
1+
module.exports = async function (docker, projectName, recipe, output) {
22
var configs = [];
33
var configNames = Object.keys(recipe.configs || []);
44
for (var configName of configNames) {

lib/networks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = async function (docker, projectName, recipe) {
1+
module.exports = async function (docker, projectName, recipe, output) {
22
var networks = [];
33
var networkNames = Object.keys(recipe.networks || []);
44
for (var networkName of networkNames) {

lib/secrets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22

3-
module.exports = async function(docker, projectName, recipe) {
3+
module.exports = async function(docker, projectName, recipe, output) {
44
var secrets = [];
55
var secretNames = Object.keys(recipe.secrets || []);
66
for (var secretName of secretNames) {

lib/services.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
module.exports = async function (docker, projectName, recipe) {
1+
const tools = require('./tools');
2+
3+
module.exports = async function (docker, projectName, recipe, output) {
24
var services = [];
3-
var serviceNames = Object.keys(recipe.services || []);
5+
var serviceNames = tools.sortServices(recipe);
46
for (var serviceName of serviceNames) {
57
var networksToAttach = [];
68
var service = recipe.services[serviceName];

0 commit comments

Comments
 (0)