Skip to content

Commit 5c8e1c3

Browse files
committed
Add validation for build secrets
1 parent a82ce1c commit 5c8e1c3

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ shows the different configuration options available:
355355
# More info about secrets: https://docs.docker.com/build/building/secrets/
356356
secrets:
357357
# Example of a secret that is a file
358-
- id=secret1,src=examples/build/secrets/secret1.txt
358+
- id=secret1,src=<path to the secret file>
359359
# Example of a secret that is an environment variable
360-
- id=secret2,env=SECRET2
360+
- id=secret2,env=<environment variable name>
361361
362362
363363
.. _Build Secrets:

buildrunner/config/models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Config(BaseModel, extra="forbid"):
150150

151151
@field_validator("steps")
152152
@classmethod
153-
def validate_steps(cls, vals) -> None:
153+
def validate_steps(cls, vals, info) -> None:
154154
"""
155155
Validate the config file
156156
@@ -161,12 +161,20 @@ def validate_steps(cls, vals) -> None:
161161
if not vals:
162162
raise ValueError('The "steps" configuration was not provided')
163163

164-
# Checks to see if there is a mutli-platform build step in the config
164+
# Checks steps for mutli-platform or secrets
165165
has_multi_platform_build = False
166+
has_secrets = False
166167
for step in vals.values():
167168
has_multi_platform_build = (
168169
has_multi_platform_build or step.is_multi_platform()
169170
)
171+
has_secrets = has_secrets or step.has_secrets()
172+
173+
if has_secrets:
174+
if info.data.get("use_legacy_builder"):
175+
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."
177+
)
170178

171179
if has_multi_platform_build:
172180
mp_push_tags = set()

buildrunner/config/models_step.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,9 @@ def is_multi_platform(self):
243243
Check if the step is a multi-platform build step
244244
"""
245245
return self.build and self.build.platforms is not None
246+
247+
def has_secrets(self):
248+
"""
249+
Check if the step has secrets
250+
"""
251+
return self.build and self.build.secrets is not None

0 commit comments

Comments
 (0)