Skip to content

Commit

Permalink
Trying to fix GitHub workflow error, trying to leverage build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
max-pfeiffer committed Sep 23, 2023
1 parent 9dc7251 commit aa5c06b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down
15 changes: 9 additions & 6 deletions tests/build_image/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
CONTEXT,
REGISTRY_PASSWORD,
REGISTRY_USERNAME,
VERSION,
)
from tests.registry_container import DockerRegistryContainer
from os import getenv
Expand All @@ -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(
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions tests/build_image/test_build_version.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
12 changes: 0 additions & 12 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 5 additions & 3 deletions tests/publish_image/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions tests/publish_image/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit aa5c06b

Please sign in to comment.