Skip to content

Commit

Permalink
Added example for env file, removed more clutter
Browse files Browse the repository at this point in the history
  • Loading branch information
max-pfeiffer committed Sep 23, 2023
1 parent f2ef1c6 commit 7f401d1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USE_LOCAL_CACHE_STORAGE_BACKEND=1
PYTHON_VERSION=3.9.18
OS_VARIANT=slim-bookworm
POETRY_VERSION=1.6.1
8 changes: 5 additions & 3 deletions build/publish.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from build.utils import get_context
from build.utils import get_context, get_image_reference
from pathlib import Path
from python_on_whales import DockerClient, Builder

Expand Down Expand Up @@ -58,7 +58,9 @@ def main(
) -> None:
context: Path = get_context()

tag: str = f"{registry}/pfeiffermax/python-poetry:{version_tag}-poetry{poetry_version}-python{python_version}-{os_variant}"
image_reference: str = get_image_reference(
registry, version_tag, poetry_version, python_version, os_variant
)

platforms: list[str] = ["linux/amd64", "linux/arm64/v8"]
cache_to: str = "type=gha,mode=max"
Expand Down Expand Up @@ -86,7 +88,7 @@ def main(
"POETRY_VERSION": poetry_version,
"OFFICIAL_PYTHON_IMAGE": f"python:{python_version}-{os_variant}",
},
tags=tag,
tags=image_reference,
platforms=platforms,
builder=builder,
cache_to=cache_to,
Expand Down
12 changes: 9 additions & 3 deletions build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def get_context() -> Path:
return Path(__file__).parent.resolve()


def get_docker_bake_file() -> Path:
docker_bake_file: Path = Path(__file__).parent.resolve() / "docker-bake.hcl"
return docker_bake_file
def get_image_reference(
registry: str,
image_version: str,
poetry_version: str,
python_version: str,
os_variant: str,
) -> str:
reference: str = f"{registry}/pfeiffermax/python-poetry:{image_version}-poetry{poetry_version}-python{python_version}-{os_variant}"
return reference
9 changes: 6 additions & 3 deletions tests/build_image/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from time import sleep
import pytest
from python_on_whales import Builder, DockerClient
from build.utils import get_image_reference

from tests.constants import (
CONTEXT,
Expand Down Expand Up @@ -43,7 +44,9 @@ def image_reference(
os_variant: str = getenv("OS_VARIANT")
poetry_version: str = getenv("POETRY_VERSION")

tag: str = f"{registry}/pfeiffermax/python-poetry:{image_version}-poetry{poetry_version}-python{python_version}-{os_variant}"
image_reference: str = get_image_reference(
registry, image_version, poetry_version, python_version, os_variant
)
cache_scope: str = (
f"{image_version}-{poetry_version}-{python_version}-{os_variant}"
)
Expand All @@ -63,11 +66,11 @@ def image_reference(
"POETRY_VERSION": poetry_version,
"OFFICIAL_PYTHON_IMAGE": f"python:{python_version}-{os_variant}",
},
tags=tag,
tags=image_reference,
platforms=platforms,
builder=pow_buildx_builder,
cache_to=cache_to,
cache_from=cache_from,
push=True,
)
yield tag
yield image_reference
3 changes: 1 addition & 2 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pathlib import Path

from build.utils import get_context, get_docker_bake_file
from build.utils import get_context

SLEEP_TIME: float = 3.0
REGISTRY_USERNAME: str = "foo"
REGISTRY_PASSWORD: str = "bar"
BAKE_FILE: Path = get_docker_bake_file()
CONTEXT: Path = get_context()

0 comments on commit 7f401d1

Please sign in to comment.