13
13
import sys
14
14
from collections .abc import MutableMapping
15
15
from enum import Enum
16
- from functools import lru_cache
17
- from functools import partial
16
+ from functools import lru_cache , partial
18
17
from tempfile import TemporaryDirectory
19
18
20
19
import docker
@@ -246,6 +245,23 @@ def _get_image_build_args(image_options, ns):
246
245
return build_args
247
246
248
247
248
+ def _get_image_extra_build_command_options (image_options , ns ):
249
+ """
250
+ Render extraBuildCommandOptions from chartpress.yaml that could be
251
+ templates, using the provided namespace that contains keys with dynamic
252
+ values such as LAST_COMMIT or TAG.
253
+
254
+ Args:
255
+ image_options (dict):
256
+ The dictionary for a given image from chartpress.yaml.
257
+ Strings in `image_options['extraBuildCommandOptions']` will be rendered
258
+ and returned.
259
+ ns (dict): the namespace used when rendering templated arguments
260
+ """
261
+ options = image_options .get ("extraBuildCommandOptions" , [])
262
+ return [str (option ).format (** ns ) for option in options ]
263
+
264
+
249
265
def _get_image_build_context_path (name , options ):
250
266
"""
251
267
Return the image's contextPath configuration value, or a default value based
@@ -306,6 +322,7 @@ def build_image(
306
322
context_path ,
307
323
dockerfile_path = None ,
308
324
build_args = None ,
325
+ extra_build_command_options = None ,
309
326
* ,
310
327
push = False ,
311
328
builder = Builder .DOCKER_BUILD ,
@@ -331,6 +348,9 @@ def build_image(
331
348
"<context_path>/Dockerfile".
332
349
build_args (dict, optional):
333
350
Dictionary of docker build arguments.
351
+ extra_build_command_options (list, optional):
352
+ List of other docker build options to use. Each item should be a string
353
+ that gets appended to the build command (e.g. "--label=version=0.1.0").
334
354
push (bool, optional):
335
355
Whether to push the image to a registry
336
356
builder (str):
@@ -366,6 +386,8 @@ def build_image(
366
386
cmd .append ("--push" )
367
387
elif len (platforms ) <= 1 :
368
388
cmd .append ("--load" )
389
+ if extra_build_command_options :
390
+ cmd .extend (extra_build_command_options )
369
391
_check_call (cmd )
370
392
371
393
if builder == Builder .DOCKER_BUILD and push :
@@ -626,18 +648,19 @@ def build_images(
626
648
627
649
# build image and optionally push image
628
650
if force_build or _image_needs_building (image_spec , platforms ):
651
+ expansion_namespace = {
652
+ "LAST_COMMIT" : _get_latest_commit_tagged_or_modifying_paths (
653
+ * all_image_paths , echo = False
654
+ ),
655
+ "TAG" : image_tag ,
656
+ }
629
657
build_image (
630
658
image_spec ,
631
659
_get_image_build_context_path (name , options ),
632
660
dockerfile_path = _get_image_dockerfile_path (name , options ),
633
- build_args = _get_image_build_args (
634
- options ,
635
- {
636
- "LAST_COMMIT" : _get_latest_commit_tagged_or_modifying_paths (
637
- * all_image_paths , echo = False
638
- ),
639
- "TAG" : image_tag ,
640
- },
661
+ build_args = _get_image_build_args (options , expansion_namespace ),
662
+ extra_build_command_options = _get_image_extra_build_command_options (
663
+ options , expansion_namespace
641
664
),
642
665
push = push or force_push ,
643
666
builder = builder ,
@@ -897,9 +920,11 @@ def publish_pages(
897
920
if os .path .isfile (os .path .join (checkout_dir , "index.yaml" )):
898
921
with open (os .path .join (checkout_dir , "index.yaml" )) as f :
899
922
chart_repo_index = yaml .load (f )
900
- published_charts = chart_repo_index ["entries" ].get (chart_name )
923
+ published_charts = chart_repo_index ["entries" ].get (chart_name , [] )
901
924
902
- if any (c ["version" ] == chart_version for c in published_charts ):
925
+ if published_charts and any (
926
+ c ["version" ] == chart_version for c in published_charts
927
+ ):
903
928
if force :
904
929
_log (
905
930
f"Chart of version { chart_version } already exists, overwriting it."
0 commit comments