4a607ad098
Adopts the firecracker infra-VM pattern for macOS: the orchestrator control plane and the gateway data plane now run in a SINGLE Apple container instead of two. Apple Containers are lightweight VMs with separate kernels, so the prior two-container design had both guests writing one bot-bottle.db over virtiofs, where fcntl locks are not coherent across kernels — concurrent writes (the orchestrator's registry vs the gateway supervise daemon's queue) could corrupt it. One container = one kernel = coherent locking. The DB moves onto a container-only Apple volume (bot-bottle-mac-db), never bind-mounted from the host, so no host process opens the live file either. The host CLI already reaches registry + supervise state over the control-plane HTTP surface (cli/supervise.py uses OrchestratorClient), exactly as firecracker's VM-only DB requires. Two simplifications fall out of the single container: - No DNS dance: the control plane and gateway daemons reach each other over 127.0.0.1, so the orchestrator-before-gateway ordering (a workaround for Apple having no container DNS) is gone, along with the moved-IP recreate logic it needed. - Net -243 lines. Mechanics: the infra container runs from the gateway image with the control-plane source bind-mounted read-only (like the docker orchestrator, so a code change needs no rebuild) and a small sh -c init that starts both processes (mirrors firecracker's _infra_init). Also implements the macOS backend's ensure_orchestrator() and adds it to discover_orchestrator_url, so operator tools (supervise) can bring up / find the control plane on demand — previously the macOS backend died with "no orchestrator control plane". Verified end-to-end on real Apple Container 1.0.0: the single infra container comes up healthy (one address for control plane + gateway), both processes run, the DB is written on the container-only volume, host-side supervise works over HTTP, and a registered agent gets 200 for an allowed host / 403 for a denied one. 1824 unit tests pass with `container` absent (CI parity), pyright clean, pylint 9.89. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Shared network/image constants for the macOS consolidated infra container.
|
|
|
|
The gateway data plane no longer runs as its own Apple container — it shares a
|
|
single per-host **infra container** with the control plane (see `infra`),
|
|
because two Apple-Container guests writing one `bot-bottle.db` over virtiofs
|
|
would race incoherent `fcntl` locks. This module holds the pieces both the
|
|
infra service and the launch/provision glue need: the network names, the
|
|
gateway image, and the network-creation helper.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from ...orchestrator.gateway import GatewayError
|
|
from . import util as container_mod
|
|
|
|
# The shared host-only network the infra container and every agent bottle sit
|
|
# on. The agent's address here is the attribution key. Distinct from the docker
|
|
# names so both backends can coexist on one host.
|
|
GATEWAY_NETWORK = "bot-bottle-mac-gateway"
|
|
# The NAT network that gives the infra container (and only it) a route out.
|
|
GATEWAY_EGRESS_NETWORK = "bot-bottle-mac-egress"
|
|
|
|
GATEWAY_IMAGE = os.environ.get("BOT_BOTTLE_GATEWAY_IMAGE", "bot-bottle-gateway:latest")
|
|
|
|
DEFAULT_CA_TIMEOUT_SECONDS = 30.0
|
|
|
|
|
|
def ensure_networks(
|
|
network: str = GATEWAY_NETWORK, egress_network: str = GATEWAY_EGRESS_NETWORK,
|
|
) -> None:
|
|
"""Create the shared host-only network + the NAT egress network. Idempotent
|
|
— `create_network` tolerates 'already exists'."""
|
|
container_mod.create_network(egress_network)
|
|
container_mod.create_network(network, internal=True)
|
|
|
|
|
|
__all__ = [
|
|
"GATEWAY_NETWORK",
|
|
"GATEWAY_EGRESS_NETWORK",
|
|
"GATEWAY_IMAGE",
|
|
"GatewayError",
|
|
"DEFAULT_CA_TIMEOUT_SECONDS",
|
|
"ensure_networks",
|
|
]
|