Skip to content

Commit

Permalink
Fixed cache scope handling
Browse files Browse the repository at this point in the history
  • Loading branch information
max-pfeiffer committed Oct 10, 2023
1 parent 8e58b98 commit 0de0cc6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
1 change: 0 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
USE_LOCAL_CACHE_STORAGE_BACKEND=1
PYTHON_VERSION=3.12.0
OS_VARIANT=slim-bookworm
POETRY_VERSION=1.6.1
4 changes: 0 additions & 4 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 8 additions & 12 deletions build/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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}"

Expand Down
12 changes: 7 additions & 5 deletions tests/build_image/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down

0 comments on commit 0de0cc6

Please sign in to comment.