mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-24 17:31:53 +00:00
Merge branch 'master' of github.com:PDMLab/docker-compose
This commit is contained in:
commit
cc9106a0b9
4 changed files with 39 additions and 7 deletions
4
index.d.ts
vendored
4
index.d.ts
vendored
|
|
@ -18,11 +18,11 @@ export declare function restartOne(service: String, options: IDockerComposeOptio
|
||||||
|
|
||||||
export declare function rm(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
export declare function rm(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
export declare function exec(container: String, command: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
export declare function exec(container: String, command: String | String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
export declare function logs(services: String[], options: IDockerComposeLogOptions): Promise<IDockerComposeResult>;
|
export declare function logs(services: String[], options: IDockerComposeLogOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
export declare function run(service: String, command: String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
export declare function run(service: String, command: String | String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
export declare function buildAll(options: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;
|
export declare function buildAll(options: IDockerComposeBuildOptions): Promise<IDockerComposeResult>;
|
||||||
|
|
||||||
|
|
|
||||||
8
index.js
8
index.js
|
|
@ -180,7 +180,7 @@ const rm = function (options) {
|
||||||
/**
|
/**
|
||||||
* Execute command in a running container
|
* Execute command in a running container
|
||||||
* @param {string} container container name
|
* @param {string} container container name
|
||||||
* @param {string} command command to execute
|
* @param {string|string[]} command command to execute
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
|
|
@ -191,7 +191,7 @@ const rm = function (options) {
|
||||||
* @return {object} std.out / std.err
|
* @return {object} std.out / std.err
|
||||||
*/
|
*/
|
||||||
const exec = function (container, command, options) {
|
const exec = function (container, command, options) {
|
||||||
const args = command.split(/\s+/);
|
const args = Array.isArray(command) ? command : command.split(/\s+/);
|
||||||
|
|
||||||
return execCompose('exec', [ '-T', container ].concat(args), options);
|
return execCompose('exec', [ '-T', container ].concat(args), options);
|
||||||
};
|
};
|
||||||
|
|
@ -199,7 +199,7 @@ const exec = function (container, command, options) {
|
||||||
/**
|
/**
|
||||||
* Run command
|
* Run command
|
||||||
* @param {string} container container name
|
* @param {string} container container name
|
||||||
* @param {string} command command to execute
|
* @param {string|string[]} command command to execute
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {string} options.cwd
|
* @param {string} options.cwd
|
||||||
* @param {boolean} [options.log]
|
* @param {boolean} [options.log]
|
||||||
|
|
@ -210,7 +210,7 @@ const exec = function (container, command, options) {
|
||||||
* @return {object} std.out / std.err
|
* @return {object} std.out / std.err
|
||||||
*/
|
*/
|
||||||
const run = function (container, command, options) {
|
const run = function (container, command, options) {
|
||||||
const args = command.split(/\s+/);
|
const args = Array.isArray(command) ? command : command.split(/\s+/);
|
||||||
|
|
||||||
return execCompose('run', [ '-T', container ].concat(args), options);
|
return execCompose('run', [ '-T', container ].concat(args), options);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<img src="https://img.shields.io/circleci/project/github/PDMLab/docker-compose.svg" /> <a href="https://join.slack.com/t/pdmlab-oss/shared_invite/enQtNjEyMjQ0MDY3NTczLTg1ZDc0YjQxMGE3MTcyYTdkODU1YjFmMTBiODE2ZTZiNDFkNjc1MWE4OTE4NWY0Y2YyMWYzYmNhZGY0NDAyYWY"><img src="https://img.shields.io/badge/Slack-join-green.svg?logo=slack" /></a>
|
<img src="https://img.shields.io/circleci/project/github/PDMLab/docker-compose.svg" /> <a href="https://join.slack.com/t/pdmlab-oss/shared_invite/enQtNjEyMjQ0MDY3NTczLTg1ZDc0YjQxMGE3MTcyYTdkODU1YjFmMTBiODE2ZTZiNDFkNjc1MWE4OTE4NWY0Y2YyMWYzYmNhZGY0NDAyYWY"><img src="https://img.shields.io/npm/dm/docker-compose.svg" /> <img src="https://img.shields.io/badge/Slack-join-green.svg?logo=slack" /></a>
|
||||||
|
|
||||||
# Manage Docker-Compose via Node.js
|
# Manage Docker-Compose via Node.js
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,38 @@ test('ensure run and exec are working', async assert => {
|
||||||
assert.end();
|
assert.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ensure run and exec with command defined as array are working', async assert => {
|
||||||
|
const checkOSID = (out, id) => {
|
||||||
|
// parse /etc/os-release contents
|
||||||
|
const re = /([\w,_]+)=(.*)/g;
|
||||||
|
let match = null;
|
||||||
|
const os = {};
|
||||||
|
|
||||||
|
while ((match = re.exec(out)) !== null) { // eslint-disable-line no-cond-assign
|
||||||
|
os[match[1]] = match[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equals(os.ID, id);
|
||||||
|
};
|
||||||
|
|
||||||
|
const opts = { cwd: path.join(__dirname), log: false };
|
||||||
|
|
||||||
|
await compose.upAll(opts);
|
||||||
|
|
||||||
|
assert.true(await isContainerRunning('/compose_test_nginx'));
|
||||||
|
|
||||||
|
let std = await compose.exec('db', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts);
|
||||||
|
|
||||||
|
assert.false(std.err);
|
||||||
|
checkOSID(std.out, 'debian');
|
||||||
|
|
||||||
|
std = await compose.run('alpine', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts);
|
||||||
|
assert.false(std.err);
|
||||||
|
checkOSID(std.out, 'alpine');
|
||||||
|
|
||||||
|
assert.end();
|
||||||
|
});
|
||||||
|
|
||||||
test('build single service', async assert => {
|
test('build single service', async assert => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue