Skip to content

Commit

Permalink
Collapse logging of run args by default
Browse files Browse the repository at this point in the history
  • Loading branch information
francoiscampbell committed Oct 12, 2023
1 parent 22f7b9f commit 1bfc082
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ Will cause the image to be pushed twice (once by the build step and another by t

Pull down multiple pre-built images. By default only the service that is being run will be pulled down, but this allows multiple images to be specified to handle prebuilt dependent images. Note that pulling will be skipped if the `skip-pull` option is activated.

### `collapse-run-log-group` (optional, boolean, run only)

Whether to collapse or expand the log group that is created for the output of `docker-compose run`. When this setting is `true`, the output is collected into a `---` group, when `false` the output is collected into a `+++` group. Setting this to `false` can be useful to highlight your command's output if it does not create its own `+++` group.

For more information see [Managing log output](https://buildkite.com/docs/pipelines/managing-log-output).

Default `true`

### `config` (optional)

The file name of the Docker Compose configuration file to use. Can also be a list of filenames. If `$COMPOSE_FILE` is set, it will be used if `config` is not specified.
Expand Down
7 changes: 6 additions & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,15 @@ ensure_stopped() {

trap ensure_stopped SIGINT SIGTERM SIGQUIT

if [[ "${BUILDKITE_PLUGIN_DOCKER_COMPOSE_COLLAPSE_RUN_LOG_GROUP:-true}" = "true" ]]; then
group_type="---"
else
group_type="+++"
fi
# Disable -e to prevent cancelling step if the command fails for whatever reason
set +e
( # subshell is necessary to trap signals (compose v2 fails to stop otherwise)
echo "+++ :docker: Running ${display_command[*]:-} in service $run_service" >&2
echo "${group_type} :docker: Running ${display_command[*]:-} in service $run_service" >&2
run_docker_compose "${run_params[@]}"
)
exitcode=$?
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ configuration:
enum: [ 1, 2 ]
command:
type: array
collapse-run-log-group:
type: boolean
config:
type: [ string, array ]
minimum: 1
Expand Down
53 changes: 53 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1622,3 +1622,56 @@ export BUILDKITE_JOB_ID=1111
assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!"
unstub buildkite-agent
}

@test "Run with collapsed run log group by default" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND="echo hello world"
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" \
"-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
"-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"

run "$PWD"/hooks/command

assert_success
assert_output --partial "--- :docker: Running /bin/sh -e -c 'echo hello world' in service myservice"
unstub docker-compose
unstub buildkite-agent
}

@test "Run with expanded run log group" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND="echo hello world"
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COLLAPSE_RUN_LOG_GROUP=false

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" \
"-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
"-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"

run "$PWD"/hooks/command

assert_success
assert_output --partial "+++ :docker: Running /bin/sh -e -c 'echo hello world' in service myservice"
unstub docker-compose
unstub buildkite-agent


}

0 comments on commit 1bfc082

Please sign in to comment.