Skip to content

Commit 058047e

Browse files
authored
Merge pull request #37 from seek-oss/verbatim-secret-flag
Support verbatim secret flag values
2 parents 9e01f43 + 51e8349 commit 058047e

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,25 @@ steps:
212212
- docker#v3.8.0
213213
```
214214

215-
You must have a recent version of Docker with BuildKit enabled to use secrets.
216-
BuildKit will be enabled automatically if any secrets are present in the
217-
configuration.
215+
You can also specify the full `--secret` flag value if you need more control:
216+
217+
```yaml
218+
steps:
219+
- command: echo amaze
220+
env:
221+
SECRET: wow
222+
plugins:
223+
- seek-oss/private-npm#v1.2.0:
224+
env: SECRET
225+
- seek-oss/docker-ecr-cache#v1.10.0:
226+
secrets:
227+
- id=npmrc,src=.npmrc
228+
- docker#v3.8.0
229+
```
230+
231+
You must have a recent version of Docker with BuildKit support to use secrets.
232+
This plugin will automatically enable BuildKit via the `DOCKER_BUILDKIT`
233+
environment variable if any secrets are present in the configuration.
218234

219235
### Changing the max cache time
220236

hooks/lib/stdlib.bash

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ read_secrets() {
2424
read_list_property 'SECRETS'
2525
for arg in ${result[@]+"${result[@]}"}; do
2626
secrets_args+=("--secret")
27-
secrets_args+=("id=${arg},env=${arg}")
27+
if [[ "${arg}" =~ ^id= ]]; then
28+
# Assume this is a full argument like id=123,src=path/to/file
29+
secrets_args+=("${arg}")
30+
else
31+
# Assume this is environment variable shorthand like SECRET_ENV
32+
secrets_args+=("id=${arg},env=${arg}")
33+
fi
2834
done
2935
}
3036

37+
read_secrets_with_output() {
38+
read_secrets
39+
40+
echo "${secrets_args[@]}"
41+
}
42+
3143
# read a plugin property of type [array, string] into a Bash array. Buildkite
3244
# exposes a string value at BUILDKITE_PLUGIN_{NAME}_{KEY}, and array values at
3345
# BUILDKITE_PLUGIN_{NAME}_{KEY}_{IDX}.

tests/stdlib.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ pre_command_hook="$PWD/hooks/pre-command"
1919
# coverage happens via later tests of compute_tag.
2020
}
2121

22+
@test "Can read secrets from array" {
23+
export BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_SECRETS_1="FOO"
24+
export BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_SECRETS_2="id=1,env=BAR"
25+
export BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_SECRETS_3="id=2,src=path/to/secret.txt"
26+
27+
run read_secrets_with_output
28+
29+
assert_success
30+
assert_output "--secret id=FOO,env=FOO --secret id=1,env=BAR --secret id=2,src=path/to/secret.txt"
31+
}
32+
2233
@test "Can get default image name" {
2334
export BUILDKITE_ORGANIZATION_SLUG="example-org"
2435
export BUILDKITE_PIPELINE_SLUG="example-pipeline"

0 commit comments

Comments
 (0)