Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Fix promotion not working when using a build tag (#70)
Browse files Browse the repository at this point in the history
* Extend caching log line

* Extend the search for images to promote

Instead of reying on the last tag in the list, we should consider all repositories.

This solves an issue where the last tag in the list was actually another repository (due to the build.tag option in the BUILD.yml file), and we thereby lost the promotion cache.

* Fix linting issue
  • Loading branch information
skovhus authored Oct 27, 2020
1 parent 94e7aef commit bbd6c3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
12 changes: 5 additions & 7 deletions brick/dockerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,24 @@ def docker_build(
dockerfile_contents += f'\nLABEL brick.dependency_hash="{dependency_hash}"'
images_matching_hash = get_image_names_with_dependency_hash(dependency_hash)
logger.debug(
f"Found {len(images_matching_hash)} image(s) matching dependency hash ({images_matching_hash[0:2]}..)"
f"Found {len(images_matching_hash)} image(s) matching dependency hash {dependency_hash} ({images_matching_hash[0:5]}..)"
)

images_are_build = set(tags).issubset(set(images_matching_hash))
if images_are_build:
logger.debug(f"Skipping docker build as images are up to date with input dependencies")
return tag_to_return

# Investigate if we can promote images instead of building them again
image_name = tag_to_return.split(":")[0]
# Investigate if we can promote an image instead of building it again
image_names = {t.split(":")[0] for t in tags}
related_images_with_latest_tag = [
image
for image in images_matching_hash
if image.split(":")[0] == image_name and image.endswith(":latest")
if image.split(":")[0] in image_names and image.endswith(":latest")
]

if related_images_with_latest_tag:
# Note that we could probably allow branch images to be used for promotion.
assert (
len(related_images_with_latest_tag) == 1
), f"Expected one related image, but found {related_images_with_latest_tag}"
image_with_latest_tag = related_images_with_latest_tag[0]
logger.debug(f"Promoting image {image_with_latest_tag}")
tag_image(image_name=image_with_latest_tag, tags=tags)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_brick.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ def test_examples_node_build_2_on_master(caplog, monkeypatch) -> None:
assert get_docker_images_built_from_debug_logs(debug_logs) == set([]) # nothing was built


@pytest.mark.skip(
reason="promoting images actually doesn't work as intended when using a build tag"
)
def test_examples_node_build_3_on_feature_branch(caplog, monkeypatch) -> None:
# NOTE: test depends on test_examples_node_build_1_on_master
clean_up_output_folders()
Expand Down

0 comments on commit bbd6c3f

Please sign in to comment.