Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: poc docker compose #164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Node.js CI

on:
on:
push:
branches:
branches:
- '*'
pull_request:
branches:
Expand All @@ -12,20 +12,23 @@ jobs:
runs-on: ubuntu-18.04
name: Lint
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: yarn
- run: yarn lint
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: yarn
- run: yarn lint
build:
runs-on: ubuntu-18.04
name: Build + Test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: yarn
- run: yarn build
- run: yarn test
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: mkdir ~/.docker/cli-plugins
- run: curl -L -o ~/.docker/cli-plugins/docker-compose https://github.com/docker/compose-cli/releases/download/v2.0.0-beta.3/docker-compose-linux-amd64
- run: chmod +x ~/.docker/cli-plugins/docker-compose
- run: yarn
- run: yarn build
- run: yarn test
25 changes: 22 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const configToArgs = (config): string[] => {
* Converts docker-compose commandline options to cli arguments
*/
const composeOptionsToArgs = (composeOptions): string[] => {
let composeArgs: string[] = []
let composeArgs: string[] = ['compose']

composeOptions.forEach((option: string[] | string): void => {
if (option instanceof Array) {
Expand All @@ -136,6 +136,24 @@ const composeOptionsToArgs = (composeOptions): string[] => {
return composeArgs
}

/**
* Converts docker-compose commandline options to cli arguments
*/
const commandOptionsToArgs = (commandOptions): string[] => {
let commandArgs: string[] = []

commandOptions.forEach((option: string[] | string): void => {
if (option instanceof Array) {
commandArgs = commandArgs.concat(option)
}
if (typeof option === 'string') {
commandArgs = commandArgs.concat([option])
}
})

return commandArgs
}

/**
* Executes docker-compose command with common options
*/
Expand All @@ -156,13 +174,14 @@ export const execCompose = (

composeArgs = composeArgs.concat(
configArgs.concat(
[command].concat(composeOptionsToArgs(commandOptions), args)
[command].concat(commandOptionsToArgs(commandOptions), args)
)
)

const cwd = options.cwd
const env = options.env || undefined
const executablePath = options.executablePath || 'docker-compose'
const executablePath =
'docker' || options.executablePath || 'docker-compose'

const childProc = childProcess.spawn(executablePath, composeArgs, {
cwd,
Expand Down