Skip to content

Commit

Permalink
feat(dockest): support function as commands for injecting the contain…
Browse files Browse the repository at this point in the history
…erId into the command. (erikengervall#133)

* feat(dockest): support function as commands for injecting the containerId into the command.

This makes it much easier to run commands inside your container, e.g. a database dump import.

* test: add example for using a command with the injected container id.
  • Loading branch information
n1ru4l authored Feb 3, 2020
1 parent 6ebed91 commit feeff5f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/dockest/src/@types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface DockerComposeFileServicePostgres extends DockerComposeFileServi
}
}

export type Commands = string[]
export type Commands = (string | ((containerId: string) => string))[]

export interface DockestService {
serviceName: ServiceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { Runner } from '../../@types'
const logPrefix = '[Dockest Service Commands]'

export const runRunnerCommands = async ({ runner, runner: { commands } }: { runner: Runner }) => {
for (const command of commands) {
for (let command of commands) {
if (typeof command === 'function') {
command = command(runner.containerId)
}
await execaWrapper(command, { runner, logPrefix, logStdout: true })
}
}
1 change: 1 addition & 0 deletions packages/examples/multiple-resources/dockest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dockest.run([
'sequelize db:migrate',
'sequelize db:seed:undo:all',
'sequelize db:seed --seed 20190101001337-demo-user',
containerId => `echo "The container id is ${containerId}"`,
],
healthcheck: ({ defaultHealthchecks: { postgres } }) => postgres(),
},
Expand Down

0 comments on commit feeff5f

Please sign in to comment.