File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,39 @@ steps:
184
184
- docker#v3.3.0
185
185
` ` `
186
186
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
+
187
220
# ## Changing the max cache time
188
221
189
222
By default images are kept in ECR for up to 30 days. This can be changed by specifying a `max-age-days` parameter :
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ read_build_args() {
20
20
done
21
21
}
22
22
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
+
23
31
# read a plugin property of type [array, string] into a Bash array. Buildkite
24
32
# exposes a string value at BUILDKITE_PLUGIN_{NAME}_{KEY}, and array values at
25
33
# BUILDKITE_PLUGIN_{NAME}_{KEY}_{IDX}.
Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ context="${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_CONTEXT:-"${context_dir}"}"
33
33
build_args=()
34
34
read_build_args
35
35
36
+ secrets_args=()
37
+ read_secrets
38
+
36
39
echo " --- Pulling image"
37
40
if ! docker pull " ${image} :${tag} " ; then
38
41
echo ' --- Building image'
@@ -53,6 +56,14 @@ if ! docker pull "${image}:${tag}"; then
53
56
)
54
57
done
55
58
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
56
67
57
68
echo " Inside $( pwd) , running \` docker ${image_build_args[*]} ${context} \` "
58
69
# 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.
You can’t perform that action at this time.
0 commit comments