Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mirror mount-buildkite-agent implementation from docker-buildkite-plugin #285

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ Whether to match the user ID and group ID for the container user to the user ID

Using this option ensures that any files created on shared mounts from within the container will be accessible to the host user. It is otherwise common to accidentally create root-owned files that Buildkite will be unable to remove, since containers by default run as the root user.

### `mount-buildkite-agent` (optional, run-only, boolean)

Whether to automatically mount the `buildkite-agent` binary and associated environment variables from the host agent machine into the container.

Default: `false`

### `pull-retries` (optional)

A number of times to retry failed docker pull. Defaults to 0.
Expand Down
25 changes: 24 additions & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ if [[ -n "$(plugin_read_config ENTRYPOINT)" ]] ; then
run_params+=("--entrypoint \"$(plugin_read_config ENTRYPOINT)\"")
fi

# Optionally handle the mount-buildkite-agent option
if [[ "$(plugin_read_config MOUNT_BUILDKITE_AGENT "false")" == "true" ]]; then
if [[ -z "${BUILDKITE_AGENT_BINARY_PATH:-}" ]] ; then
if ! command -v buildkite-agent >/dev/null 2>&1 ; then
echo -n "+++ 🚨 Failed to find buildkite-agent in PATH to mount into container, "
echo "you can disable this behaviour with 'mount-buildkite-agent:false'"
else
BUILDKITE_AGENT_BINARY_PATH=$(command -v buildkite-agent)
fi
fi
fi

# Mount buildkite-agent if we have a path for it
if [[ -n "${BUILDKITE_AGENT_BINARY_PATH:-}" ]] ; then
run_params+=(
"-e" "BUILDKITE_JOB_ID"
"-e" "BUILDKITE_BUILD_ID"
"-e" "BUILDKITE_AGENT_ACCESS_TOKEN"
"-v" "$BUILDKITE_AGENT_BINARY_PATH:/usr/bin/buildkite-agent"
)
fi

run_params+=("$run_service")

build_params=(--pull)
Expand Down Expand Up @@ -298,7 +320,8 @@ set -e

if [[ $exitcode -ne 0 ]] ; then
echo "^^^ +++"
echo "+++ :warning: Failed to run command, exited with $exitcode"
echo "+++ :warning: Failed to run command, exited with $exitcode, run params:"
echo "${run_params[@]}"
fi

if [[ -n "${BUILDKITE_AGENT_ACCESS_TOKEN:-}" ]] ; then
Expand Down
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ configuration:
type: string
propagate-uid-gid:
type: boolean
mount-buildkite-agent:
type: boolean
oneOf:
- required:
- run
Expand All @@ -97,3 +99,4 @@ configuration:
workdir: [ run ]
user: [ run ]
propagate-uid-gid: [ run ]
mount-buildkite-agent: [ run ]