Skip to content

Commit

Permalink
Merge pull request #334 from donbobka/add-support-docker-compose-v2
Browse files Browse the repository at this point in the history
Add support docker compose v2
  • Loading branch information
pzeballos authored Sep 27, 2022
2 parents 0579362 + 8970334 commit 11020f2
Show file tree
Hide file tree
Showing 8 changed files with 1,659 additions and 1 deletion.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ steps:
plugins:
${BUILDKITE_PULL_REQUEST_REPO:-$BUILDKITE_REPO}#${BUILDKITE_COMMIT}:
run: tests
command: ["bats", "tests", "tests/v2"]

# The rest of the steps are integration tests

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,16 @@ Select when to upload container logs.

The default is `on-error`.

### `cli-version` (optional)

If set to `2`, plugin will use `docker compose` to execute commands; otherwise it will default to version `1` using `docker-compose` instead.

## Developing

To run the tests:

```bash
docker-compose run --rm tests
docker-compose run --rm tests bats tests tests/v2
```

## License
Expand Down
3 changes: 3 additions & 0 deletions lib/shared.bash
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ function build_image_override_file_with_version() {
# Runs the docker-compose command, scoped to the project, with the given arguments
function run_docker_compose() {
local command=(docker-compose)
if [[ "$(plugin_read_config CLI_VERSION "1")" == "2" ]] ; then
command=(docker compose)
fi

if [[ "$(plugin_read_config VERBOSE "false")" == "true" ]] ; then
command+=(--verbose)
Expand Down
5 changes: 5 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ configuration:
type: boolean
entrypoint:
type: string
cli-version:
type: string
enum:
- 1
- 2
anyOf:
- required:
- run
Expand Down
17 changes: 17 additions & 0 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ load '../lib/shared'
unstub docker-compose
}

@test "Build with docker-compose and v1 is set explicitly " {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull myservice : echo built myservice"

run $PWD/hooks/command

assert_success
assert_output --partial "built myservice"
unstub docker-compose
}

@test "Build with a repository" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
Expand Down
Loading

0 comments on commit 11020f2

Please sign in to comment.