deploy (CLI group)
What it is
A Click-based CLI module that provides deployment commands for:
- Deploying a Docker image to a Naas space (
deploy naas) - Generating and operating a local Docker Compose deployment (
deploy local,deploy local-up,deploy local-down,deploy local-logs)
It also contains a small Naas API client and a deployer that builds/pushes an image and creates/updates a Naas space.
Public API
CLI commands
deploy(Click group)- Root command group for subcommands below.
deploy naas --env <env>- Loads configuration for
env, builds a Docker image, pushes it to a Naas registry, and creates/updates a Naas space.
- Loads configuration for
deploy local --env <env> [--regenerate] [--no-backup] [--headscale]- Generates (and optionally regenerates) local deployment files via
setup_local_deploy(...).
- Generates (and optionally regenerates) local deployment files via
deploy local-up [--detach]- Runs
docker compose upusingdocker-compose.ymland.envwith profilesinfrastructureandcontainer.
- Runs
deploy local-down [--volumes]- Runs
docker compose downwith the same files/profiles; optionally removes volumes.
- Runs
deploy local-logs- Follows logs with
docker compose logs -f(shell invocation).
- Follows logs with
Classes
Container(pydanticBaseModel)- Fields:
name,image,port,cpu,memory,env. - Represents a container definition for a Naas space payload.
- Fields:
Space(pydanticBaseModel)- Fields:
name,containers(list[Container]). - Represents a space definition for a Naas space payload.
- Fields:
NaasAPIClient__init__(naas_api_key: str): sets API key and uses base URLhttps://api.naas.ai.create_registry(name: str):POST /registry/; on409callsget_registry.get_registry(name: str):GET /registry/{name}.get_registry_credentials(name: str):GET /registry/{name}/credentials.create_space(space: Space):POST /space/; on409callsupdate_space; on402raisesclick.ClickException.update_space(space: Space):PUT /space/{space.name}.get_space(name: str):GET /space/{name}.
NaasDeployer__init__(configuration: EngineConfiguration): requiresconfiguration.deployand instantiatesNaasAPIClientwithconfiguration.deploy.naas_api_key.docker_build(image_name: str): runsdocker build -t <image_name> . --platform linux/amd64.deploy(): end-to-end Naas deployment (registry creation, build/login/push, digest extraction, space create/update, prints success message).
Functions (module-internal)
_get_configuration(env: str) -> EngineConfiguration- Sets
ENVenvironment variable, loads configuration viaEngineConfiguration.load_configuration(), and validatesconfiguration.deployexists.
- Sets
Configuration/Dependencies
Configuration
- Uses
EngineConfiguration.load_configuration()and expects a non-Noneconfiguration.deploysection with at least:naas_api_key(used for API auth)space_name(used for registry and space name)env(dict passed as container environment variables)
The --env option sets os.environ["ENV"] to select which config file to load (e.g., config.prod.yaml, config.local.yaml, etc., per the help text).
External dependencies
- Docker CLI must be available for:
docker build,docker login,docker push,docker inspectdocker compose up/down/logs
- Python packages used:
click,requests,pydantic,rich,naas_abi_core.
Usage
CLI
# Deploy to Naas using the "prod" environment config
naas-abi-cli deploy naas --env prod
# Generate local deployment files (optionally include headscale)
naas-abi-cli deploy local --env local --headscale
# Start local deployment
naas-abi-cli deploy local-up --detach
# Tail logs
naas-abi-cli deploy local-logs
# Stop local deployment (optionally remove volumes)
naas-abi-cli deploy local-down --volumes
Minimal Python example (API client)
from naas_abi_cli.cli.deploy.deploy import NaasAPIClient
client = NaasAPIClient(naas_api_key="YOUR_NAAS_API_KEY")
space = client.get_space("your-space-name")
print(space)
Caveats
- Docker commands are invoked without checking return codes (
subprocess.run(...)withoutcheck=True), so failures may not raise automatically. - Image digest extraction uses a shell pipeline (
shell=True) to parsedocker inspectoutput. - Naas deployment hardcodes container settings:
- container name:
"api" - port:
9879 - cpu:
"1" - memory:
"1Gi"
- container name:
- Local commands assume
docker-compose.ymland.envexist in the current working directory.