Skip to content

Commit

Permalink
Merge pull request #122 from moorthya/sysctl_support
Browse files Browse the repository at this point in the history
Add docker sysctl support
  • Loading branch information
lox authored Apr 30, 2019
2 parents 7c8e01e + e0bf028 commit f199bc8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_VOLUMES BUILDKITE_PLUGIN
done
fi

# Ensure sysctl option is an array
if [[ -n "${BUILDKITE_PLUGIN_DOCKER_SYSCTLS:-}" ]] ; then
echo -n "🚨 The Docker Plugin’s sysctl configuration option must be an array."
exit 1
fi

# Parse sysctl args and add them to docker args
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_SYSCTLS ; then
for arg in "${result[@]}" ; do
args+=( "--sysctl" "$arg" )
done
fi

# Set workdir if one is provided or if the checkout is mounted
if [[ -n "${workdir:-}" ]] || [[ "${BUILDKITE_PLUGIN_DOCKER_MOUNT_CHECKOUT:-on}" =~ ^(true|on|1)$ ]]; then
args+=("--workdir" "${workdir}")
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ configuration:
type: boolean
init:
type: boolean
sysctls:
type: array
required:
- image
additionalProperties: false
23 changes: 23 additions & 0 deletions tests/command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ export DOCKER_STUB_DEBUG=/dev/tty
unset BUILDKITE_PLUGIN_DOCKER_ENVIRONMENT_1
}

@test "Runs BUILDKITE_COMMAND with sysctls" {
export BUILDKITE_PLUGIN_DOCKER_WORKDIR=/app
export BUILDKITE_PLUGIN_DOCKER_IMAGE=image:tag
export BUILDKITE_PLUGIN_DOCKER_MOUNT_BUILDKITE_AGENT=false
export BUILDKITE_PLUGIN_DOCKER_SYSCTLS_0=net.ipv4.ip_forward=1
export BUILDKITE_PLUGIN_DOCKER_SYSCTLS_1=net.unix.max_dgram_qlen=200
export BUILDKITE_COMMAND="echo hello world; pwd"

stub docker \
"run -it --rm --init --volume $PWD:/app --sysctl net.ipv4.ip_forward=1 --sysctl net.unix.max_dgram_qlen=200 --workdir /app image:tag /bin/sh -e -c 'echo hello world; pwd' : echo ran command in docker"

run $PWD/hooks/command

assert_success
assert_output --partial "ran command in docker"

unstub docker
unset BUILDKITE_PLUGIN_DOCKER_IMAGE
unset BUILDKITE_COMMAND
unset BUILDKITE_PLUGIN_DOCKER_ENVIRONMENT_0
unset BUILDKITE_PLUGIN_DOCKER_ENVIRONMENT_1
}

@test "Runs BUILDKITE_COMMAND with mount-checkout=false" {
export BUILDKITE_PLUGIN_DOCKER_IMAGE=image:tag
export BUILDKITE_PLUGIN_DOCKER_MOUNT_BUILDKITE_AGENT=false
Expand Down

0 comments on commit f199bc8

Please sign in to comment.