|
| 1 | +"""``bp deploy`` — generate deployment artifacts. |
| 2 | +
|
| 3 | +Today this is just a wrapper around the in-tree ``deploy`` feature. |
| 4 | +Other deploy-adjacent commands (``bp deploy nginx-tls``, ``bp deploy |
| 5 | +github-actions``) can mount here as siblings. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from enum import StrEnum |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +import typer |
| 14 | + |
| 15 | +from ..features.installer import FeatureInstaller |
| 16 | +from ..features.registry import get_feature |
| 17 | +from ..lib.project import discover_project |
| 18 | +from ..lib.prompts import error, info |
| 19 | + |
| 20 | +app = typer.Typer(no_args_is_help=True, help="Generate deployment artifacts.") |
| 21 | + |
| 22 | + |
| 23 | +class DeployMode(StrEnum): |
| 24 | + local = "local" |
| 25 | + prod = "prod" |
| 26 | + nginx = "nginx" |
| 27 | + |
| 28 | + |
| 29 | +@app.command("generate") |
| 30 | +def generate( |
| 31 | + mode: DeployMode = typer.Argument( |
| 32 | + ..., |
| 33 | + help="Deployment mode to generate. Pick `local` for hot-reload dev, `prod` for " |
| 34 | + "single-host production, `nginx` for production behind a reverse proxy.", |
| 35 | + ), |
| 36 | + output_dir: Path = typer.Option( |
| 37 | + None, |
| 38 | + "--output-dir", |
| 39 | + "-o", |
| 40 | + help="Where to write the compose file. Defaults to the repo root.", |
| 41 | + ), |
| 42 | + api_port: int = typer.Option(8000, "--api-port", help="Host port to publish the API on."), |
| 43 | + workers: int = typer.Option(4, "--workers", help="Number of API workers (prod / nginx only)."), |
| 44 | + force: bool = typer.Option(False, "--force", "-f", help="Overwrite existing files without asking."), |
| 45 | + yes: bool = typer.Option(False, "--yes", "-y", help="Assume yes for all prompts."), |
| 46 | + dry_run: bool = typer.Option(False, "--dry-run", help="Show what would be written, don't touch disk."), |
| 47 | +) -> None: |
| 48 | + """Generate ``docker-compose.yml`` (and ``nginx/default.conf`` for nginx mode).""" |
| 49 | + project = discover_project(output_dir) |
| 50 | + feature = get_feature("deploy") |
| 51 | + if feature is None: # pragma: no cover — built-in feature, always present |
| 52 | + error("deploy feature is not registered.") |
| 53 | + raise typer.Exit(code=1) |
| 54 | + |
| 55 | + target_root = (output_dir or project.repo_root).resolve() |
| 56 | + target_root.mkdir(parents=True, exist_ok=True) |
| 57 | + |
| 58 | + params: dict = { |
| 59 | + "mode": mode.value, |
| 60 | + "api_port": api_port, |
| 61 | + "workers": workers, |
| 62 | + "compose_target": target_root / "docker-compose.yml", |
| 63 | + } |
| 64 | + if mode == DeployMode.nginx: |
| 65 | + params["nginx_conf_target"] = target_root / "nginx" / "default.conf" |
| 66 | + |
| 67 | + plan = feature.plan(params, project) |
| 68 | + |
| 69 | + installer = FeatureInstaller(dry_run=dry_run, assume_yes=force or yes) |
| 70 | + info(f"deploy: generating '{mode.value}' compose for {project.repo_root}") |
| 71 | + result = installer.apply(plan) |
| 72 | + |
| 73 | + if result.files_skipped: |
| 74 | + info("") |
| 75 | + info(f"{len(result.files_skipped)} file(s) skipped.") |
| 76 | + if dry_run: |
| 77 | + info("") |
| 78 | + info("dry-run complete — no files were written.") |
| 79 | + return |
| 80 | + |
| 81 | + info("") |
| 82 | + info("done. Next steps:") |
| 83 | + if mode == DeployMode.local: |
| 84 | + info(" docker compose up --build") |
| 85 | + elif mode == DeployMode.prod: |
| 86 | + info(" cp backend/.env.example backend/.env # if you haven't already") |
| 87 | + info(" docker compose up -d --build") |
| 88 | + else: |
| 89 | + info(" cp backend/.env.example backend/.env # if you haven't already") |
| 90 | + info(" docker compose up -d --build") |
| 91 | + info(" curl -i http://localhost/api/v1/health") |
0 commit comments