From aa5c06b3ccbb9cd47bde0d6506f0fe4bc8fbd755 Mon Sep 17 00:00:00 2001 From: Max Pfeiffer Date: Sat, 23 Sep 2023 11:00:14 +0200 Subject: [PATCH] Trying to fix GitHub workflow error, trying to leverage build cache --- .github/workflows/pipeline.yml | 2 ++ tests/build_image/conftest.py | 15 +++++++++------ tests/build_image/test_build_version.py | 5 ++--- tests/conftest.py | 13 +++++++++++++ tests/constants.py | 12 ------------ tests/publish_image/test_cli.py | 8 +++++--- tests/publish_image/test_env.py | 8 +++++--- 7 files changed, 36 insertions(+), 27 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 499afac..335420c 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -37,6 +37,7 @@ jobs: needs: code-quality runs-on: ubuntu-20.04 strategy: + fail-fast: false matrix: python_version: ["3.9.18", "3.10.13", "3.11.5"] os_variant: ["bookworm", "slim-bookworm"] @@ -83,6 +84,7 @@ jobs: needs: code-quality runs-on: ubuntu-20.04 strategy: + fail-fast: false matrix: python_version: ["3.11.5"] os_variant: ["slim-bookworm"] diff --git a/tests/build_image/conftest.py b/tests/build_image/conftest.py index e701746..46e1ee8 100644 --- a/tests/build_image/conftest.py +++ b/tests/build_image/conftest.py @@ -6,7 +6,6 @@ CONTEXT, REGISTRY_PASSWORD, REGISTRY_USERNAME, - VERSION, ) from tests.registry_container import DockerRegistryContainer from os import getenv @@ -30,6 +29,7 @@ def registry_container() -> DockerRegistryContainer: def image_reference( docker_client: DockerClient, pow_buildx_builder: Builder, + image_version: str, registry_container: DockerRegistryContainer, ): docker_client.login( @@ -43,15 +43,18 @@ def image_reference( os_variant: str = getenv("OS_VARIANT") poetry_version: str = getenv("POETRY_VERSION") - tag: str = f"{registry}/pfeiffermax/python-poetry:{VERSION}-poetry{poetry_version}-python{python_version}-{os_variant}" + tag: str = f"{registry}/pfeiffermax/python-poetry:{image_version}-poetry{poetry_version}-python{python_version}-{os_variant}" + cache_scope: str = ( + f"{image_version}-{poetry_version}-{python_version}-{os_variant}" + ) platforms: list[str] = ["linux/amd64", "linux/arm64/v8"] - cache_to: str = "type=gha,mode=max" - cache_from: str = "type=gha" + cache_to: str = f"type=gha,mode=max,scope=$GITHUB_REF_NAME-{cache_scope}" + cache_from: str = f"type=gha,scope=$GITHUB_REF_NAME-{cache_scope}" if getenv("USE_LOCAL_CACHE_STORAGE_BACKEND"): - cache_to = "type=local,mode=max,dest=/tmp" - cache_from = "type=local,src=/tmp" + cache_to = f"type=local,mode=max,dest=/tmp,scope={cache_scope}" + cache_from = f"type=local,src=/tmp,scope={cache_scope}" docker_client.buildx.build( context_path=CONTEXT, diff --git a/tests/build_image/test_build_version.py b/tests/build_image/test_build_version.py index eb5968a..7d9651a 100644 --- a/tests/build_image/test_build_version.py +++ b/tests/build_image/test_build_version.py @@ -1,9 +1,8 @@ -from tests.constants import VERSION from tests.utils import ImageTagComponents -def test_build_version(image_reference) -> None: +def test_build_version(image_reference: str, image_version: str) -> None: components: ImageTagComponents = ImageTagComponents.create_from_reference( image_reference ) - assert components.version == VERSION + assert components.version == image_version diff --git a/tests/conftest.py b/tests/conftest.py index d54bca2..65ed777 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,8 @@ import pytest from python_on_whales import DockerClient, Builder +from random import randrange + +from semver import VersionInfo @pytest.fixture(scope="session") @@ -15,3 +18,13 @@ def pow_buildx_builder(docker_client: DockerClient) -> Builder: yield builder docker_client.buildx.stop(builder) docker_client.buildx.remove(builder) + + +@pytest.fixture(scope="session") +def image_version() -> str: + image_version: str = str( + VersionInfo( + major=randrange(100), minor=randrange(100), patch=randrange(100) + ) + ) + return image_version diff --git a/tests/constants.py b/tests/constants.py index 25c7ae2..8744ec5 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -1,21 +1,9 @@ from pathlib import Path -from random import randrange - -from semver import VersionInfo from build.utils import get_context, get_docker_bake_file -from tests.utils import generate_image_references SLEEP_TIME: float = 3.0 REGISTRY_USERNAME: str = "foo" REGISTRY_PASSWORD: str = "bar" -VERSION: str = str( - VersionInfo( - major=randrange(100), minor=randrange(100), patch=randrange(100) - ) -) BAKE_FILE: Path = get_docker_bake_file() CONTEXT: Path = get_context() -IMAGE_REFERENCES: list[str] = generate_image_references( - BAKE_FILE, CONTEXT, VERSION -) diff --git a/tests/publish_image/test_cli.py b/tests/publish_image/test_cli.py index a54c1e7..886146f 100644 --- a/tests/publish_image/test_cli.py +++ b/tests/publish_image/test_cli.py @@ -2,11 +2,12 @@ from python_on_whales import DockerException from build.publish import main -from tests.constants import REGISTRY_PASSWORD, REGISTRY_USERNAME, VERSION +from tests.constants import REGISTRY_PASSWORD, REGISTRY_USERNAME from tests.registry_container import DockerRegistryContainer def test_registry_with_credentials( + image_version: str, cli_runner: CliRunner, python_version: str, os_variant: str, @@ -23,7 +24,7 @@ def test_registry_with_credentials( "--docker-hub-password", REGISTRY_PASSWORD, "--version-tag", - VERSION, + image_version, "--python-version", python_version, "--os-variant", @@ -38,6 +39,7 @@ def test_registry_with_credentials( def test_registry_with_wrong_credentials( + image_version: str, cli_runner: CliRunner, python_version: str, os_variant: str, @@ -54,7 +56,7 @@ def test_registry_with_wrong_credentials( "--docker-hub-password", "boom", "--version-tag", - VERSION, + image_version, "--python-version", python_version, "--os-variant", diff --git a/tests/publish_image/test_env.py b/tests/publish_image/test_env.py index 8d975cd..086f32e 100644 --- a/tests/publish_image/test_env.py +++ b/tests/publish_image/test_env.py @@ -2,11 +2,12 @@ from python_on_whales import DockerException from build.publish import main -from tests.constants import REGISTRY_PASSWORD, REGISTRY_USERNAME, VERSION +from tests.constants import REGISTRY_PASSWORD, REGISTRY_USERNAME from tests.registry_container import DockerRegistryContainer def test_registry_with_credentials( + image_version: str, cli_runner: CliRunner, python_version: str, os_variant: str, @@ -20,7 +21,7 @@ def test_registry_with_credentials( env={ "DOCKER_HUB_USERNAME": REGISTRY_USERNAME, "DOCKER_HUB_PASSWORD": REGISTRY_PASSWORD, - "GIT_TAG_NAME": VERSION, + "GIT_TAG_NAME": image_version, "PYTHON_VERSION": python_version, "OS_VARIANT": os_variant, "POETRY_VERSION": poetry_version, @@ -31,6 +32,7 @@ def test_registry_with_credentials( def test_registry_with_wrong_credentials( + image_version: str, cli_runner: CliRunner, python_version: str, os_variant: str, @@ -44,7 +46,7 @@ def test_registry_with_wrong_credentials( env={ "DOCKER_HUB_USERNAME": "boom", "DOCKER_HUB_PASSWORD": "bang", - "GIT_TAG_NAME": VERSION, + "GIT_TAG_NAME": image_version, "PYTHON_VERSION": python_version, "OS_VARIANT": os_variant, "POETRY_VERSION": poetry_version,