stack_services
What it is
Utilities and static metadata for evaluating “readiness” of local stack services (typically Docker Compose services) via:
- Docker Compose container state/health
- HTTP health endpoints on localhost
- TCP connectivity checks on localhost ports
Public API
Constants
-
ABI_REQUIRED_URL: str- Hard-coded HTTP endpoint used as the required readiness check for the
abiservice (http://127.0.0.1:9879).
- Hard-coded HTTP endpoint used as the required readiness check for the
-
SERVICE_CATALOG: dict[str, ServiceDefinition]- Static catalog of known services and their readiness targets (URLs and/or TCP ports), plus display metadata.
Data classes
-
ServiceDefinition- Service metadata and readiness configuration.
- Fields:
key: strdisplay_name: strcategory: strdescription: strurls: tuple[str, ...] = ()(HTTP endpoints to probe)tcp_targets: tuple[tuple[str, int], ...] = ()(TCP host/port to probe)is_one_shot: bool = False(init/one-shot container semantics)
-
ReadinessResult- Result of a readiness evaluation.
- Fields:
ready: boolsource: str(e.g.,compose,docker-health,http,tcp)detail: str(human-readable detail/status)
Function
evaluate_service_readiness(service_name: str, state: ComposeServiceState | None, http_timeout: float = 1.5, tcp_timeout: float = 1.2) -> ReadinessResult- Determines whether a service should be considered “ready” based on:
- missing container (
state is None) → not ready - Docker health
unhealthy→ not ready - one-shot services (
ServiceDefinition.is_one_shot) → ready only whenstate.state == "exited"andexit_code == 0 - special-case
abi:- must be
running - must pass HTTP check to
ABI_REQUIRED_URL
- must be
- otherwise:
- Docker health
healthy→ ready - must be
running(else not ready) - if in
SERVICE_CATALOG, attempts:- HTTP checks in order; first success marks ready
- then TCP checks in order; first success marks ready
- if no checks succeed (or none configured), running container is considered ready
- Docker health
- missing container (
- Determines whether a service should be considered “ready” based on:
Configuration/Dependencies
- Depends on
ComposeServiceStatefrom.stack_runtime(must provide at leaststate,health,exit_codeattributes used here). - Uses standard library:
urllib.request/urllib.errorfor HTTP probingsocketfor TCP probing
- Service endpoints/ports are hard-coded to
127.0.0.1with fixed ports inSERVICE_CATALOG.
Usage
from naas_abi_cli.cli.stack_services import evaluate_service_readiness
# ComposeServiceState comes from naas_abi_cli.cli.stack_runtime.
# This call returns a ReadinessResult describing readiness status.
result = evaluate_service_readiness(service_name="postgres", state=None)
print(result.ready) # False
print(result.source) # "compose"
print(result.detail) # "Container not created"
Caveats
abireadiness is stricter than other services:- it must be
runningand respond successfully onhttp://127.0.0.1:9879, regardless of other URLs in the catalog.
- it must be
- If a container is
runningbut all configured HTTP/TCP checks fail (or no checks exist), the function returns ready with sourcecomposeand detailContainer is running.