Skip to content
Merged
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
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ steps:
mount-checkout: false
```

You can enable custom logging drivers and logging options with the use of `log-driver` and `log-opt`:

```yml
steps:
- command: "npm run start"
plugins:
- docker#v5.12.0:
image: "node:7"
log-driver: "awslogs"
log-opt:
- "awslogs-group=my-buildkite-logs"
- "awslogs-region=us-east-1"
- "awslogs-stream-prefix=buildkite"
- "awslogs-create-group=true"
```

Variable interpolation can be tricky due to the 3 layers involved (Buildkite, agent VM, and docker). For example, if you want to use [ECR Buildkite plugin](https://github.com/buildkite-plugins/ecr-buildkite-plugin), you will need to use the following syntax. Note the `$$` prefix for variables that would otherwise resolve at pipeline upload time, not runtime:

```yml
Expand Down Expand Up @@ -307,6 +323,20 @@ Whether or not to leave the container after the run, or immediately remove it wi

Default: `false`

### `log-driver` (optional, string)

The logging driver for the container. This allows you to configure how Docker handles logs for the container.

Common drivers include: `json-file`, `syslog`, `journald`, `gelf`, `fluentd`, `awslogs`, `splunk`, `etwlogs`, `gcplogs`, `logentries`, `none`.

:information_source: As a default, Docker uses the [json-file logging driver](https://docs.docker.com/engine/logging/drivers/json-file/)

See [Docker's logging documentation](https://docs.docker.com/config/containers/logging/) for complete details.

### `log-opt` (optional, array)

Options for the logging driver. These are key-value pairs that configure the behavior of the selected logging driver.

### `load` (optional, string)

Specify a file to load a docker image from. If omitted no load will be done.
Expand All @@ -315,7 +345,7 @@ Specify a file to load a docker image from. If omitted no load will be done.

Whether to automatically mount the current working directory which contains your checked out codebase. Mounts onto `/workdir`, unless `workdir` is set, in which case that will be used.

If there's a git mirror path and `mount-checkout` is enabled, the (mirror path)[https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_REPO_MIRROR] is mounted into the docker container as an added volume. Otherwise, the git mirror path will have to be explicitly added as an extra volume to mount into the container.
If there's a git mirror path and `mount-checkout` is enabled, the (mirror path)[https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_REPO_MIRROR] is mounted into the docker container as an added volume. Otherwise, the git mirror path will have to be explicitly added as an extra volume to mount into the container.

Default: `true`

Expand Down
12 changes: 12 additions & 0 deletions commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ if [[ -n "${BUILDKITE_PLUGIN_DOCKER_STORAGE_OPT:-}" ]] ; then
args+=("--storage-opt" "${BUILDKITE_PLUGIN_DOCKER_STORAGE_OPT:-}")
fi

# Support docker run --log-driver
if [[ -n "${BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER:-}" ]] ; then
args+=("--log-driver" "${BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER}")
fi

# Support docker run --log-opt
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_LOG_OPT; then
for arg in "${result[@]}"; do
args+=("--log-opt" "$arg")
done
fi

shell=()
shell_disabled=1

Expand Down
4 changes: 4 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ configuration:
type: boolean
load:
type: string
log-driver:
type: string
log-opt:
type: array
memory:
type: string
memory-swap:
Expand Down
64 changes: 64 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,70 @@ EOF
unstub docker
}

@test "Runs BUILDKITE_COMMAND with log-driver" {
export BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER=json-file
export BUILDKITE_COMMAND="echo hello world"

stub docker \
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --log-driver json-file --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
}

@test "Runs BUILDKITE_COMMAND with log-opt" {
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=max-size=10m
export BUILDKITE_COMMAND="echo hello world"

stub docker \
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --log-opt max-size=10m --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
}

@test "Runs BUILDKITE_COMMAND with multiple log-opt" {
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=max-size=10m
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_1=max-file=3
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_2=labels=production
export BUILDKITE_COMMAND="echo hello world"

stub docker \
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --log-opt max-size=10m --log-opt max-file=3 --log-opt labels=production --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
}

@test "Runs BUILDKITE_COMMAND with log-driver and log-opt" {
export BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER=syslog
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=syslog-address=tcp://192.168.1.3:514
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_1=tag=myapp
export BUILDKITE_COMMAND="echo hello world"

stub docker \
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --log-driver syslog --log-opt syslog-address=tcp://192.168.1.3:514 --log-opt tag=myapp --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
}

@test "Run with BUILDKITE_COMMAND that exits with a failure" {
export BUILDKITE_COMMAND='pwd'

Expand Down