From c01c2880deccf12119ffda6455bfcf5082f26eb2 Mon Sep 17 00:00:00 2001 From: skovhus Date: Mon, 26 Oct 2020 08:23:50 +0100 Subject: [PATCH 1/3] Extend caching log line --- brick/dockerlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brick/dockerlib.py b/brick/dockerlib.py index dc97c7d..dcb775c 100644 --- a/brick/dockerlib.py +++ b/brick/dockerlib.py @@ -55,7 +55,7 @@ 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)) From 0a2ce9d8edc9076aaef55c19c2dfd4039b3ef415 Mon Sep 17 00:00:00 2001 From: skovhus Date: Mon, 26 Oct 2020 08:24:04 +0100 Subject: [PATCH 2/3] 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. --- brick/dockerlib.py | 10 ++++------ tests/test_brick.py | 3 --- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/brick/dockerlib.py b/brick/dockerlib.py index dcb775c..4f2fdd0 100644 --- a/brick/dockerlib.py +++ b/brick/dockerlib.py @@ -63,18 +63,16 @@ def docker_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 = set([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) diff --git a/tests/test_brick.py b/tests/test_brick.py index a39e208..3875dd4 100644 --- a/tests/test_brick.py +++ b/tests/test_brick.py @@ -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() From e82d5fc89360340fcc7e3b21c939d7775541e3cc Mon Sep 17 00:00:00 2001 From: skovhus Date: Tue, 27 Oct 2020 13:27:31 +0100 Subject: [PATCH 3/3] Fix linting issue --- brick/dockerlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brick/dockerlib.py b/brick/dockerlib.py index 4f2fdd0..c0f342f 100644 --- a/brick/dockerlib.py +++ b/brick/dockerlib.py @@ -64,7 +64,7 @@ def docker_build( return tag_to_return # Investigate if we can promote an image instead of building it again - image_names = set([t.split(":")[0] for t in tags]) + image_names = {t.split(":")[0] for t in tags} related_images_with_latest_tag = [ image for image in images_matching_hash