Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional tag to merged manifest list [CLOUDDST-25217] #280

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pubtools/_quay/container_image_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_internal_container_repo_name,
log_step,
run_with_retries,
timestamp,
)
from .quay_client import QuayClient
from .tag_images import tag_images
Expand Down Expand Up @@ -216,6 +217,14 @@ def run_merge_workflow(self, source_ref: str, dest_refs: List[str]) -> None:
merger.set_quay_clients(self.src_quay_client, self.dest_quay_client)
merger.merge_manifest_lists()

# add additional tag to merged manifest lists so that they won't be garbage collected
dest_repos = []
for ref in dest_refs:
repo = ref.split(":")[0]
if repo not in dest_repos:
dest_repos.append(repo)
self.run_tag_images(ref, [f"{ref}-{timestamp()}"], True, self.target_settings)

def copy_multiarch_push_item(self, push_item: Any, source_ml: ManifestList) -> None:
"""
Evaluate the correct tagging and manifest list merging strategy of multiarch push item.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_container_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,22 @@ def test_copy_v1_item(
)


@mock.patch("pubtools._quay.container_image_pusher.timestamp")
@mock.patch("pubtools._quay.container_image_pusher.ManifestListMerger")
@mock.patch("pubtools._quay.container_image_pusher.tag_images")
@mock.patch("pubtools._quay.container_image_pusher.QuayClient")
def test_merge_workflow(
mock_quay_client,
mock_tag_images,
mock_ml_merger,
mock_timestamp,
target_settings,
container_multiarch_push_item,
):
mock_get_manifest = mock.MagicMock()
mock_get_manifest.return_value = {"manifests": [{"digest": "digest1"}, {"digest": "digest2"}]}
mock_quay_client.return_value.get_manifest = mock_get_manifest
mock_timestamp.return_value = "timestamp"

pusher = container_image_pusher.ContainerImagePusher(
[container_multiarch_push_item], target_settings
Expand All @@ -212,6 +215,10 @@ def test_merge_workflow(
"registry/dest1/image@digest2",
"registry/dest2/image@digest2",
]
assert mock_tag_images.call_args_list[2][0][0] == "registry/dest1/image:1"
assert mock_tag_images.call_args_list[2][0][1] == ["registry/dest1/image:1-timestamp"]
assert mock_tag_images.call_args_list[3][0][0] == "registry/dest2/image:2"
assert mock_tag_images.call_args_list[3][0][1] == ["registry/dest2/image:2-timestamp"]

assert mock_ml_merger.call_args_list == [
mock.call("registry/src/image:1", "registry/dest1/image:1", host="quay.io"),
Expand Down
Loading