## Summary - Add `containers/nettest/default.nix` using `dockerTools.buildLayeredImage` with curl, jq, dnsutils, cacert, and bash — equivalent to the existing Dockerfile - Update `container-tag-and-release` to require `--nix` or `--dockerfile` flag when both build types exist for a container - Update `container-list` to show `[dockerfile+nix]` label when both exist ## Deployment and Testing - [ ] SSH to ringtail, run `nix build -f containers/nettest/default.nix -o result` to verify the nix expression builds - [ ] Tag `nettest-nix-v1.0.0`, confirm `build-container-nix` workflow runs on `nix-container-builder` runner and pushes to registry - [ ] Smoke test on ringtail k3s: `kubectl run nettest --image=registry.ops.eblu.me/blumeops/nettest:v1.0.0 --restart=Never && kubectl logs nettest` - [ ] Verify `mise run container-list` shows `[dockerfile+nix]` for nettest - [ ] Verify `mise run container-tag-and-release nettest v1.1.0` prompts for build type Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/214
114 lines
3.4 KiB
Text
Executable file
114 lines
3.4 KiB
Text
Executable file
#!/usr/bin/env -S uv run --script
|
|
# /// script
|
|
# requires-python = ">=3.12"
|
|
# dependencies = ["typer>=0.15.0"]
|
|
# ///
|
|
#MISE description="Release a container image by creating a git tag"
|
|
#USAGE arg "<container>" help="Container name (directory under containers/)"
|
|
#USAGE arg "<version>" help="Version in vX.Y.Z format"
|
|
#USAGE flag "--dry-run" help="Show what would be done without creating tags"
|
|
"""Release a container image by creating a git tag that triggers CI builds.
|
|
|
|
One tag triggers all applicable workflows:
|
|
- Dockerfile present -> Build Container workflow -> :v<version>
|
|
- default.nix present -> Build Container (Nix) workflow -> :v<version>-nix
|
|
"""
|
|
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import typer
|
|
|
|
REGISTRY = "registry.ops.eblu.me"
|
|
FORGE_ACTIONS = "https://forge.ops.eblu.me/eblume/blumeops/actions"
|
|
|
|
app = typer.Typer(add_completion=False)
|
|
|
|
|
|
def git(*args: str) -> str:
|
|
result = subprocess.run(
|
|
["git", *args], capture_output=True, text=True, check=True
|
|
)
|
|
return result.stdout.strip()
|
|
|
|
|
|
def git_tag_exists(tag: str) -> bool:
|
|
result = subprocess.run(
|
|
["git", "rev-parse", tag], capture_output=True, text=True
|
|
)
|
|
return result.returncode == 0
|
|
|
|
|
|
def list_containers() -> None:
|
|
typer.echo("Available containers:")
|
|
for d in sorted(Path("containers").iterdir()):
|
|
if not d.is_dir():
|
|
continue
|
|
types = []
|
|
if (d / "Dockerfile").exists():
|
|
types.append("dockerfile")
|
|
if (d / "default.nix").exists():
|
|
types.append("nix")
|
|
if types:
|
|
typer.echo(f" - {d.name} ({', '.join(types)})")
|
|
|
|
|
|
@app.command()
|
|
def main(
|
|
container: str = typer.Argument(help="Container name (directory under containers/)"),
|
|
version: str = typer.Argument(help="Version in vX.Y.Z format"),
|
|
dry_run: bool = typer.Option(False, "--dry-run", help="Show what would be done without creating tags"),
|
|
) -> None:
|
|
"""Release a container image by creating a git tag that triggers CI builds."""
|
|
if not re.match(r"^v\d+\.\d+\.\d+$", version):
|
|
typer.echo("Error: Version must be in format vX.Y.Z (e.g. v1.0.0)")
|
|
raise typer.Exit(1)
|
|
|
|
container_dir = Path("containers") / container
|
|
has_dockerfile = (container_dir / "Dockerfile").exists()
|
|
has_nix = (container_dir / "default.nix").exists()
|
|
|
|
if not has_dockerfile and not has_nix:
|
|
typer.echo(f"Error: No Dockerfile or default.nix found in '{container_dir}'")
|
|
typer.echo()
|
|
list_containers()
|
|
raise typer.Exit(1)
|
|
|
|
image = f"blumeops/{container}"
|
|
tag = f"{container}-{version}"
|
|
|
|
# Show what workflows will trigger
|
|
builds = []
|
|
if has_dockerfile:
|
|
builds.append(f" dockerfile -> {REGISTRY}/{image}:{version}")
|
|
if has_nix:
|
|
builds.append(f" nix -> {REGISTRY}/{image}:{version}-nix")
|
|
|
|
if dry_run:
|
|
typer.echo("[dry-run mode]")
|
|
typer.echo(f"Container: {container}")
|
|
typer.echo(f"Tag: {tag}")
|
|
typer.echo(f"Builds:")
|
|
for b in builds:
|
|
typer.echo(b)
|
|
typer.echo()
|
|
|
|
if git_tag_exists(tag):
|
|
typer.echo(f"Error: Tag '{tag}' already exists")
|
|
raise typer.Exit(1)
|
|
|
|
if dry_run:
|
|
typer.echo(f"[dry-run] Would create and push tag: {tag}")
|
|
else:
|
|
git("tag", tag)
|
|
git("push", "origin", tag)
|
|
typer.echo(f"Tag '{tag}' created and pushed")
|
|
|
|
typer.echo()
|
|
typer.echo(f"Monitor builds at: {FORGE_ACTIONS}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app()
|