From 186e04741d055765fd2321193c20394e6d86365e Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Wed, 30 Jan 2019 09:42:00 +0100 Subject: [PATCH 1/2] implement restart command --- index.d.ts | 3 +++ index.js | 37 ++++++++++++++++++++++++++++++++++++- test/index.js | 26 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index b808a89..8f59fbe 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,6 +6,9 @@ declare module "docker-compose" { kill(options: IDockerComposeOptions): Promise; down(options: IDockerComposeOptions): Promise; stop(options: IDockerComposeOptions): Promise; + restartAll(options: IDockerComposeOptions): Promise; + restartMany(services:String[], options: IDockerComposeOptions): Promise; + restartOne(service:String, options: IDockerComposeOptions): Promise; rm(options: IDockerComposeOptions): Promise; exec(container:String, command:String, options: IDockerComposeOptions): Promise; run(service:String, command:String, options: IDockerComposeOptions): Promise; diff --git a/index.js b/index.js index 09399fb..2c966fe 100644 --- a/index.js +++ b/index.js @@ -233,4 +233,39 @@ const ps = function (options) { return execCompose('ps', [], options); }; -module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, run, buildAll, buildMany, buildOne, ps }; +/** + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + */ +const restartAll = function (options) { + return execCompose('restart', [], options); +}; + +/** + * @param {string[]} services + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + */ +const restartMany = function (services, options) { + return execCompose('restart', services, options); +}; + +/** + * @param {string} service + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + */ +const restartOne = function (service, options) { + return restartMany([ service ], options); +}; + +module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, restartAll, restartMany, restartOne, run, buildAll, buildMany, buildOne, ps }; diff --git a/test/index.js b/test/index.js index 963b001..ca7bf46 100644 --- a/test/index.js +++ b/test/index.js @@ -245,3 +245,29 @@ test('ps does not show status data for stopped containers', async assert => { assert.end(); }); + +test('restartAll does restart all containers', async assert => { + await compose.upAll({ cwd: path.join(__dirname), log: true }); + await compose.restartAll({ cwd: path.join(__dirname), log: true }); + + assert.true(await isContainerRunning('/compose_test_mongodb')); + assert.true(await isContainerRunning('/compose_test_alpine')); + assert.end(); +}); + +test('restartMany does restart selected containers', async assert => { + await compose.upAll({ cwd: path.join(__dirname), log: true }); + await compose.restartMany([ 'db', 'alpine' ], { cwd: path.join(__dirname), log: true }); + + assert.true(await isContainerRunning('/compose_test_mongodb')); + assert.true(await isContainerRunning('/compose_test_alpine')); + assert.end(); +}); + +test('restartOne does restart container', async assert => { + await compose.upAll({ cwd: path.join(__dirname), log: true }); + await compose.restartOne('db', { cwd: path.join(__dirname), log: true }); + + assert.true(await isContainerRunning('/compose_test_mongodb')); + assert.end(); +}); From 5ecc699f90932fc05708c9d2a1a4d122d87246c2 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Wed, 30 Jan 2019 09:48:54 +0100 Subject: [PATCH 2/2] fix assert: alpine finishes after start/restart --- test/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/index.js b/test/index.js index ca7bf46..b40fcec 100644 --- a/test/index.js +++ b/test/index.js @@ -251,7 +251,6 @@ test('restartAll does restart all containers', async assert => { await compose.restartAll({ cwd: path.join(__dirname), log: true }); assert.true(await isContainerRunning('/compose_test_mongodb')); - assert.true(await isContainerRunning('/compose_test_alpine')); assert.end(); }); @@ -260,7 +259,6 @@ test('restartMany does restart selected containers', async assert => { await compose.restartMany([ 'db', 'alpine' ], { cwd: path.join(__dirname), log: true }); assert.true(await isContainerRunning('/compose_test_mongodb')); - assert.true(await isContainerRunning('/compose_test_alpine')); assert.end(); });