"""Docker image commands.""" import os import subprocess import typer from cli_tools.helpers import run app = typer.Typer(help="Build and manage Docker images.", no_args_is_help=True) DOCKER_IMAGE = "python-dev" DOCKER_DIR = "docker/python-dev" DOCKERHUB_IMAGE = "roxauto/python-dev" @app.command() def build( tag: str = typer.Option("latest", help="Image tag."), no_cache: bool = typer.Option(False, "--no-cache", help="Build without cache."), ): """Build the python-dev Docker image locally.""" uid = os.getuid() gid = os.getgid() full_tag = f"{DOCKER_IMAGE}:{tag}" run(f"cp ai-tools/claude/CLAUDE.md {DOCKER_DIR}/CLAUDE.md") run(f"cp scripts/aliases.sh {DOCKER_DIR}/aliases.sh") run(f"cp scripts/bash_helpers.sh {DOCKER_DIR}/bash_helpers.sh") run( f"docker build -t {full_tag} " f"--build-arg UID={uid} --build-arg GID={gid} " f"{'--no-cache ' if no_cache else ''}" f"--network=host {DOCKER_DIR}", ) @app.command() def push(tag: str = typer.Option("latest", help="Image tag.")): """Tag and push the python-dev image to DockerHub.""" token = os.environ.get("DOCKERHUB_TOKEN") if not token: typer.echo("DOCKERHUB_TOKEN env variable is not set.", err=True) raise typer.Exit(1) subprocess.run( ["docker", "login", "-u", "roxauto", "--password-stdin"], input=token, text=True, check=True, ) run(f"docker tag {DOCKER_IMAGE}:{tag} {DOCKERHUB_IMAGE}:{tag}") run(f"docker push {DOCKERHUB_IMAGE}:{tag}")