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

Handle cases where multi-platform images are retagged in a mp step #116

Merged
merged 1 commit into from
Jan 30, 2024
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
7 changes: 6 additions & 1 deletion buildrunner/validation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,12 @@ def validate_multiplatform_are_not_retagged():
# Iterate through each step images and check for multi-platform re-tagging
retagged_images = []
for step_name, step_images_info in step_images.items():
if not step_images_info.dest_images:
if (
# Ignore steps that do not push images
not step_images_info.dest_images
# Ignore steps that are also multi-platform, as re-tagging will work in this case
or step_images_info.is_multi_platform
):
continue

other_steps_images_infos = [
Expand Down
71 changes: 49 additions & 22 deletions tests/test_config_validation/test_retagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,57 @@ def test_reusing_multi_platform_images():
assert errors is None


@pytest.mark.parametrize(
"config_yaml",
[
# Tests that "BUILDRUNNER_BUILD_DOCKER_TAG" is replaced with id_string-build_number
"""
steps:
build-container-multi-platform:
build:
dockerfile: |
FROM {{ DOCKER_REGISTRY }}/busybox
platforms:
- linux/amd64
- linux/arm64/v8
push:
- repository: user1/buildrunner-test-multi-platform
tags: [ 'latest', '0.0.1', {{ BUILDRUNNER_BUILD_DOCKER_TAG }} ]

use-built-image1:
run:
image: user1/buildrunner-test-multi-platform
cmd: echo "Hello World"
""",
"""
steps:
build-container-multi-platform:
build:
dockerfile: |
FROM {{ DOCKER_REGISTRY }}/busybox
platforms:
- linux/amd64
- linux/arm64/v8
push:
- repository: user1/buildrunner-test-multi-platform
tags: [ 'latest', '0.0.1', {{ BUILDRUNNER_BUILD_DOCKER_TAG }} ]

use-built-image1:
build:
dockerfile: |
FROM user1/buildrunner-test-multi-platform:latest
platforms:
- linux/amd64
- linux/arm64/v8
push:
repository: user1/buildrunner-test-multi-platform2
tags: [ 'latest' ]
""",
],
)
@mock.patch("buildrunner.config.DEFAULT_GLOBAL_CONFIG_FILES", [])
@mock.patch("buildrunner.detect_vcs")
def test_valid_config_with_buildrunner_build_tag(detect_vcs_mock):
# Tests that "BUILDRUNNER_BUILD_DOCKER_TAG" is replaced with id_string-build_number

config_yaml = """
steps:
build-container-multi-platform:
build:
dockerfile: |
FROM {{ DOCKER_REGISTRY }}/busybox
platforms:
- linux/amd64
- linux/arm64/v8
push:
- repository: user1/buildrunner-test-multi-platform
tags: [ 'latest', '0.0.1', {{ BUILDRUNNER_BUILD_DOCKER_TAG }} ]

use-built-image1:
run:
image: user1/buildrunner-test-multi-platform
cmd: echo "Hello World"
"""

def test_valid_config_with_buildrunner_build_tag(detect_vcs_mock, config_yaml):
id_string = "main-921.ie02ed8.m1705616822"
build_number = 342
type(detect_vcs_mock.return_value).id_string = mock.PropertyMock(
Expand Down
Loading