Skip to content

Commit

Permalink
Merge pull request #354 from buildkite-plugins/toote_mount_checkout_path
Browse files Browse the repository at this point in the history
Mount checkout path
  • Loading branch information
pzeballos authored Oct 24, 2022
2 parents e7ebf73 + b647262 commit 779e0e1
Showing 5 changed files with 395 additions and 74 deletions.
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ The following pipeline will run `test.sh` inside a `app` service container using
steps:
- command: test.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
```
@@ -28,7 +28,7 @@ through if you need:
steps:
- command: test.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
config: docker-compose.tests.yml
env:
@@ -41,7 +41,7 @@ or multiple config files:
steps:
- command: test.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
config:
- docker-compose.yml
@@ -56,7 +56,7 @@ env:
steps:
- command: test.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
```

@@ -65,7 +65,7 @@ If you want to control how your command is passed to docker-compose, you can use
```yml
steps:
- plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
command: ["custom", "command", "values"]
```
@@ -79,15 +79,15 @@ steps:
- plugins:
- docker-login#v2.0.1:
username: xyz
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: app
image-repository: index.docker.io/myorg/myrepo
- wait
- command: test.sh
plugins:
- docker-login#v2.0.1:
username: xyz
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
```

@@ -104,7 +104,7 @@ steps:
- command: generate-dist.sh
artifact_paths: "dist/*"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
```

@@ -122,7 +122,7 @@ steps:
- command: generate-dist.sh
artifact_paths: "dist/*"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
volumes:
- "./dist:/app/dist"
@@ -146,7 +146,7 @@ this plugin offers a `environment` block of its own:
steps:
- command: generate-dist.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
env:
- BUILDKITE_BUILD_NUMBER
@@ -164,7 +164,7 @@ Alternatively, you can have the plugin add all environment variables defined for
steps:
- command: use-vars.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
propagate-environment: true
```
@@ -179,7 +179,7 @@ Alternatively, if you want to set build arguments when pre-building an image, th
steps:
- command: generate-dist.sh
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: app
image-repository: index.docker.io/myorg/myrepo
args:
@@ -196,7 +196,7 @@ If you have multiple steps that use the same service/image (such as steps that r
steps:
- label: ":docker: Build"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: app
image-repository: index.docker.io/myorg/myrepo
@@ -206,7 +206,7 @@ steps:
command: test.sh
parallelism: 25
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: app
```

