From c47cbbb947fb6a6db62555b0ed8f1bb3cbf5aaf4 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Sat, 15 Jan 2022 13:44:17 -0500 Subject: [PATCH 1/5] fix: docker-compose rm command when passing multiple services, add stopMany command, update documentation --- docs/README.md | 3 ++- src/index.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index f9af4994..98ba605a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,10 +36,11 @@ npm install --save-dev docker-compose * `restartAll(options)` - Restart all services * `restartMany(services, options)` - Restart services * `restartOne(service, options)` - Restart service -* `rm(options, services)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode - `services` can optionally be used to select the containers to remove +* `rm(services, options)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode - `services` can optionally be used to select the containers to remove * `run(service, command, options)` - Run a one-off `command` on a service - uses `-T` to properly handle stdin & stdout * `stop(options)` - Stop running containers without removing them * `stopOne(service, options)` - Stops one container without removing it +* `stopMany(services, options)` - Stops containers without removing them * `unpauseOne(service, options)` - Resume the specified service * `upAll(options)` - Builds, (re)creates, starts, and attaches to containers for all services - always uses the `-d` flag due to non interactive mode * `upMany(services, options)` - Builds, (re)creates, starts, and attaches to containers for the services specified in `services` - always uses the `-d` flag due to non interactive mode diff --git a/src/index.ts b/src/index.ts index 210bf40f..f927835a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -290,6 +290,13 @@ export const stopOne = function ( return execCompose('stop', [service], options) } +export const stopMany = function ( + services: string[], + options?: IDockerComposeOptions +): Promise { + return execCompose('stop', [services], options) +} + export const pauseOne = function ( service: string, options?: IDockerComposeOptions @@ -311,10 +318,10 @@ export const kill = function ( } export const rm = function ( + services: string[], options?: IDockerComposeOptions, - ...services: string[] ): Promise { - return execCompose('rm', ['-f', ...services], options) + return execCompose('rm', ['-f'].concat(services), options) } export const exec = function ( From 704cb184b7dde12d290c01ae50c1c02db2374bb3 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Sat, 15 Jan 2022 15:58:33 -0500 Subject: [PATCH 2/5] feat: add stopMany, update documentation --- docs/README.md | 4 ++-- src/index.ts | 10 +++++----- test/index.test.ts | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index 98ba605a..9590207c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,11 +36,11 @@ npm install --save-dev docker-compose * `restartAll(options)` - Restart all services * `restartMany(services, options)` - Restart services * `restartOne(service, options)` - Restart service -* `rm(services, options)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode - `services` can optionally be used to select the containers to remove +* `rm(options, services)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode - `services` can optionally be used to select the containers to remove * `run(service, command, options)` - Run a one-off `command` on a service - uses `-T` to properly handle stdin & stdout * `stop(options)` - Stop running containers without removing them * `stopOne(service, options)` - Stops one container without removing it -* `stopMany(services, options)` - Stops containers without removing them +* `stopMany(options,services)` - Stops containers without removing them * `unpauseOne(service, options)` - Resume the specified service * `upAll(options)` - Builds, (re)creates, starts, and attaches to containers for all services - always uses the `-d` flag due to non interactive mode * `upMany(services, options)` - Builds, (re)creates, starts, and attaches to containers for the services specified in `services` - always uses the `-d` flag due to non interactive mode diff --git a/src/index.ts b/src/index.ts index f927835a..449249db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -291,10 +291,10 @@ export const stopOne = function ( } export const stopMany = function ( - services: string[], - options?: IDockerComposeOptions + options?: IDockerComposeOptions, + ...services: string[] ): Promise { - return execCompose('stop', [services], options) + return execCompose('stop', [...services], options) } export const pauseOne = function ( @@ -318,10 +318,10 @@ export const kill = function ( } export const rm = function ( - services: string[], options?: IDockerComposeOptions, + ...services: string[] ): Promise { - return execCompose('rm', ['-f'].concat(services), options) + return execCompose('rm', ['-f', ...services], options) } export const exec = function ( diff --git a/test/index.test.ts b/test/index.test.ts index 6bc43344..56ebcd50 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -223,6 +223,17 @@ test('ensure only single container gets stopped', async (): Promise => { await compose.down({ cwd: path.join(__dirname), log: logOutput }) }) +test('ensure multiple containers gets stopped', async (): Promise => { + await compose.upAll({ cwd: path.join(__dirname), log: logOutput }) + expect(await isContainerRunning('/compose_test_web')).toBeTruthy() + expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() + + await compose.stopMany({ cwd: path.join(__dirname), log: logOutput },'proxy','web') + expect(await isContainerRunning('/compose_test_web')).toBeFalsy() + expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy() + await compose.down({ cwd: path.join(__dirname), log: logOutput }) +}) + test('ensure only single container gets paused then resumed', async (): Promise => { const opts = { cwd: path.join(__dirname), log: logOutput } await compose.upAll(opts) From e494c66444fb5bd1b61326a70dffb3c7d2a8650c Mon Sep 17 00:00:00 2001 From: gamaraan Date: Sat, 15 Jan 2022 16:03:53 -0500 Subject: [PATCH 3/5] chore: remove extra whitespace --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 449249db..db1f524d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -321,7 +321,7 @@ export const rm = function ( options?: IDockerComposeOptions, ...services: string[] ): Promise { - return execCompose('rm', ['-f', ...services], options) + return execCompose('rm', ['-f', ...services], options) } export const exec = function ( From 7dae1b1af3409c1311fcfd8b47b38483e3e6ba66 Mon Sep 17 00:00:00 2001 From: gamaraan Date: Sun, 16 Jan 2022 01:45:42 -0500 Subject: [PATCH 4/5] chore: fix linting --- test/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index 56ebcd50..7a12a86d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -228,7 +228,7 @@ test('ensure multiple containers gets stopped', async (): Promise => { expect(await isContainerRunning('/compose_test_web')).toBeTruthy() expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() - await compose.stopMany({ cwd: path.join(__dirname), log: logOutput },'proxy','web') + await compose.stopMany({ cwd: path.join(__dirname), log: logOutput }, 'proxy', 'web') expect(await isContainerRunning('/compose_test_web')).toBeFalsy() expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy() await compose.down({ cwd: path.join(__dirname), log: logOutput }) From 5cabfc0786287e9e16a33695673ddee3d1e6e740 Mon Sep 17 00:00:00 2001 From: "gabi.hulea" Date: Sun, 16 Jan 2022 12:48:22 +0200 Subject: [PATCH 5/5] chore(lint): prettier --- test/index.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index 7a12a86d..3115839a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -228,7 +228,11 @@ test('ensure multiple containers gets stopped', async (): Promise => { expect(await isContainerRunning('/compose_test_web')).toBeTruthy() expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy() - await compose.stopMany({ cwd: path.join(__dirname), log: logOutput }, 'proxy', 'web') + await compose.stopMany( + { cwd: path.join(__dirname), log: logOutput }, + 'proxy', + 'web' + ) expect(await isContainerRunning('/compose_test_web')).toBeFalsy() expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy() await compose.down({ cwd: path.join(__dirname), log: logOutput })