Skip to content

Commit

Permalink
feat: stop many (#200)
Browse files Browse the repository at this point in the history
* docs: docker-compose rm command when passing multiple services
* feat: add stopMany, update documentation

Co-authored-by: Jenkins <devops@everseen.com>
Co-authored-by: gabi.hulea <gabi.hulea@everseen.com>
  • Loading branch information
3 people committed Jan 16, 2022
1 parent 9850fb9 commit f10a9b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npm install --save-dev docker-compose
* `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(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
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ export const stopOne = function (
return execCompose('stop', [service], options)
}

export const stopMany = function (
options?: IDockerComposeOptions,
...services: string[]
): Promise<IDockerComposeResult> {
return execCompose('stop', [...services], options)
}

export const pauseOne = function (
service: string,
options?: IDockerComposeOptions
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ test('ensure only single container gets stopped', async (): Promise<void> => {
await compose.down({ cwd: path.join(__dirname), log: logOutput })
})

test('ensure multiple containers gets stopped', async (): Promise<void> => {
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<void> => {
const opts = { cwd: path.join(__dirname), log: logOutput }
await compose.upAll(opts)
Expand Down

0 comments on commit f10a9b6

Please sign in to comment.