@@ -222,7 +222,7 @@ steps:
agents:
queue: docker-builder
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build:
- app
- tests
@@ -234,7 +234,7 @@ steps:
command: test.sh
parallelism: 25
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: tests
```

@@ -246,7 +246,7 @@ If you want to push your Docker images ready for deployment, you can use the `pu
steps:
- label: ":docker: Push"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
push: app
```

@@ -256,7 +256,7 @@ To push multiple images, you can use a list:
steps:
- label: ":docker: Push"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
push:
- first-service
- second-service
@@ -268,7 +268,7 @@ If you want to push to a specific location (that's not defined as the `image` in
steps:
- label: ":docker: Push"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
push:
- app:index.docker.io/myorg/myrepo/myapp
- app:index.docker.io/myorg/myrepo/myapp:latest
@@ -282,14 +282,14 @@ A newly spawned agent won't contain any of the docker caches for the first run w
steps:
- label: ":docker: Build an image"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: app
image-repository: index.docker.io/myorg/myrepo
cache-from: app:index.docker.io/myorg/myrepo/myapp:latest
- wait
- label: ":docker: Push to final repository"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
push:
- app:index.docker.io/myorg/myrepo/myapp
- app:index.docker.io/myorg/myrepo/myapp:latest
@@ -303,7 +303,7 @@ This plugin allows for the value of `cache-from` to be a string or a list. If it
steps:
- label: ":docker Build an image"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: app
image-repository: index.docker.io/myorg/myrepo
cache-from:
@@ -312,7 +312,7 @@ steps:
- wait
- label: ":docker: Push to final repository"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
push:
- app:index.docker.io/myorg/myrepo/myapp
- app:index.docker.io/myorg/myrepo/myapp:my-branch
@@ -326,7 +326,7 @@ Adding a grouping tag to the end of a cache-from list item allows this plugin to
steps:
- label: ":docker: Build Intermediate Image"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: myservice_intermediate # docker-compose.yml is the same as myservice but has `target: intermediate`
image-name: buildkite-build-${BUILDKITE_BUILD_NUMBER}
image-repository: index.docker.io/myorg/myrepo/myservice_intermediate
@@ -336,7 +336,7 @@ steps:
- wait
- label: ":docker: Build Final Image"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: myservice
image-name: buildkite-build-${BUILDKITE_BUILD_NUMBER}
image-repository: index.docker.io/myorg/myrepo
@@ -380,7 +380,7 @@ A basic pipeline similar to the following:
steps:
- label: ":docker: Run & Push"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
run: myservice
push: myservice
```
@@ -395,7 +395,7 @@ A basic pipeline similar to the following:
steps:
- label: ":docker: Build & Push"
plugins:
- docker-compose#v4.3.0:
- docker-compose#v4.5.0:
build: myservice
push: myservice
```
@@ -468,7 +468,7 @@ Completely avoid running any `pull` command. Images being used will need to be p

### `workdir` (optional, run only)

Specify the container working directory via `docker-compose run --workdir`. This option is also used by [`mount-checkout`](#mount-checkout-optional-run-only-boolean) to determine where to mount the checkout in the container.
Specify the container working directory via `docker-compose run --workdir`. This option is also used by [`mount-checkout`](#mount-checkout-optional-run-only-boolean) if it doesn't specify where to mount the checkout in the container.

Example: `/app`

@@ -494,9 +494,11 @@ Whether to automatically mount the `buildkite-agent` binary and associated envir

Default: `false`

### `mount-checkout` (optional, run-only, boolean)
### `mount-checkout` (optional, run-only, string or boolean)

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.
The absolute path where to mount the current working directory which contains your checked out codebase.

If set to `true` it will mount onto `/workdir`, unless `workdir` is set, in which case that will be used.

Default: `false`

11 changes: 7 additions & 4 deletions commands/run.sh
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ override_file="docker-compose.buildkite-${BUILDKITE_BUILD_NUMBER}-override.yml"
pull_retries="$(plugin_read_config PULL_RETRIES "0")"
mount_ssh_agent=''
mount_checkout="$(plugin_read_config MOUNT_CHECKOUT "false")"
workdir=''

expand_headers_on_error() {
echo "^^^ +++"
@@ -138,8 +139,6 @@ if [[ "$(plugin_read_config DEPENDENCIES "true")" == "false" ]] ; then
run_params+=(--no-deps)
fi

workdir=''

if [[ -n "$(plugin_read_config WORKDIR)" ]] || [[ "${mount_checkout}" == "true" ]]; then
workdir="$(plugin_read_config WORKDIR "$workdir_default")"
fi
@@ -148,9 +147,13 @@ if [[ -n "${workdir}" ]] ; then
run_params+=("--workdir=${workdir}")
fi

# By default, mount $PWD onto $WORKDIR
if [[ "${mount_checkout}" == "true" ]] ; then
if [[ "${mount_checkout}" == "true" ]]; then
run_params+=("-v" "${pwd_default}:${workdir}")
elif [[ "${mount_checkout}" =~ ^/.*$ ]]; then
run_params+=("-v" "${pwd_default}:${mount_checkout}")
elif [[ "${mount_checkout}" != "false" ]]; then
echo -n "🚨 mount-checkout should be either true or an absolute path to use as a mountpoint"
exit 1
fi

# Can't set both user and propagate-uid-gid
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ configuration:
mount-ssh-agent:
type: boolean
mount-checkout:
type: boolean
type: [ boolean, string ]
no-cache:
type: boolean
propagate-environment:
Loading

0 comments on commit 779e0e1

Please sign in to comment.