Skip to content

Commit 163723b

Browse files
authored
Merge pull request #292 from buildkite-plugins/SUP-2491-troubleshooting-permission-issues
Add troubleshooting section to README
2 parents a26011f + a8755dd commit 163723b

1 file changed

Lines changed: 67 additions & 13 deletions

File tree

README.md

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Also see the [Docker Compose Buildkite Plugin](https://github.com/buildkite-plug
88

99
### `run`
1010

11-
The following pipeline will build a binary in the dist directory using [golang Docker image](https://hub.docker.com/_/golang/) and then uploaded as an artifact.
11+
The following pipeline will build a binary in the dist directory using the [golang Docker image](https://hub.docker.com/_/golang/) and then uploaded as an artifact.
1212

1313
```yml
1414
steps:
@@ -164,7 +164,7 @@ You can read more about runtime variable interpolation from the [docs](https://b
164164

165165
If the image that you want to run is not in a registry the `load` property can be used to load an image from a tar file.
166166

167-
This can be useful if a previous step builds an image and uploads it as an artifact. The below example shows how a artifact can be downloaded and then passed to the `load` property to load the image which can then be referred to in the `image` property to start a container and run a command as explained above.
167+
This can be useful if a previous step builds an image and uploads it as an artifact. The below example shows how an artifact can be downloaded and then passed to the `load` property to load the image which can then be referred to in the `image` property to start a container and run a command as explained above.
168168

169169
```yml
170170
steps:
@@ -177,9 +177,9 @@ steps:
177177
image: "node:7"
178178
```
179179

180-
### 🚨 Warning
180+
### :warning: Warning
181181

182-
You need to be careful when/if [running the BuildKite agent itself in docker](https://buildkite.com/docs/agent/v3/docker) that, itself, runs pipelines that use this plugin. Make sure to read all the documentation on the matter, specially the caveats and warnings listed.
182+
You need to be careful when/if [running the Buildkite agent itself in docker](https://buildkite.com/docs/agent/v3/docker) that, itself, runs pipelines that use this plugin. Make sure to read all the documentation on the matter, specially the caveats and warnings listed.
183183

184184
## Configuration
185185

@@ -273,7 +273,7 @@ If you set this to `VALUE`, and `VALUE` is an environment variable containing a
273273

274274
When set to true, it will activate interpolation of variables in the elements of the `image` configuration variable. When turned off (the default), attempting to use variables will fail as the literal `$VARIABLE_NAME` string will be passed as the image name.
275275

276-
Environment variable interporation rules apply here. `$VARIABLE_NAME` is resolved at pipeline upload time, whereas `$$VARIABLE_NAME` is at run time. All things being equal, you likely want `$$VARIABLE_NAME`.
276+
Environment variable interpolation rules apply here. `$VARIABLE_NAME` is resolved at pipeline upload time, whereas `$$VARIABLE_NAME` is at run time. All things being equal, you likely want `$$VARIABLE_NAME`.
277277

278278
:warning: **Important:** this is considered an unsafe option as the most compatible way to achieve this is to run the strings through `eval` which could lead to arbitrary code execution or information leaking if you don't have complete control of the pipeline
279279

@@ -283,7 +283,7 @@ Whether or not to automatically propagate all* pipeline environment variables in
283283

284284
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.
285285

286-
\* Caveat: only environment variables listed in $BUILDKITE_ENV_FILE will be propagated. This does not include e.g. variables that you exported in an `environment` hook. If you wish for those to be propagated, try `env-propagation-list`.
286+
\* Caveat: only environment variables listed in $BUILDKITE_ENV_FILE will be propagated. This does not include for example variables that you exported in an `environment` hook. If you wish for those to be propagated, try `env-propagation-list`.
287287

288288
### `propagate-aws-auth-tokens` (optional, boolean)
289289

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

346346
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.
347347

348-
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.
348+
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.
349349

350350
Default: `true`
351351

@@ -435,7 +435,7 @@ Example: `[ "powershell", "-Command" ]`
435435

436436
### `shm-size` (optional, string)
437437

438-
Set the size of the `/dev/shm` shared memory filesystem mount inside the docker contianer. If unset, uses the default for the platform (typically `64mb`). See [docker runs runtime constraints documentation](https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources) for information on allowed formats.
438+
Set the size of the `/dev/shm` shared memory filesystem mount inside the docker container. If unset, uses the default for the platform (typically `64mb`). See [docker run's runtime constraints documentation](https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources) for information on allowed formats.
439439

440440
Example: `2gb`
441441

@@ -475,15 +475,15 @@ Example: `mynamespace`
475475

476476
### `volumes` (optional, array or boolean)
477477

478-
Extra volume mounts to pass to the docker container, in an array. Items are specified as `SOURCE:TARGET`. Each entry corresponds to a Docker CLI `--volume` parameter. Relative local paths are converted to their full-path (e.g `./code:/app`).
478+
Extra volume mounts to pass to the docker container, in an array. Items are specified as `SOURCE:TARGET`. Each entry corresponds to a Docker CLI `--volume` parameter. Relative local paths are converted to their full-path (for example `./code:/app`).
479479

480480
Example: `[ "/var/run/docker.sock:/var/run/docker.sock" ]`
481481

482482
### `expand-volume-vars` (optional, boolean, run only, unsafe)
483483

484484
When set to true, it will activate interpolation of variables in the elements of the `volumes` configuration array as well as `workdir`. When turned off (the default), attempting to use variables will fail as the literal `$VARIABLE_NAME` string will be passed to the `-v` option.
485485

486-
Environment variable interporation rules apply here. `$VARIABLE_NAME` is resolved at pipeline upload time, whereas `$$VARIABLE_NAME` is at run time. All things being equal, you likely want `$$VARIABLE_NAME`.
486+
Environment variable interpolation rules apply here. `$VARIABLE_NAME` is resolved at pipeline upload time, whereas `$$VARIABLE_NAME` is at run time. All things being equal, you likely want `$$VARIABLE_NAME`.
487487

488488
:warning: **Important:** this is considered an unsafe option as the most compatible way to achieve this is to run the strings through `eval` which could lead to arbitrary code execution or information leaking if you don't have complete control of the pipeline
489489

@@ -493,13 +493,13 @@ Tmpfs mounts to pass to the docker container, in an array. Each entry correspond
493493

494494
Example: `[ "/tmp", "/root/.cache" ]`
495495

496-
### `workdir`(optional, string)
496+
### `workdir` (optional, string)
497497

498498
The working directory to run the command in, inside the container. The default is `/workdir`. This path is also used by `mount-checkout` to determine where to mount the checkout in the container.
499499

500500
Example: `/app`
501501

502-
### `sysctls`(optional, array)
502+
### `sysctls` (optional, array)
503503

504504
Set namespaced kernel parameters in the container. More information can be found in https://docs.docker.com/engine/reference/commandline/run/.
505505

@@ -560,6 +560,60 @@ can be found in https://docs.docker.com/config/containers/resource_constraints/#
560560

561561
Example: `0`
562562

563+
## Troubleshooting
564+
565+
### File and Directory Permissions with Volume Mounts
566+
567+
When using volume mounts with Docker containers, file and directory permissions can become problematic due to user ID (UID) and group ID (GID) mismatches between the host and container environments.
568+
569+
#### Common Permission Issues
570+
571+
1. **Root-owned files**: Many Docker images run as root by default, creating files owned by root that the host user cannot modify or delete
572+
2. **Permission denied errors**: Host files may be inaccessible inside the container if UIDs/GIDs don't match
573+
3. **Build artifacts**: Generated files may have incorrect ownership, preventing cleanup by the Buildkite agent
574+
575+
#### Solutions
576+
577+
**Option 1: Use `propagate-uid-gid` (Recommended)**
578+
```yml
579+
steps:
580+
- command: "make build"
581+
plugins:
582+
- docker#v5.13.0:
583+
image: "node:18"
584+
propagate-uid-gid: true
585+
```
586+
This matches the container user's UID/GID to the host user, ensuring files created in volume mounts have correct ownership.
587+
588+
**Option 2: Use `chown` for cleanup**
589+
```yml
590+
steps:
591+
- command: "npm run build"
592+
plugins:
593+
- docker#v5.13.0:
594+
image: "node:18"
595+
chown: true
596+
```
597+
This changes ownership of the checkout directory back to the agent user after the container exits.
598+
599+
**Option 3: Specify explicit user**
600+
```yml
601+
steps:
602+
- command: "python setup.py build"
603+
plugins:
604+
- docker#v5.13.0:
605+
image: "python:3.9"
606+
user: "1000:1000" # Match your host user's UID:GID
607+
```
608+
609+
#### Troubleshooting Permission Issues
610+
611+
If you encounter permission errors:
612+
1. Check file ownership with `ls -la` on both host and container
613+
2. Verify UID/GID matching between host user and container user
614+
3. Consider using `propagate-uid-gid: true` to automatically handle ID mapping
615+
4. For persistent issues, use `chown: true` as a fallback solution
616+
563617
## Container Labels
564618

565619
When running a command, the plugin will automatically add the following Docker labels to the container:
@@ -582,7 +636,7 @@ This behaviour can be disabled with the `run-labels: false` option.
582636

583637
## Developing
584638

585-
To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).
639+
To run testing, shellchecks and plugin linting use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).
586640

587641
```bash
588642
bk run

0 commit comments

Comments
 (0)