setup_local_deploy (local deploy setup)
What it is
Utilities to scaffold and maintain a local deployment layout for an ABI project:
- Renders
.deploy/from packaged templates. - Moves generated
docker-compose.ymland.envto the project root. - Ensures required environment variables exist (and generates secrets).
- Optionally adds a Headscale service and its configuration.
Public API
setup_local_deploy(project_path: str, include_headscale: bool = False, base_domain: str | None = None, regenerate: bool = False, backup: bool = True) -> None- Creates/updates local deploy files under
project_path. - Prompts for a base domain if
base_domainis not provided. - If
regenerate=True, can back up existing deploy artifacts and re-render templates. - If
include_headscale=True, renders Headscale templates and injects aheadscaleservice intodocker-compose.yml(if not already present).
- Creates/updates local deploy files under
Other functions/constants in this module are internal helpers.
Configuration/Dependencies
- Template source: uses
Copier(from..utils.Copier) to render templates located inside the installednaas_abi_clipackage:cli/deploy/templates/localcli/deploy/templates/local/docker/headscale(when Headscale is enabled)
- Interactive input:
rich.prompt.Prompt.askis used whenbase_domainis omitted. - Backups (when
regenerate=Trueandbackup=True):- Writes to:
.abi-backups/deploy-local/<timestamp>/ - Backs up any existing:
.deploy/,docker-compose.yml,.env
- Writes to:
- Key environment defaults:
- Uses
DEFAULT_ENV_VALUESand computed hosts frombase_domain:PUBLIC_WEB_HOST = nexus.<base_domain>PUBLIC_API_HOST = api.<base_domain>- Headscale (if enabled):
headscale.<base_domain>,vpn.<base_domain>
- Generates random UUID secrets for:
POSTGRES_PASSWORD,MINIO_ROOT_PASSWORD,RABBITMQ_PASSWORD,FUSEKI_ADMIN_PASSWORD
- Uses
- NEXUS_API_URL derivation:
- Built from
PUBLIC_API_HOSTand optionalPUBLIC_API_SCHEME. - Defaults scheme to
httpfor localhost/IP hosts, otherwisehttps. - If host has no explicit port and is localhost/IP, appends port
9879.
- Built from
Usage
Minimal (non-interactive) usage from Python:
from naas_abi_cli.cli.deploy.local import setup_local_deploy
setup_local_deploy(
project_path=".",
base_domain="localhost",
include_headscale=False,
regenerate=False,
)
Regenerate and include Headscale (with backup):
from naas_abi_cli.cli.deploy.local import setup_local_deploy
setup_local_deploy(
project_path=".",
base_domain="example.localhost",
include_headscale=True,
regenerate=True,
backup=True,
)
Caveats
- If
include_headscale=Trueand the targetdocker-compose.ymlexists but does not contain avolumes:section, Headscale injection raisesValueError. - Headscale template rendering must produce:
.deploy/docker/headscale/config.yaml.deploy/docker/headscale/extra-records.jsonOtherwiseFileNotFoundErroris raised.
- When not regenerating,
.deploy/.envcontent is appended to the project.envonly once (guarded by a marker line). Subsequent runs won’t re-append that block. - When
regenerate=True, the.envis rewritten using the new template while preserving existing values where keys match, and appending non-template keys under “Preserved custom values from previous .env”.