Repository navigation
build: reuse built wheel in container image and publish image every main build #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amimas
wants to merge
15
commits into
main
Choose a base branch
from
refactor-container-build-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+306
−73
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e80ccb5
build: consume pre-built package in docker image build
amimas c2a0018
build(docker): align build and release pipeline with GHCR promotion flow
amimas e05c758
docs: document docker build and release flow
amimas 15f32fc
fix: docker buildx does not support --image parameter
amimas 8959e46
build: add --tag and debug log for docker build command
amimas e0e9d11
build: add uv dependency install step for docker jobs
amimas d20fceb
build: set image name and tag as environment var in workflow
amimas d4183cf
ci: fix uv run command in build workflow
amimas ed6b9dc
ci: fix uv run command in smoke test
amimas 3e0da0f
ci(release): use IMAGE_BASE for release image promotion
amimas 280b7fb
fix(ci): release image tag promotion for major/minor aliases
amimas 6045adb
build: remove duplicate step of re-tagging latest
amimas f199a74
ci: drop unused package permission and keep main alias on GHCR
amimas ddf335f
docs(dev): fix default text for docker command
amimas e1f2c26
fix(dev): stop duplicating Docker image name on push
amimas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,76 @@ | ||
| """Tasks related to building and verifying Docker images.""" | ||
|
|
||
| import argparse | ||
| from pathlib import Path | ||
|
|
||
| from dev.common import REPO_ROOT, logger, run_command, get_executable | ||
| from dev.release import publish_docker | ||
|
|
||
|
|
||
| def build(extra_args: list[str] | None = None): | ||
| """Builds the GitLabForm Docker image. | ||
| """Builds the GitLabForm Docker image from a prebuilt wheel in dist/. | ||
|
|
||
| The Dockerfile installs the packaged wheel rather than building from the source tree, | ||
| so the local prerequisite is always: `uv run package build` before `uv run docker build`. | ||
|
|
||
| Local development usually builds for the host architecture only (for example, `docker buildx build` | ||
| with no explicit `--platform` override). CI uses the same toolkit commands but passes explicit | ||
| `--platform` values for multi-arch validation; the reusable build workflow validates each target | ||
| architecture without pushing registry credentials. This keeps the CLI surface consistent across | ||
| local development and GitHub Actions while the actual GHCR publication remains in the release | ||
| workflow. | ||
|
|
||
| Args: | ||
| extra_args: Arguments for the docker build command (e.g., --image, --tag, --push). | ||
| extra_args: Arguments for the docker build command (e.g., --tag, --push, --output). | ||
| """ | ||
| parser = argparse.ArgumentParser(add_help=False) | ||
| parser.add_argument("--image", default="localhost/gitlabform") | ||
| parser.add_argument("--tag", default="latest") | ||
| parser.add_argument("--tag", default="localhost/gitlabform:latest") | ||
| parser.add_argument("--push", action="store_true", help="Automatically push after build") | ||
| parser.add_argument( | ||
| "--output", help="Write the built image to an archive file (for example: type=docker,dest=/tmp/image.tar)" | ||
| ) | ||
|
|
||
| parsed, remaining = parser.parse_known_args(extra_args or []) | ||
| image_name = f"{parsed.image}:{parsed.tag}" | ||
| # image_name = f"{parsed.tag}" | ||
|
|
||
| # TODO: Add a check here if the Dockerfile is ever updated to require | ||
| # pre-built wheels from the 'dist/' directory. | ||
| # Ensure the Docker build has access to the prebuilt wheel artifact. | ||
| dist_dir = REPO_ROOT / "dist" | ||
| if not dist_dir.exists() or not any(dist_dir.glob("*.whl")): | ||
| logger.error("No Python wheel found in dist/. Run `uv run package build` before building the Docker image.") | ||
| raise SystemExit(1) | ||
|
|
||
| docker_bin = get_executable("docker") | ||
| # Note: REPO_ROOT is the context, so the Dockerfile can access dist/ if needed. | ||
| build_cmd = [docker_bin, "build", "--pull", "-t", image_name] + remaining + [str(REPO_ROOT)] | ||
| build_cmd = [docker_bin, "buildx", "build", "--pull", "-t", parsed.tag] | ||
| if parsed.output: | ||
| build_cmd.extend(["--output", parsed.output]) | ||
| build_cmd.extend(remaining) | ||
| build_cmd.append(str(REPO_ROOT)) | ||
|
|
||
| run_command(build_cmd, f"Building Docker image: [bold cyan]{image_name}[/bold cyan]") | ||
| # Log the exact docker command we are going to run. | ||
| logger.info(f"[bold blue]==>[/bold blue] Executing: {build_cmd}") | ||
| run_command(build_cmd, f"Building Docker image: [bold cyan]{parsed.tag}[/bold cyan]") | ||
|
|
||
| if parsed.push: | ||
| # Delegate to the release domain to ensure consistent push logic | ||
| publish_docker([f"--image={parsed.image}", f"--tag={parsed.tag}"]) | ||
| publish_docker([f"--tag={parsed.tag}"]) | ||
|
rickbrouwer marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def verify(extra_args: list[str] | None = None): | ||
| """Verifies the built Docker image with a smoke test.""" | ||
| parser = argparse.ArgumentParser(add_help=False) | ||
| parser.add_argument("--image", default="localhost/gitlabform") | ||
| parser.add_argument("--tag", default="latest") | ||
| parser.add_argument("--tag", default="localhost/gitlabform:latest") | ||
| parser.add_argument("--input", help="Load a Docker image archive from disk before verifying it") | ||
|
|
||
| parsed, remaining = parser.parse_known_args(extra_args or []) | ||
| image_name = f"{parsed.image}:{parsed.tag}" | ||
|
|
||
| docker_bin = get_executable("docker") | ||
| cmd = [docker_bin, "run", "--rm"] + remaining + [image_name, "gitlabform", "--version"] | ||
| run_command(cmd, f"Verifying Docker image: [bold cyan]{image_name}[/bold cyan]") | ||
| if parsed.input: | ||
| archive = Path(parsed.input).expanduser() | ||
| if not archive.exists(): | ||
| logger.error(f"Docker archive not found: {archive}") | ||
| raise SystemExit(1) | ||
| load_cmd = [docker_bin, "load", "--input", str(archive)] | ||
| run_command(load_cmd, f"Loading Docker image archive: [bold cyan]{archive}[/bold cyan]") | ||
|
|
||
| cmd = [docker_bin, "run", "--rm"] + remaining + [parsed.tag, "gitlabform", "--version"] | ||
| run_command(cmd, f"Verifying Docker image: [bold cyan]{parsed.tag}[/bold cyan]") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.