Skip to content

Commit

Permalink
Merge pull request #114 from timelydata/master
Browse files Browse the repository at this point in the history
Add propagate-uid-gid option
  • Loading branch information
toolmantim authored Apr 8, 2019
2 parents 7f17dfc + 25f13e1 commit da31a7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ Whether or not to automatically propagate all pipeline environment variables int

Note that only pipeline variables will automatically be propagated (what you see in the Buildkite UI). Variables set in proceeding hook scripts will not be propagated to the container.

### `propagate-uid-gid` (optional, boolean)

Whether to match the user ID and group ID for the container user to the user ID and group ID for the host user. It is similar to specifying `user: 1000:1000`, except it avoids hardcoding a particular user/group 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.

### `privileged` (optional, boolean)

Whether or not to run the container in [privileged mode](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
Expand Down
9 changes: 9 additions & 0 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,19 @@ if [[ -n "${workdir:-}" ]] || [[ "${BUILDKITE_PLUGIN_DOCKER_MOUNT_CHECKOUT:-on}"
fi

# Support docker run --user
if [[ -n "${BUILDKITE_PLUGIN_DOCKER_USER:-}" ]] && [[ -n "${BUILDKITE_PLUGIN_DOCKER_PROPAGATE_UID_GID:-}" ]]; then
echo "+++ Error: Can't set both user and propagate-uid-gid"
exit 1
fi

if [[ -n "${BUILDKITE_PLUGIN_DOCKER_USER:-}" ]] ; then
args+=("-u" "${BUILDKITE_PLUGIN_DOCKER_USER:-}")
fi

if [[ -n "${BUILDKITE_PLUGIN_DOCKER_PROPAGATE_UID_GID:-}" ]] ; then
args+=("-u" "$(id -u):$(id -g)")
fi

# Support docker run --group-add
while IFS='=' read -r name _ ; do
if [[ $name =~ ^(BUILDKITE_PLUGIN_DOCKER_ADDITIONAL_GROUPS_[0-9]+) ]] ; then
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ configuration:
type: string
propagate-environment:
type: boolean
propagate-uid-gid:
type: boolean
privileged:
type: boolean
init:
Expand Down

0 comments on commit da31a7c

Please sign in to comment.