mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-24 09:22:08 +00:00
Merge branch 'master' into iss-11
This commit is contained in:
commit
b20a9bdb6c
4 changed files with 313 additions and 330 deletions
80
index.js
80
index.js
|
|
@ -1,18 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const promisify = require('es6-promisify');
|
const childProcess = require('child_process');
|
||||||
const execute = promisify(require('child_process').exec, { multiArgs: true });
|
|
||||||
const logger = require('./lib/log');
|
|
||||||
|
|
||||||
const logStandards = function (std) {
|
|
||||||
if (std.out && std.out.length > 0) {
|
|
||||||
logger.info(std.out);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std.err && std.err.length > 0) {
|
|
||||||
logger.warn(std.err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts supplied yml files to cli arguments
|
* Converts supplied yml files to cli arguments
|
||||||
|
|
@ -21,11 +9,11 @@ const logStandards = function (std) {
|
||||||
*/
|
*/
|
||||||
const configToArgs = config => {
|
const configToArgs = config => {
|
||||||
if (typeof config === 'undefined') {
|
if (typeof config === 'undefined') {
|
||||||
return '';
|
return [];
|
||||||
} else if (typeof config === 'string') {
|
} else if (typeof config === 'string') {
|
||||||
return `-f ${config}`;
|
return [ '-f', config ];
|
||||||
} else if (config instanceof Array) {
|
} else if (config instanceof Array) {
|
||||||
return config.map(configToArgs).join(' ');
|
return config.reduce((args, item) => args.concat([ '-f', item ]), []);
|
||||||
}
|
}
|
||||||
throw new Error(`Invalid argument supplied: ${config}`);
|
throw new Error(`Invalid argument supplied: ${config}`);
|
||||||
};
|
};
|
||||||
|
|
@ -33,34 +21,33 @@ const configToArgs = config => {
|
||||||
/**
|
/**
|
||||||
* Executes docker-compose command with common options
|
* Executes docker-compose command with common options
|
||||||
* @param {string} command
|
* @param {string} command
|
||||||
|
* @param {string[]} args
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const execCompose = (command, options) => new Promise((resolve, reject) => {
|
const execCompose = (command, args, options) => new Promise((resolve, reject) => {
|
||||||
const cmd = `docker-compose ${configToArgs(options.config)} ${command}`;
|
const composeArgs = configToArgs(options.config);
|
||||||
const cwd = options.cwd;
|
const cwd = options.cwd;
|
||||||
|
const env = options.env || null;
|
||||||
|
|
||||||
execute(cmd, { cwd }).then(
|
const childProc = childProcess.spawn('docker-compose', composeArgs.concat([ command ], args), { cwd, env }, (err, stdout, stderr) => {
|
||||||
standards => {
|
if (err) {
|
||||||
const std = {
|
reject(err);
|
||||||
out: standards[0],
|
} else {
|
||||||
err: standards[1]
|
resolve({
|
||||||
};
|
err: stderr,
|
||||||
|
out: stdout
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (options.log) {
|
if (options.log) {
|
||||||
logStandards(std);
|
childProc.stdout.pipe(process.stdout);
|
||||||
}
|
childProc.stderr.pipe(process.stderr);
|
||||||
|
}
|
||||||
resolve(std);
|
|
||||||
},
|
|
||||||
error => {
|
|
||||||
logger.error(error.message);
|
|
||||||
|
|
||||||
return reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,9 +55,10 @@ const execCompose = (command, options) => new Promise((resolve, reject) => {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const up = function (options) {
|
const up = function (options) {
|
||||||
return execCompose('up -d', options);
|
return execCompose('up', [ '-d' ], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,9 +66,10 @@ const up = function (options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const down = function (options) {
|
const down = function (options) {
|
||||||
return execCompose('down', options);
|
return execCompose('down', [], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -88,9 +77,10 @@ const down = function (options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const stop = function (options) {
|
const stop = function (options) {
|
||||||
return execCompose('stop', options);
|
return execCompose('stop', [], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,9 +88,10 @@ const stop = function (options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const kill = function (options) {
|
const kill = function (options) {
|
||||||
return execCompose('kill', options);
|
return execCompose('kill', [], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -108,9 +99,10 @@ const kill = function (options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*/
|
*/
|
||||||
const rm = function (options) {
|
const rm = function (options) {
|
||||||
return execCompose('rm -f', options);
|
return execCompose('rm', [ '-f' ], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,11 +113,12 @@ const rm = function (options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*
|
*
|
||||||
* @return {object} std.out / std.err
|
* @return {object} std.out / std.err
|
||||||
*/
|
*/
|
||||||
const exec = function (container, command, options) {
|
const exec = function (container, command, options) {
|
||||||
return execCompose(`exec -T ${container} ${command}`, options);
|
return execCompose('exec', [ '-T', container, command ], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -136,11 +129,12 @@ const exec = function (container, command, options) {
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
* @param {?(string|string[])} [options.config]
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
*
|
*
|
||||||
* @return {object} std.out / std.err
|
* @return {object} std.out / std.err
|
||||||
*/
|
*/
|
||||||
const run = function (container, command, options) {
|
const run = function (container, command, options) {
|
||||||
return execCompose(`run -T ${container} ${command}`, options);
|
return execCompose('run', [ '-T', container, command ], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
555
package-lock.json
generated
555
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docker-compose",
|
"name": "docker-compose",
|
||||||
"version": "0.6.1",
|
"version": "0.7.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./node_modules/.bin/tape test",
|
"test": "./node_modules/.bin/tape test",
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
{
|
{
|
||||||
"name": "Ignatiev Mikhail"
|
"name": "Ignatiev Mikhail"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Ezekiel Warren"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Palash Mondal"
|
"name": "Palash Mondal"
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +25,6 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Manage docker-compose from Node.js",
|
"description": "Manage docker-compose from Node.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"es6-promisify": "^5.0.0",
|
|
||||||
"winston": "^2.3.1"
|
"winston": "^2.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ Also please add tests and make sure to run `npm run eslint`.
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2017 PDMLab
|
Copyright (c) 2018 PDMLab
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue