Skip to content

Commit d3f21ed

Browse files
committed
Update multiplatform validation for secrets
1 parent 71c1d72 commit d3f21ed

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ see https://docs.docker.com/build/building/secrets/.
377377
In order to use secrets in buildrunner, you need to do the following:
378378

379379
#. Update the buildrunner configuration file
380-
* Set ``use-legacy-builder`` to ``false``
380+
* Set ``use-legacy-builder`` to ``false`` or add ``platforms`` to the ``build`` section
381381
* Add the secrets to the ``secrets`` section in the ``build`` section
382382
#. Update the Dockerfile to use the secrets
383383
* Add the ``--mount`` at the beginning of each RUN command that needs the secret

buildrunner/config/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,22 @@ def validate_steps(cls, vals, info) -> None:
163163

164164
# Checks steps for mutli-platform or secrets
165165
has_multi_platform_build = False
166-
has_secrets = False
166+
167+
# Check for multi-platform builds and secrets validation
167168
for step in vals.values():
168169
has_multi_platform_build = (
169170
has_multi_platform_build or step.is_multi_platform()
170171
)
171-
has_secrets = has_secrets or step.has_secrets()
172172

173-
if has_secrets:
174-
if info.data.get("use_legacy_builder"):
173+
# If the step has secrets and the builder is legacy or no platforms are set for the step, raise an error
174+
if (
175+
step.has_secrets()
176+
and not step.is_multi_platform()
177+
and info.data.get("use_legacy_builder")
178+
):
175179
raise ValueError(
176-
"Build secrets are not supported with the legacy builder. Please set use-legacy-builder to false in order to use secrets in your build."
180+
"Build secrets are not supported with the legacy builder. Please set use-legacy-builder to false"
181+
" or add platforms to the build section in order to use secrets in your build."
177182
)
178183

179184
if has_multi_platform_build:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# In order to use secrets, you need to set use-legacy-builder to false in the config file OR
2+
# add platforms to the build section
3+
# To run this example, you need to set the SECRET_PASSWORD environment variable
4+
# and run the example with the following command:
5+
# SECRET2=my_secret ./run-buildrunner.sh -f examples/build/secrets/buildrunner-platforms.yaml
6+
# More info about secrets: https://docs.docker.com/build/building/secrets/
7+
steps:
8+
simple-build-step:
9+
build:
10+
dockerfile: |
11+
FROM alpine:latest
12+
RUN --mount=type=secret,id=secret1 \
13+
--mount=type=secret,id=secret2 \
14+
SECRET1_FILE=/run/secrets/secret1 \
15+
SECRET2_VARIABLE=$(cat /run/secrets/secret2) \
16+
echo "Using secrets in my build - secret1: $(cat $SECRET1_FILE) secret2: $SECRET2_VARIABLE"
17+
secrets:
18+
# Example of a secret that is a file
19+
- id=secret1,src=examples/build/secrets/secret1.txt
20+
# Example of a secret that is an environment variable
21+
- id=secret2,env=SECRET2
22+
platforms:
23+
- linux/amd64
24+
- linux/arm64

0 commit comments

Comments
 (0)