File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,37 @@ steps:
167
167
- docker#v3.3.0
168
168
` ` `
169
169
170
+ # ## Specifying secrets
171
+
172
+ [Build-time variables] can be extracted from a pulled image, so when passing
173
+ sensitive data, [secrets] should be used instead.
174
+
175
+ [secrets] : https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information
176
+
177
+ To use environment variables (perhaps fetched by another plugin) as secrets :
178
+
179
+ ` ` ` dockerfile
180
+ # syntax=docker/dockerfile:1.2
181
+
182
+ FROM bash
183
+
184
+ RUN --mount=type=secret,id=SECRET cat /run/secrets/SECRET
185
+ ` ` `
186
+
187
+ ` ` ` yaml
188
+ steps:
189
+ - command: echo amaze
190
+ env:
191
+ SECRET: wow
192
+ plugins:
193
+ - seek-oss/docker-ecr-cache#v1.9.0:
194
+ secrets:
195
+ - SECRET
196
+ - docker#v3.3.0
197
+ ` ` `
198
+
199
+ You must have a recent version of Docker with BuildKit enabled to use secrets.
200
+
170
201
# ## Changing the max cache time
171
202
172
203
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 @@ -20,6 +20,9 @@ context="${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_CONTEXT:-"${docker_file_dir}"}"
20
20
build_args=()
21
21
read_build_args
22
22
23
+ secrets_args=()
24
+ read_secrets
25
+
23
26
echo " --- Pulling image"
24
27
if ! docker pull " ${image} :${tag} " ; then
25
28
echo ' --- Building image'
@@ -40,6 +43,13 @@ if ! docker pull "${image}:${tag}"; then
40
43
)
41
44
done
42
45
fi
46
+ if [[ " ${# secrets_args[@]} " -gt 0 ]]; then
47
+ for sa in " ${secrets_args[@]} " ; do
48
+ image_build_args+=(
49
+ " ${sa} "
50
+ )
51
+ done
52
+ fi
43
53
44
54
echo " Inside $( pwd) , running \` docker ${image_build_args[*]} ${context} \` "
45
55
# 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