mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-14 12:11:25 +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';
|
||||
|
||||
const promisify = require('es6-promisify');
|
||||
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);
|
||||
}
|
||||
};
|
||||
const childProcess = require('child_process');
|
||||
|
||||
/**
|
||||
* Converts supplied yml files to cli arguments
|
||||
|
|
@ -21,11 +9,11 @@ const logStandards = function (std) {
|
|||
*/
|
||||
const configToArgs = config => {
|
||||
if (typeof config === 'undefined') {
|
||||
return '';
|
||||
return [];
|
||||
} else if (typeof config === 'string') {
|
||||
return `-f ${config}`;
|
||||
return [ '-f', config ];
|
||||
} 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}`);
|
||||
};
|
||||
|
|
@ -33,34 +21,33 @@ const configToArgs = config => {
|
|||
/**
|
||||
* Executes docker-compose command with common options
|
||||
* @param {string} command
|
||||
* @param {string[]} args
|
||||
* @param {object} options
|
||||
* @param {string} options.cwd
|
||||
* @param {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
const execCompose = (command, options) => new Promise((resolve, reject) => {
|
||||
const cmd = `docker-compose ${configToArgs(options.config)} ${command}`;
|
||||
const execCompose = (command, args, options) => new Promise((resolve, reject) => {
|
||||
const composeArgs = configToArgs(options.config);
|
||||
const cwd = options.cwd;
|
||||
const env = options.env || null;
|
||||
|
||||
execute(cmd, { cwd }).then(
|
||||
standards => {
|
||||
const std = {
|
||||
out: standards[0],
|
||||
err: standards[1]
|
||||
};
|
||||
const childProc = childProcess.spawn('docker-compose', composeArgs.concat([ command ], args), { cwd, env }, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve({
|
||||
err: stderr,
|
||||
out: stdout
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (options.log) {
|
||||
logStandards(std);
|
||||
}
|
||||
|
||||
resolve(std);
|
||||
},
|
||||
error => {
|
||||
logger.error(error.message);
|
||||
|
||||
return reject(error);
|
||||
}
|
||||
);
|
||||
if (options.log) {
|
||||
childProc.stdout.pipe(process.stdout);
|
||||
childProc.stderr.pipe(process.stderr);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
@ -68,9 +55,10 @@ const execCompose = (command, options) => new Promise((resolve, reject) => {
|
|||
* @param {string} options.cwd
|
||||
* @param {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*
|
||||
* @return {object} std.out / std.err
|
||||
*/
|
||||
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 {boolean} [options.log]
|
||||
* @param {?(string|string[])} [options.config]
|
||||
* @param {?object} [options.env]
|
||||
*
|
||||
* @return {object} std.out / std.err
|
||||
*/
|
||||
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",
|
||||
"version": "0.6.1",
|
||||
"version": "0.7.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "./node_modules/.bin/tape test",
|
||||
|
|
@ -15,6 +15,9 @@
|
|||
{
|
||||
"name": "Ignatiev Mikhail"
|
||||
},
|
||||
{
|
||||
"name": "Ezekiel Warren"
|
||||
},
|
||||
{
|
||||
"name": "Palash Mondal"
|
||||
}
|
||||
|
|
@ -22,7 +25,6 @@
|
|||
"license": "MIT",
|
||||
"description": "Manage docker-compose from Node.js",
|
||||
"dependencies": {
|
||||
"es6-promisify": "^5.0.0",
|
||||
"winston": "^2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ Also please add tests and make sure to run `npm run eslint`.
|
|||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 PDMLab
|
||||
Copyright (c) 2018 PDMLab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
Loading…
Reference in a new issue