refactor: Align vocabulary — component → program / deployment
Canonical terms (see docs/registry.md glossary): - program: any catalog entry (tool/daemon/frontend) — the software - service / job: how a program is deployed (systemd .service / .timer) - deployment: umbrella for the unified service+job+program view Changes: - core: ServiceSpec/JobSpec component: → program: (component accepted as back-compat validation_alias); DeployedComponent → Deployment. - api: ComponentSummary/Detail → DeploymentSummary/Detail; GET /components → /deployments; GatewayRoute.component → program; GatewayInfo .component_count → deployment_count; ServiceActionResponse/action keys component → program. - app: matching type renames, /components → /deployments hook, route /component/:name → /deployment/:name, GatewayRoute.program. - docs: component-registry.md → registry.md (+ canonical glossary); CLAUDE.md endpoint list refreshed (drop removed /tools, add typed program/service/job + config routes). Tests: core 92, cli 24, api 52 green; app build clean; ruff clean.
This commit is contained in:
@@ -252,7 +252,7 @@ def _expand_units(
|
||||
|
||||
services[name] = ServiceSpec(
|
||||
id=name,
|
||||
component=name,
|
||||
program=name,
|
||||
run=run_spec,
|
||||
expose=ExposeSpec(
|
||||
http=HttpExposeSpec(
|
||||
@@ -272,7 +272,7 @@ def _expand_units(
|
||||
assert unit.argv is not None # guaranteed by validator
|
||||
jobs[name] = JobSpec(
|
||||
id=name,
|
||||
component=name,
|
||||
program=name,
|
||||
description=unit.description,
|
||||
run=RunCommand(runner="command", argv=list(unit.argv)),
|
||||
schedule=unit.schedule,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Deploy logic — bridge castle.yaml spec to runtime (~/.castle/).
|
||||
|
||||
This module contains the core deploy logic shared by the CLI and API.
|
||||
It reads castle.yaml, resolves services/jobs into DeployedComponents,
|
||||
It reads castle.yaml, resolves services/jobs into Deployments,
|
||||
writes the registry, generates systemd units and the Caddyfile, and
|
||||
copies frontend build outputs.
|
||||
"""
|
||||
@@ -31,7 +31,7 @@ from castle_core.generators.systemd import (
|
||||
from castle_core.manifest import JobSpec, ServiceSpec
|
||||
from castle_core.registry import (
|
||||
REGISTRY_PATH,
|
||||
DeployedComponent,
|
||||
Deployment,
|
||||
NodeConfig,
|
||||
NodeRegistry,
|
||||
load_registry,
|
||||
@@ -139,21 +139,21 @@ def _resolve_description(config: CastleConfig, spec: ServiceSpec | JobSpec) -> s
|
||||
"""Get description, falling through to program if referenced."""
|
||||
if spec.description:
|
||||
return spec.description
|
||||
if spec.component and spec.component in config.programs:
|
||||
return config.programs[spec.component].description
|
||||
if spec.program and spec.program in config.programs:
|
||||
return config.programs[spec.program].description
|
||||
return None
|
||||
|
||||
|
||||
def _build_deployed_service(
|
||||
config: CastleConfig, name: str, svc: ServiceSpec, messages: list[str]
|
||||
) -> DeployedComponent:
|
||||
"""Build a DeployedComponent from a ServiceSpec."""
|
||||
) -> Deployment:
|
||||
"""Build a Deployment from a ServiceSpec."""
|
||||
run = svc.run
|
||||
# Env prefix and data dir are keyed by the program (component) the service
|
||||
# runs, not the service name — that's the prefix the program's settings read
|
||||
# (e.g. job `protonmail-sync` runs program `protonmail` → PROTONMAIL_DATA_DIR).
|
||||
# Falls back to the service name when no component is referenced.
|
||||
config_key = svc.component or name
|
||||
config_key = svc.program or name
|
||||
prefix = _env_prefix(config_key)
|
||||
env: dict[str, str] = {}
|
||||
|
||||
@@ -182,7 +182,7 @@ def _build_deployed_service(
|
||||
env = resolve_env_vars(env)
|
||||
|
||||
# Ensure python tool is installed before resolving binary
|
||||
_ensure_python_tool(config, svc.component, messages)
|
||||
_ensure_python_tool(config, svc.program, messages)
|
||||
|
||||
# Build run_cmd
|
||||
run_cmd = _build_run_cmd(name, run, env, messages)
|
||||
@@ -194,13 +194,13 @@ def _build_deployed_service(
|
||||
|
||||
# Resolve stack from referenced program
|
||||
stack = None
|
||||
if svc.component and svc.component in config.programs:
|
||||
stack = config.programs[svc.component].stack
|
||||
if svc.program and svc.program in config.programs:
|
||||
stack = config.programs[svc.program].stack
|
||||
|
||||
# Remote services proxy to an external base_url
|
||||
base_url = getattr(run, "base_url", None)
|
||||
|
||||
return DeployedComponent(
|
||||
return Deployment(
|
||||
runner=run.runner,
|
||||
run_cmd=run_cmd,
|
||||
env=env,
|
||||
@@ -217,12 +217,12 @@ def _build_deployed_service(
|
||||
|
||||
def _build_deployed_job(
|
||||
config: CastleConfig, name: str, job: JobSpec, messages: list[str]
|
||||
) -> DeployedComponent:
|
||||
"""Build a DeployedComponent from a JobSpec."""
|
||||
) -> Deployment:
|
||||
"""Build a Deployment from a JobSpec."""
|
||||
run = job.run
|
||||
# Keyed by the program (component) the job runs, not the job name — see
|
||||
# _build_deployed_service for rationale. Falls back to the job name.
|
||||
config_key = job.component or name
|
||||
config_key = job.program or name
|
||||
prefix = _env_prefix(config_key)
|
||||
env: dict[str, str] = {}
|
||||
|
||||
@@ -232,14 +232,14 @@ def _build_deployed_job(
|
||||
env.update(job.defaults.env)
|
||||
|
||||
env = resolve_env_vars(env)
|
||||
_ensure_python_tool(config, job.component, messages)
|
||||
_ensure_python_tool(config, job.program, messages)
|
||||
run_cmd = _build_run_cmd(name, run, env, messages)
|
||||
|
||||
stack = None
|
||||
if job.component and job.component in config.programs:
|
||||
stack = config.programs[job.component].stack
|
||||
if job.program and job.program in config.programs:
|
||||
stack = config.programs[job.program].stack
|
||||
|
||||
return DeployedComponent(
|
||||
return Deployment(
|
||||
runner=run.runner,
|
||||
run_cmd=run_cmd,
|
||||
env=env,
|
||||
@@ -273,33 +273,33 @@ def _python_tool_needs_install(program: str) -> bool:
|
||||
|
||||
|
||||
def _ensure_python_tool(
|
||||
config: CastleConfig, component: str | None, messages: list[str]
|
||||
config: CastleConfig, program: str | None, messages: list[str]
|
||||
) -> None:
|
||||
"""Ensure a Python program's editable install is current."""
|
||||
if not component or component not in config.programs:
|
||||
if not program or program not in config.programs:
|
||||
return
|
||||
comp = config.programs[component]
|
||||
comp = config.programs[program]
|
||||
if not comp.source or not comp.stack or not comp.stack.startswith("python"):
|
||||
return
|
||||
source_dir = Path(comp.source)
|
||||
if not source_dir.is_dir():
|
||||
messages.append(f"Warning: source not found: {source_dir}")
|
||||
return
|
||||
if not _python_tool_needs_install(component):
|
||||
if not _python_tool_needs_install(program):
|
||||
return
|
||||
pkg_spec = str(source_dir)
|
||||
if comp.install_extras:
|
||||
pkg_spec += "[" + ",".join(comp.install_extras) + "]"
|
||||
messages.append(f"Installing {component} from {source_dir}...")
|
||||
messages.append(f"Installing {program} from {source_dir}...")
|
||||
result = subprocess.run(
|
||||
["uv", "tool", "install", "--editable", pkg_spec, "--force"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
messages.append(f"Error: {component} install failed:\n{result.stdout}{result.stderr}")
|
||||
messages.append(f"Error: {program} install failed:\n{result.stdout}{result.stderr}")
|
||||
else:
|
||||
messages.append(f"Installed {component}")
|
||||
messages.append(f"Installed {program}")
|
||||
|
||||
|
||||
def _build_run_cmd(name: str, run: object, env: dict[str, str], messages: list[str]) -> list[str]:
|
||||
@@ -354,7 +354,7 @@ def _build_run_cmd(name: str, run: object, env: dict[str, str], messages: list[s
|
||||
raise ValueError(f"Unsupported runner: {run.runner}") # type: ignore[union-attr]
|
||||
|
||||
|
||||
def _format_deployed(name: str, deployed: DeployedComponent) -> str:
|
||||
def _format_deployed(name: str, deployed: Deployment) -> str:
|
||||
"""Format deployment summary for a component."""
|
||||
parts = [name]
|
||||
if deployed.port:
|
||||
|
||||
@@ -6,7 +6,7 @@ import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from castle_core.manifest import RestartPolicy, SystemdSpec
|
||||
from castle_core.registry import DeployedComponent
|
||||
from castle_core.registry import Deployment
|
||||
|
||||
SYSTEMD_USER_DIR = Path.home() / ".config" / "systemd" / "user"
|
||||
UNIT_PREFIX = "castle-"
|
||||
@@ -74,7 +74,7 @@ def cron_to_interval_sec(cron: str) -> int | None:
|
||||
|
||||
def generate_unit_from_deployed(
|
||||
name: str,
|
||||
deployed: DeployedComponent,
|
||||
deployed: Deployment,
|
||||
systemd_spec: SystemdSpec | None = None,
|
||||
) -> str:
|
||||
"""Generate a systemd unit from a deployed component (registry-based).
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from enum import Enum
|
||||
from typing import Annotated, Literal, Union
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
EnvMap = dict[str, str]
|
||||
|
||||
@@ -247,8 +247,13 @@ class ProgramSpec(BaseModel):
|
||||
class ServiceSpec(BaseModel):
|
||||
"""Long-running daemon deployment config."""
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
id: str = ""
|
||||
component: str | None = None
|
||||
# The program this service deploys. (`component` accepted as a legacy alias.)
|
||||
program: str | None = Field(
|
||||
default=None, validation_alias=AliasChoices("program", "component")
|
||||
)
|
||||
description: str | None = None
|
||||
|
||||
run: RunSpec
|
||||
@@ -274,8 +279,13 @@ class ServiceSpec(BaseModel):
|
||||
class JobSpec(BaseModel):
|
||||
"""Scheduled task that runs periodically and exits."""
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
id: str = ""
|
||||
component: str | None = None
|
||||
# The program this job runs. (`component` accepted as a legacy alias.)
|
||||
program: str | None = Field(
|
||||
default=None, validation_alias=AliasChoices("program", "component")
|
||||
)
|
||||
description: str | None = None
|
||||
|
||||
run: RunSpec
|
||||
|
||||
@@ -28,7 +28,7 @@ class NodeConfig:
|
||||
|
||||
|
||||
@dataclass
|
||||
class DeployedComponent:
|
||||
class Deployment:
|
||||
"""A component deployed on this node with resolved runtime config."""
|
||||
|
||||
runner: str
|
||||
@@ -50,7 +50,7 @@ class NodeRegistry:
|
||||
"""What's deployed on this node."""
|
||||
|
||||
node: NodeConfig
|
||||
deployed: dict[str, DeployedComponent] = field(default_factory=dict)
|
||||
deployed: dict[str, Deployment] = field(default_factory=dict)
|
||||
|
||||
|
||||
def load_registry(path: Path | None = None) -> NodeRegistry:
|
||||
@@ -77,7 +77,7 @@ def load_registry(path: Path | None = None) -> NodeRegistry:
|
||||
gateway_port=node_data.get("gateway_port", 9000),
|
||||
)
|
||||
|
||||
deployed: dict[str, DeployedComponent] = {}
|
||||
deployed: dict[str, Deployment] = {}
|
||||
for name, comp_data in data.get("deployed", {}).items():
|
||||
# Support both old "category" and new "behavior" keys for migration
|
||||
behavior = comp_data.get("behavior")
|
||||
@@ -92,7 +92,7 @@ def load_registry(path: Path | None = None) -> NodeRegistry:
|
||||
if category == "frontend"
|
||||
else category
|
||||
)
|
||||
deployed[name] = DeployedComponent(
|
||||
deployed[name] = Deployment(
|
||||
runner=comp_data.get("runner", "command"),
|
||||
run_cmd=comp_data.get("run_cmd", []),
|
||||
env=comp_data.get("env", {}),
|
||||
|
||||
@@ -28,9 +28,9 @@ _EXTRA_PATH_DIRS = [
|
||||
|
||||
@dataclass
|
||||
class ActionResult:
|
||||
"""Result of a stack lifecycle action."""
|
||||
"""Result of a program lifecycle action."""
|
||||
|
||||
component: str
|
||||
program: str
|
||||
action: str
|
||||
status: str # "ok" | "error"
|
||||
output: str = ""
|
||||
@@ -90,12 +90,12 @@ class StackHandler:
|
||||
result = await action_fn(name, comp, root)
|
||||
if result.status != "ok":
|
||||
return ActionResult(
|
||||
component=name,
|
||||
program=name,
|
||||
action="check",
|
||||
status="error",
|
||||
output=f"{action_name} failed:\n{result.output}",
|
||||
)
|
||||
return ActionResult(component=name, action="check", status="ok")
|
||||
return ActionResult(program=name, action="check", status="ok")
|
||||
|
||||
async def install(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
raise NotImplementedError
|
||||
@@ -111,33 +111,33 @@ class PythonHandler(StackHandler):
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["uv", "sync"], src)
|
||||
return ActionResult(
|
||||
component=name, action="build", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="build", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def test(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
if not (src / "tests").exists():
|
||||
return ActionResult(
|
||||
component=name, action="test", status="ok",
|
||||
program=name, action="test", status="ok",
|
||||
output="No tests directory found, skipping.",
|
||||
)
|
||||
rc, output = await _run(["uv", "run", "pytest", "tests/", "-v"], src)
|
||||
return ActionResult(
|
||||
component=name, action="test", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="test", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def lint(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["uv", "run", "ruff", "check", "."], src)
|
||||
return ActionResult(
|
||||
component=name, action="lint", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="lint", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def type_check(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["uv", "run", "pyright"], src)
|
||||
return ActionResult(
|
||||
component=name, action="type-check", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="type-check", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def install(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
@@ -149,7 +149,7 @@ class PythonHandler(StackHandler):
|
||||
["uv", "tool", "install", "--editable", pkg_spec, "--force"], src
|
||||
)
|
||||
return ActionResult(
|
||||
component=name, action="install", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="install", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def uninstall(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
@@ -162,7 +162,7 @@ class PythonHandler(StackHandler):
|
||||
pkg_name = data.get("project", {}).get("name", pkg_name)
|
||||
rc, output = await _run(["uv", "tool", "uninstall", pkg_name], src)
|
||||
return ActionResult(
|
||||
component=name, action="uninstall", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="uninstall", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
|
||||
@@ -173,28 +173,28 @@ class ReactViteHandler(StackHandler):
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["pnpm", "build"], src)
|
||||
return ActionResult(
|
||||
component=name, action="build", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="build", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def test(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["pnpm", "test"], src)
|
||||
return ActionResult(
|
||||
component=name, action="test", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="test", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def lint(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["pnpm", "lint"], src)
|
||||
return ActionResult(
|
||||
component=name, action="lint", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="lint", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def type_check(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
src = _source_dir(comp, root)
|
||||
rc, output = await _run(["pnpm", "type-check"], src)
|
||||
return ActionResult(
|
||||
component=name, action="type-check", status="ok" if rc == 0 else "error", output=output
|
||||
program=name, action="type-check", status="ok" if rc == 0 else "error", output=output
|
||||
)
|
||||
|
||||
async def install(self, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
@@ -203,18 +203,18 @@ class ReactViteHandler(StackHandler):
|
||||
result = await self.build(name, comp, root)
|
||||
if result.status != "ok":
|
||||
return ActionResult(
|
||||
component=name, action="install", status="error",
|
||||
program=name, action="install", status="error",
|
||||
output=f"Build failed:\n{result.output}",
|
||||
)
|
||||
outputs = comp.build.outputs if comp.build else []
|
||||
if not outputs:
|
||||
return ActionResult(
|
||||
component=name, action="install", status="error",
|
||||
program=name, action="install", status="error",
|
||||
output="No build outputs configured.",
|
||||
)
|
||||
dist = _source_dir(comp, root) / outputs[0]
|
||||
return ActionResult(
|
||||
component=name, action="install", status="ok",
|
||||
program=name, action="install", status="ok",
|
||||
output=f"Built; served in place from {dist}",
|
||||
)
|
||||
|
||||
@@ -224,7 +224,7 @@ class ReactViteHandler(StackHandler):
|
||||
Deactivating one means dropping its gateway route — handled by removing the
|
||||
program from the registry, not by deleting build output."""
|
||||
return ActionResult(
|
||||
component=name, action="uninstall", status="ok",
|
||||
program=name, action="uninstall", status="ok",
|
||||
output=f"{name}: served in place; nothing to uninstall.",
|
||||
)
|
||||
|
||||
@@ -287,8 +287,8 @@ async def _run_declared(
|
||||
rc, output = await _run(argv, src)
|
||||
outputs.append(output)
|
||||
if rc != 0:
|
||||
return ActionResult(component=name, action=verb, status="error", output="".join(outputs))
|
||||
return ActionResult(component=name, action=verb, status="ok", output="".join(outputs))
|
||||
return ActionResult(program=name, action=verb, status="error", output="".join(outputs))
|
||||
return ActionResult(program=name, action=verb, status="ok", output="".join(outputs))
|
||||
|
||||
|
||||
async def run_action(verb: str, name: str, comp: ProgramSpec, root: Path) -> ActionResult:
|
||||
@@ -303,17 +303,17 @@ async def run_action(verb: str, name: str, comp: ProgramSpec, root: Path) -> Act
|
||||
subs = [s for s in ("lint", "type-check", "test") if is_available(comp, s)]
|
||||
if not subs:
|
||||
return ActionResult(
|
||||
component=name, action="check", status="error",
|
||||
program=name, action="check", status="error",
|
||||
output="No checkable verbs available.",
|
||||
)
|
||||
for sub in subs:
|
||||
result = await run_action(sub, name, comp, root)
|
||||
if result.status != "ok":
|
||||
return ActionResult(
|
||||
component=name, action="check", status="error",
|
||||
program=name, action="check", status="error",
|
||||
output=f"{sub} failed:\n{result.output}",
|
||||
)
|
||||
return ActionResult(component=name, action="check", status="ok")
|
||||
return ActionResult(program=name, action="check", status="ok")
|
||||
|
||||
# 1. Declared command overrides the stack default.
|
||||
declared = _declared_commands(comp, verb)
|
||||
@@ -321,7 +321,7 @@ async def run_action(verb: str, name: str, comp: ProgramSpec, root: Path) -> Act
|
||||
try:
|
||||
src = _source_dir(comp, root)
|
||||
except ValueError:
|
||||
return ActionResult(component=name, action=verb, status="error", output="No source directory")
|
||||
return ActionResult(program=name, action=verb, status="error", output="No source directory")
|
||||
return await _run_declared(name, verb, declared, src)
|
||||
|
||||
# 2. Stack default.
|
||||
@@ -333,7 +333,7 @@ async def run_action(verb: str, name: str, comp: ProgramSpec, root: Path) -> Act
|
||||
|
||||
# 3. Unavailable.
|
||||
return ActionResult(
|
||||
component=name, action=verb, status="error",
|
||||
program=name, action=verb, status="error",
|
||||
output=f"Verb '{verb}' is not available for '{name}' "
|
||||
f"(no declared command and no stack handler provides it).",
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ def castle_root(tmp_path: Path) -> Generator[Path, None, None]:
|
||||
},
|
||||
"services": {
|
||||
"test-svc": {
|
||||
"component": "test-svc-comp",
|
||||
"program": "test-svc-comp",
|
||||
"description": "Test service",
|
||||
"run": {
|
||||
"runner": "python",
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
from castle_core.generators.caddyfile import generate_caddyfile_from_registry
|
||||
from castle_core.registry import DeployedComponent, NodeConfig, NodeRegistry
|
||||
from castle_core.registry import Deployment, NodeConfig, NodeRegistry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -22,7 +22,7 @@ def _isolate_config(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def _make_registry(
|
||||
deployed: dict[str, DeployedComponent] | None = None,
|
||||
deployed: dict[str, Deployment] | None = None,
|
||||
gateway_port: int = 9000,
|
||||
) -> NodeRegistry:
|
||||
"""Create a test registry."""
|
||||
@@ -45,7 +45,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Caddyfile has reverse proxy routes for deployed services."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-svc": DeployedComponent(
|
||||
"test-svc": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "test-svc"],
|
||||
port=19000,
|
||||
@@ -61,7 +61,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Components without proxy_path are not in Caddyfile."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-tool": DeployedComponent(
|
||||
"test-tool": Deployment(
|
||||
runner="command",
|
||||
run_cmd=["test-tool"],
|
||||
),
|
||||
@@ -81,7 +81,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Service proxy routes appear before the dashboard catch-all."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-svc": DeployedComponent(
|
||||
"test-svc": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "test-svc"],
|
||||
port=19000,
|
||||
@@ -98,13 +98,13 @@ class TestCaddyfileFromRegistry:
|
||||
"""Multiple services get separate proxy routes."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"svc-a": DeployedComponent(
|
||||
"svc-a": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "svc-a"],
|
||||
port=9001,
|
||||
proxy_path="/svc-a",
|
||||
),
|
||||
"svc-b": DeployedComponent(
|
||||
"svc-b": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "svc-b"],
|
||||
port=9002,
|
||||
@@ -126,14 +126,14 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""Remote services get reverse_proxy entries to their hostname."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"local-svc": DeployedComponent(
|
||||
"local-svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/local"
|
||||
),
|
||||
}
|
||||
)
|
||||
remote = _make_registry(
|
||||
deployed={
|
||||
"remote-svc": DeployedComponent(
|
||||
"remote-svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9050, proxy_path="/remote"
|
||||
),
|
||||
}
|
||||
@@ -148,14 +148,14 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""If local and remote use the same path, local wins."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
)
|
||||
remote = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""No remote routes when remote_registries is None."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestLoadConfig:
|
||||
"""Service references a component."""
|
||||
config = load_config(castle_root)
|
||||
svc = config.services["test-svc"]
|
||||
assert svc.component == "test-svc-comp"
|
||||
assert svc.program == "test-svc-comp"
|
||||
|
||||
def test_job_schedule(self, castle_root: Path) -> None:
|
||||
"""Job has correct schedule."""
|
||||
|
||||
@@ -7,11 +7,11 @@ from unittest.mock import patch
|
||||
|
||||
from castle_core import deploy as deploy_mod
|
||||
from castle_core.deploy import _desired_unit_files, _prune_orphans
|
||||
from castle_core.registry import DeployedComponent, NodeConfig, NodeRegistry
|
||||
from castle_core.registry import Deployment, NodeConfig, NodeRegistry
|
||||
|
||||
|
||||
def _svc(managed: bool = True, schedule: str | None = None) -> DeployedComponent:
|
||||
return DeployedComponent(
|
||||
def _svc(managed: bool = True, schedule: str | None = None) -> Deployment:
|
||||
return Deployment(
|
||||
runner="python",
|
||||
run_cmd=["x"],
|
||||
env={},
|
||||
@@ -20,7 +20,7 @@ def _svc(managed: bool = True, schedule: str | None = None) -> DeployedComponent
|
||||
)
|
||||
|
||||
|
||||
def _registry(**deployed: DeployedComponent) -> NodeRegistry:
|
||||
def _registry(**deployed: Deployment) -> NodeRegistry:
|
||||
return NodeRegistry(node=NodeConfig(castle_root="/x", gateway_port=9000), deployed=dict(deployed))
|
||||
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ class TestServiceSpec:
|
||||
"""Service can reference a component."""
|
||||
s = ServiceSpec(
|
||||
id="svc",
|
||||
component="my-component",
|
||||
program="my-component",
|
||||
run=RunPython(runner="python", program="svc"),
|
||||
)
|
||||
assert s.component == "my-component"
|
||||
assert s.program == "my-component"
|
||||
|
||||
def test_service_with_proxy(self) -> None:
|
||||
"""Service with proxy spec."""
|
||||
@@ -139,11 +139,11 @@ class TestJobSpec:
|
||||
"""Job can reference a component."""
|
||||
j = JobSpec(
|
||||
id="sync",
|
||||
component="protonmail",
|
||||
program="protonmail",
|
||||
run=RunCommand(runner="command", argv=["protonmail", "sync"]),
|
||||
schedule="*/5 * * * *",
|
||||
)
|
||||
assert j.component == "protonmail"
|
||||
assert j.program == "protonmail"
|
||||
|
||||
def test_job_requires_schedule(self) -> None:
|
||||
"""Job without schedule is invalid."""
|
||||
|
||||
@@ -7,7 +7,7 @@ from castle_core.generators.systemd import (
|
||||
generate_unit_from_deployed,
|
||||
unit_name,
|
||||
)
|
||||
from castle_core.registry import DeployedComponent
|
||||
from castle_core.registry import Deployment
|
||||
|
||||
|
||||
class TestUnitName:
|
||||
@@ -24,7 +24,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_description(self) -> None:
|
||||
"""Unit file has service description."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={"TEST_SVC_PORT": "19000"},
|
||||
@@ -35,7 +35,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_no_working_directory(self) -> None:
|
||||
"""Unit file has no WorkingDirectory (source/runtime separation)."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -46,7 +46,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_environment(self) -> None:
|
||||
"""Unit file has environment variables from deployed config."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={"TEST_SVC_DATA_DIR": "/home/user/.castle/data/test-svc"},
|
||||
@@ -57,7 +57,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_restart_policy(self) -> None:
|
||||
"""Unit file has restart configuration."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -68,7 +68,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_exec_start_from_run_cmd(self) -> None:
|
||||
"""Unit file ExecStart uses resolved run_cmd."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -79,7 +79,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_basic_service(self) -> None:
|
||||
"""Generate a unit from a deployed component."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "my-svc"],
|
||||
env={"MY_SVC_PORT": "9001", "MY_SVC_DATA_DIR": "/home/user/.castle/data/my-svc"},
|
||||
@@ -95,7 +95,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_scheduled_job(self) -> None:
|
||||
"""Scheduled component generates oneshot unit."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="command",
|
||||
run_cmd=["/home/user/.local/bin/my-job"],
|
||||
env={},
|
||||
@@ -108,7 +108,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_no_repo_paths(self) -> None:
|
||||
"""Generated units must not reference repo paths."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "my-svc"],
|
||||
env={"DATA_DIR": "/home/user/.castle/data/my-svc"},
|
||||
|
||||
@@ -76,7 +76,7 @@ class TestUnitExpansion:
|
||||
assert svc.expose.http.health_path == "/health"
|
||||
assert svc.proxy.caddy.path_prefix == "/my-svc"
|
||||
assert svc.manage.systemd is not None
|
||||
assert svc.component == "my-svc"
|
||||
assert svc.program == "my-svc"
|
||||
|
||||
def test_tool_creates_program_only(self, units_root: Path) -> None:
|
||||
config = load_config(units_root)
|
||||
@@ -108,7 +108,7 @@ class TestUnitExpansion:
|
||||
assert job.run.runner == "command"
|
||||
assert job.run.argv == ["my-job", "run"]
|
||||
assert job.defaults.env["DATA_DIR"] == "/tmp/data"
|
||||
assert job.component == "my-job"
|
||||
assert job.program == "my-job"
|
||||
|
||||
def test_service_without_path_prefix(self, tmp_path: Path) -> None:
|
||||
config_data = {
|
||||
|
||||
Reference in New Issue
Block a user