Skip to content

Commit bbc08ec

Browse files
committed
CH-235 ensure that static images tags are processed only once
1 parent 0d8e087 commit bbc08ec

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def _init_static_images(self, base_image_name):
158158

159159
img_name = image_name_from_dockerfile_path(os.path.basename(
160160
static_img_dockerfile), base_name=base_name)
161+
# Static images have context where the Dockerfile is located
161162
self.base_images[os.path.basename(static_img_dockerfile)] = self.image_tag(
162163
img_name, build_context_path=static_img_dockerfile,
163164
dependencies=guess_build_dependencies_from_dockerfile(static_img_dockerfile)
@@ -183,13 +184,15 @@ def _assign_static_build_dependencies(self, helm_values):
183184
# del helm_values[KEY_TASK_IMAGES_BUILD][image_name]
184185

185186
def _init_base_images(self, base_image_name):
187+
"""Initialize base images (infrastructure/base-images/) with root context."""
186188
for i in range(len(self.root_paths)):
187189
root_path = self.root_paths[i]
188190
base_name = base_image_name
189191

190-
for base_img_dockerfile in self.__find_static_dockerfile_paths(root_path):
192+
for base_img_dockerfile in find_dockerfiles_paths(os.path.join(root_path, BASE_IMAGES_PATH)):
191193
img_name = image_name_from_dockerfile_path(
192194
os.path.basename(base_img_dockerfile), base_name=base_name)
195+
# Base images have context at root
193196
self.base_images[os.path.basename(base_img_dockerfile)] = self.image_tag(
194197
img_name, build_context_path=root_path,
195198
dependencies=guess_build_dependencies_from_dockerfile(base_img_dockerfile)
@@ -211,9 +214,6 @@ def _init_test_images(self, base_image_name):
211214

212215
return test_images
213216

214-
def __find_static_dockerfile_paths(self, root_path):
215-
return find_dockerfiles_paths(os.path.join(root_path, BASE_IMAGES_PATH)) + find_dockerfiles_paths(os.path.join(root_path, STATIC_IMAGES_PATH))
216-
217217
def _merge_base_helm_values(self, helm_values):
218218
# Override for every cloudharness scaffolding
219219
for root_path in self.root_paths:
@@ -328,9 +328,17 @@ def image_tag(self, image_name, build_context_path=None, dependencies=()):
328328
logging.info(f"Ignoring {ignore}")
329329
tag = generate_tag_from_content(build_context_path, ignore)
330330
logging.info(f"Content hash: {tag}")
331+
332+
# Get dependencies from build context if not provided
331333
dependencies = dependencies or guess_build_dependencies_from_dockerfile(build_context_path)
332-
tag = sha1((tag + "".join(self.all_images.get(n, '') for n in dependencies)).encode("utf-8")).hexdigest()
333-
logging.info(f"Generated tag: {tag}")
334+
335+
# Combine with dependency tags
336+
dep_tags = "".join(self.all_images.get(n, '') for n in dependencies)
337+
if dep_tags:
338+
logging.info(f"Dependency tags: {[(n, self.all_images.get(n, '')) for n in dependencies]}")
339+
tag = sha1((tag + dep_tags).encode("utf-8")).hexdigest()
340+
logging.info(f"Generated tag (with dependencies): {tag}")
341+
334342
app_name = image_name.split("/")[-1] # the image name can have a prefix
335343
self.all_images[app_name] = tag
336344
return self.registry + image_name + (f':{tag}' if tag else '')

0 commit comments

Comments
 (0)