Skip to content

Commit 85d9a94

Browse files
committed
Adding log-driver, log-opt
Adding log-driver and log-opt options
1 parent db8815a commit 85d9a94

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

commands/run.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@ if [[ -n "${BUILDKITE_PLUGIN_DOCKER_STORAGE_OPT:-}" ]] ; then
397397
args+=("--storage-opt" "${BUILDKITE_PLUGIN_DOCKER_STORAGE_OPT:-}")
398398
fi
399399

400+
# Support docker run --log-driver
401+
if [[ -n "${BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER:-}" ]] ; then
402+
args+=("--log-driver" "${BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER}")
403+
fi
404+
405+
# Support docker run --log-opt
406+
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_LOG_OPT; then
407+
for arg in "${result[@]}"; do
408+
args+=("--log-opt" "$arg")
409+
done
410+
fi
411+
400412
shell=()
401413
shell_disabled=1
402414

plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ configuration:
4747
type: boolean
4848
load:
4949
type: string
50+
log-driver:
51+
type: string
52+
log-opt:
53+
type: array
5054
memory:
5155
type: string
5256
memory-swap:

tests/command.bats

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,70 @@ EOF
13821382
unstub docker
13831383
}
13841384

1385+
@test "Runs BUILDKITE_COMMAND with log-driver" {
1386+
export BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER=json-file
1387+
export BUILDKITE_COMMAND="echo hello world"
1388+
1389+
stub docker \
1390+
"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"
1391+
1392+
run "$PWD"/hooks/command
1393+
1394+
assert_success
1395+
assert_output --partial "ran command in docker"
1396+
1397+
unstub docker
1398+
}
1399+
1400+
@test "Runs BUILDKITE_COMMAND with log-opt" {
1401+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=max-size=10m
1402+
export BUILDKITE_COMMAND="echo hello world"
1403+
1404+
stub docker \
1405+
"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"
1406+
1407+
run "$PWD"/hooks/command
1408+
1409+
assert_success
1410+
assert_output --partial "ran command in docker"
1411+
1412+
unstub docker
1413+
}
1414+
1415+
@test "Runs BUILDKITE_COMMAND with multiple log-opt" {
1416+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=max-size=10m
1417+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_1=max-file=3
1418+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_2=labels=production
1419+
export BUILDKITE_COMMAND="echo hello world"
1420+
1421+
stub docker \
1422+
"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"
1423+
1424+
run "$PWD"/hooks/command
1425+
1426+
assert_success
1427+
assert_output --partial "ran command in docker"
1428+
1429+
unstub docker
1430+
}
1431+
1432+
@test "Runs BUILDKITE_COMMAND with log-driver and log-opt" {
1433+
export BUILDKITE_PLUGIN_DOCKER_LOG_DRIVER=syslog
1434+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_0=syslog-address=tcp://192.168.1.3:514
1435+
export BUILDKITE_PLUGIN_DOCKER_LOG_OPT_1=tag=myapp
1436+
export BUILDKITE_COMMAND="echo hello world"
1437+
1438+
stub docker \
1439+
"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"
1440+
1441+
run "$PWD"/hooks/command
1442+
1443+
assert_success
1444+
assert_output --partial "ran command in docker"
1445+
1446+
unstub docker
1447+
}
1448+
13851449
@test "Run with BUILDKITE_COMMAND that exits with a failure" {
13861450
export BUILDKITE_COMMAND='pwd'
13871451

0 commit comments

Comments
 (0)