From 0de0cc69604a720e388454e1140630e78c7dfcb3 Mon Sep 17 00:00:00 2001 From: Max Pfeiffer Date: Tue, 10 Oct 2023 21:00:15 +0200 Subject: [PATCH] Fixed cache scope handling --- .env-example | 1 - .github/workflows/pipeline.yml | 4 ---- build/publish.py | 20 ++++++++------------ tests/build_image/conftest.py | 12 +++++++----- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/.env-example b/.env-example index bbdc052..483fc57 100644 --- a/.env-example +++ b/.env-example @@ -1,4 +1,3 @@ -USE_LOCAL_CACHE_STORAGE_BACKEND=1 PYTHON_VERSION=3.12.0 OS_VARIANT=slim-bookworm POETRY_VERSION=1.6.1 diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index f8cf603..9954bb0 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -143,11 +143,7 @@ jobs: uses: actions/download-artifact@v3 - name: Compile the relevant reports run: | - ls -sal find . -name "*.xml" -exec cp {} . \; - ls -sal - cat build_image_coverage_report.xml - cat publish_image_coverage_report.xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/build/publish.py b/build/publish.py index 6198cc2..3c10893 100644 --- a/build/publish.py +++ b/build/publish.py @@ -4,6 +4,7 @@ from build.utils import get_context, get_image_reference from pathlib import Path from python_on_whales import DockerClient, Builder +from os import getenv @click.command() @@ -41,12 +42,6 @@ @click.option( "--registry", envvar="REGISTRY", default="docker.io", help="Docker registry" ) -@click.option( - "--use-local-cache-storage-backend", - envvar="USE_LOCAL_CACHE_STORAGE_BACKEND", - is_flag=True, - help="Use local cache storage backend for docker builds", -) def main( docker_hub_username: str, docker_hub_password: str, @@ -55,19 +50,20 @@ def main( python_version: str, os_variant: str, registry: str, - use_local_cache_storage_backend: bool, ) -> None: + github_ref_name: str = getenv("GITHUB_REF_NAME") context: Path = get_context() - image_reference: str = get_image_reference( registry, version_tag, poetry_version, python_version, os_variant ) cache_scope: str = f"{poetry_version}-{python_version}-{os_variant}" - 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 use_local_cache_storage_backend: + if github_ref_name: + 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}" + else: cache_to = f"type=local,mode=max,dest=/tmp,scope={cache_scope}" cache_from = f"type=local,src=/tmp,scope={cache_scope}" diff --git a/tests/build_image/conftest.py b/tests/build_image/conftest.py index 08057e3..01a0942 100644 --- a/tests/build_image/conftest.py +++ b/tests/build_image/conftest.py @@ -37,20 +37,22 @@ def image_reference( password=REGISTRY_PASSWORD, ) registry: str = registry_container.get_registry() - python_version: str = getenv("PYTHON_VERSION") os_variant: str = getenv("OS_VARIANT") poetry_version: str = getenv("POETRY_VERSION") + github_ref_name: str = getenv("GITHUB_REF_NAME") image_reference: str = get_image_reference( registry, image_version, poetry_version, python_version, os_variant ) cache_scope: str = f"{poetry_version}-{python_version}-{os_variant}" - 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"): + if github_ref_name: + 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}" + else: cache_to = f"type=local,mode=max,dest=/tmp,scope={cache_scope}" cache_from = f"type=local,src=/tmp,scope={cache_scope}"