@@ -236,6 +236,23 @@ def _get_image_build_args(image_options, ns):
236
236
return build_args
237
237
238
238
239
+ def _get_image_extra_build_command_options (image_options , ns ):
240
+ """
241
+ Render extraBuildCommandOptions from chartpress.yaml that could be
242
+ templates, using the provided namespace that contains keys with dynamic
243
+ values such as LAST_COMMIT or TAG.
244
+
245
+ Args:
246
+ image_options (dict):
247
+ The dictionary for a given image from chartpress.yaml.
248
+ Strings in `image_options['extraBuildCommandOptions']` will be rendered
249
+ and returned.
250
+ ns (dict): the namespace used when rendering templated arguments
251
+ """
252
+ options = image_options .get ("extraBuildCommandOptions" , [])
253
+ return [str (option ).format (** ns ) for option in options ]
254
+
255
+
239
256
def _get_image_build_context_path (name , options ):
240
257
"""
241
258
Return the image's contextPath configuration value, or a default value based
@@ -296,6 +313,7 @@ def build_image(
296
313
context_path ,
297
314
dockerfile_path = None ,
298
315
build_args = None ,
316
+ extra_build_command_options = None ,
299
317
* ,
300
318
push = False ,
301
319
builder = Builder .DOCKER_BUILD ,
@@ -321,6 +339,9 @@ def build_image(
321
339
"<context_path>/Dockerfile".
322
340
build_args (dict, optional):
323
341
Dictionary of docker build arguments.
342
+ extra_build_command_options (list, optional):
343
+ List of other docker build options to use. Each item should be a string
344
+ that gets appended to the build command (e.g. "--label=version=0.1.0").
324
345
push (bool, optional):
325
346
Whether to push the image to a registry
326
347
builder (str):
@@ -356,6 +377,8 @@ def build_image(
356
377
cmd .append ("--push" )
357
378
elif len (platforms ) <= 1 :
358
379
cmd .append ("--load" )
380
+ if extra_build_command_options :
381
+ cmd .extend (extra_build_command_options )
359
382
_check_call (cmd )
360
383
361
384
if builder == Builder .DOCKER_BUILD and push :
@@ -592,18 +615,19 @@ def build_images(
592
615
593
616
# build image and optionally push image
594
617
if force_build or _image_needs_building (image_spec , platforms ):
618
+ expansion_namespace = {
619
+ "LAST_COMMIT" : _get_latest_commit_tagged_or_modifying_paths (
620
+ * all_image_paths , echo = False
621
+ ),
622
+ "TAG" : image_tag ,
623
+ }
595
624
build_image (
596
625
image_spec ,
597
626
_get_image_build_context_path (name , options ),
598
627
dockerfile_path = _get_image_dockerfile_path (name , options ),
599
- build_args = _get_image_build_args (
600
- options ,
601
- {
602
- "LAST_COMMIT" : _get_latest_commit_tagged_or_modifying_paths (
603
- * all_image_paths , echo = False
604
- ),
605
- "TAG" : image_tag ,
606
- },
628
+ build_args = _get_image_build_args (options , expansion_namespace ),
629
+ extra_build_command_options = _get_image_extra_build_command_options (
630
+ options , expansion_namespace
607
631
),
608
632
push = push or force_push ,
609
633
builder = builder ,
0 commit comments