Skip to content

Commit 55157af

Browse files
authored
Merge pull request #36 from seek-oss/secrets
2 parents ec6d9a0 + 781aee3 commit 55157af

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ steps:
184184
- docker#v3.3.0
185185
```
186186

187+
### Specifying secrets
188+
189+
[Build-time variables] can be extracted from a pulled image, so when passing
190+
sensitive data, [secrets] should be used instead.
191+
192+
[secrets]: https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information
193+
194+
To use environment variables (perhaps fetched by another plugin) as secrets:
195+
196+
```dockerfile
197+
# syntax=docker/dockerfile:1.2
198+
199+
FROM bash
200+
201+
RUN --mount=type=secret,id=SECRET cat /run/secrets/SECRET
202+
```
203+
204+
```yaml
205+
steps:
206+
- command: echo amaze
207+
env:
208+
SECRET: wow
209+
plugins:
210+
- seek-oss/docker-ecr-cache#v1.9.0:
211+
secrets:
212+
- SECRET
213+
- docker#v3.3.0
214+
```
215+
216+
You must have a recent version of Docker with BuildKit enabled to use secrets.
217+
BuildKit will be enabled automatically if any secrets are present in the
218+
configuration.
219+
187220
### Changing the max cache time
188221

189222
By default images are kept in ECR for up to 30 days. This can be changed by specifying a `max-age-days` parameter:

hooks/lib/stdlib.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ read_build_args() {
2020
done
2121
}
2222

23+
read_secrets() {
24+
read_list_property 'SECRETS'
25+
for arg in ${result[@]+"${result[@]}"}; do
26+
secrets_args+=("--secret")
27+
secrets_args+=("id=${arg},env=${arg}")
28+
done
29+
}
30+
2331
# read a plugin property of type [array, string] into a Bash array. Buildkite
2432
# exposes a string value at BUILDKITE_PLUGIN_{NAME}_{KEY}, and array values at
2533
# BUILDKITE_PLUGIN_{NAME}_{KEY}_{IDX}.

hooks/pre-command

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ context="${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_CONTEXT:-"${context_dir}"}"
3333
build_args=()
3434
read_build_args
3535

36+
secrets_args=()
37+
read_secrets
38+
3639
echo "--- Pulling image"
3740
if ! docker pull "${image}:${tag}"; then
3841
echo '--- Building image'
@@ -53,6 +56,14 @@ if ! docker pull "${image}:${tag}"; then
5356
)
5457
done
5558
fi
59+
if [[ "${#secrets_args[@]}" -gt 0 ]]; then
60+
export DOCKER_BUILDKIT=1
61+
for sa in "${secrets_args[@]}"; do
62+
image_build_args+=(
63+
"${sa}"
64+
)
65+
done
66+
fi
5667

5768
echo "Inside $(pwd), running \`docker ${image_build_args[*]} ${context}\`"
5869
# We can't quote BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_ADDITIONAL_BUILD_ARGS, because it's passed here as a string instead of a bash array.

0 commit comments

Comments
 (0)