Skip to content

Commit 1ff8059

Browse files
committed
CH-260 fix tag generation for task images
1 parent ae229a2 commit 1ff8059

5 files changed

Lines changed: 72 additions & 4 deletions

File tree

tools/deployment-cli-tools/ch_cli_tools/configurationgenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _clear_unused_db_configuration(self, harness_config):
357357

358358
def image_tag(self, image_name, build_context_path=None, dependencies=()):
359359
tag = self.tag
360-
360+
361361
return self.registry + image_name + (f':{tag}' if tag else '')
362362

363363

tools/deployment-cli-tools/ch_cli_tools/preprocessing.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import shutil
77
from glob import glob
8-
from os.path import join, basename, isabs, relpath
8+
from os.path import join, basename, dirname, isabs, relpath
99

1010
from .helm import KEY_APPS, KEY_TASK_IMAGES, KEY_HARNESS, KEY_DEPLOYMENT
1111
from .configurationgenerator import DEFAULT_IGNORE, generate_tag_from_content
@@ -136,6 +136,18 @@ def get_build_paths(root_paths, helm_values, merge_build_path=DEFAULT_MERGE_PATH
136136
relpath(base_path, root_path)
137137
)
138138

139+
for task_path in find_subdirs(join(base_path, 'tasks')):
140+
task_name = app_name_from_path(relpath(task_path, dirname(base_path)))
141+
if task_name not in helm_values.get(KEY_TASK_IMAGES, {}):
142+
continue
143+
if task_name not in artifacts:
144+
artifacts[task_name] = task_path
145+
else:
146+
artifacts[task_name] = join(
147+
merge_build_path,
148+
relpath(task_path, root_path)
149+
)
150+
139151
return artifacts
140152

141153

tools/deployment-cli-tools/ch_cli_tools/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def merge_configuration_directories(source: Union[str, pathlib.Path], destinatio
280280
merge_roots = ('deploy', 'deployment')
281281
spec = pathspec.PathSpec.from_lines('gitwildmatch', exclude)
282282
copy_single_files = False
283-
283+
284284
if not destination_path.exists():
285285
logging.info("Creating merged directory %s from %s", destination, source)
286286
merge_roots_set = set(merge_roots)

tools/deployment-cli-tools/harness-deployment

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ if __name__ == "__main__":
126126
app_version=args.app_version,
127127
))
128128

129-
130129
helm_values = chart_fn(**chart_args)
131130

132131
merged_root_paths = preprocess_build_overrides(

tools/deployment-cli-tools/tests/test_preprocessing.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import copy
12
import shutil
23
import os
4+
import tempfile
35

46
from ch_cli_tools.helm import *
57
from ch_cli_tools.preprocessing import *
@@ -72,3 +74,58 @@ def test_generate_hash_based_image_tags_uses_merged_content():
7274
assert image_before != image_after
7375

7476
shutil.rmtree(MERGE_BUILD_DIR)
77+
78+
79+
def test_task_file_changes_trigger_different_tag():
80+
"""Modifying a file under applications/*/tasks/*/* must produce a different
81+
hash-based tag for the corresponding task image."""
82+
83+
values = create_helm_chart(
84+
[CLOUDHARNESS_ROOT], output_path=OUT, include=['workflows'],
85+
domain="my.local", namespace='test', env='dev', local=False,
86+
tag=None, registry='reg',
87+
)
88+
89+
# Pick a task image that lives under applications/workflows/tasks/
90+
task_key = 'workflows-notify-queue'
91+
assert task_key in values[KEY_TASK_IMAGES], (
92+
f"Expected '{task_key}' in task-images; got {list(values[KEY_TASK_IMAGES].keys())}"
93+
)
94+
95+
# --- first run: compute tags on the original tree ---
96+
preprocess_build_overrides(
97+
root_paths=[CLOUDHARNESS_ROOT], helm_values=values,
98+
merge_build_path=MERGE_BUILD_DIR,
99+
)
100+
values_before = copy.deepcopy(values)
101+
generate_hash_based_image_tags(
102+
root_paths=[CLOUDHARNESS_ROOT], helm_values=values_before,
103+
merge_build_path=MERGE_BUILD_DIR,
104+
)
105+
tag_before = values_before[KEY_TASK_IMAGES][task_key]
106+
107+
# --- mutate a task file and recompute ---
108+
task_dir = os.path.join(
109+
CLOUDHARNESS_ROOT, 'applications', 'workflows', 'tasks', 'notify-queue',
110+
)
111+
tmp_file = os.path.join(task_dir, '_tag_test_tmp_file')
112+
try:
113+
with open(tmp_file, 'w') as f:
114+
f.write('trigger-tag-change')
115+
116+
values_after = copy.deepcopy(values)
117+
generate_hash_based_image_tags(
118+
root_paths=[CLOUDHARNESS_ROOT], helm_values=values_after,
119+
merge_build_path=MERGE_BUILD_DIR,
120+
)
121+
tag_after = values_after[KEY_TASK_IMAGES][task_key]
122+
finally:
123+
if os.path.exists(tmp_file):
124+
os.remove(tmp_file)
125+
if os.path.exists(MERGE_BUILD_DIR):
126+
shutil.rmtree(MERGE_BUILD_DIR)
127+
128+
assert tag_before != tag_after, (
129+
f"Task image tag for '{task_key}' did not change after modifying task files. "
130+
f"Before: {tag_before}, After: {tag_after}"
131+
)

0 commit comments

Comments
 (0)