Phase 2b: serve static frontends in place from repo dist

The Caddyfile generator now emits static-frontend routes that root directly at
<source>/<build.outputs[0]> (e.g. /data/repos/castle/app/dist) instead of a copy
under ~/.castle/artifacts/content. Removes _copy_app_static and the central
content-dir staging entirely; rebuilds are live without a copy step.

- caddyfile.py: manifest-driven static routes (castle-app at /, others at /<name>)
- ReactViteHandler.install just builds in place (no copy); uninstall is a no-op
- is_active(static frontend) = repo dist exists
- test isolation updated for the generator's config use

Dashboard + power-graph-app verified serving from repo dist; 168 tests pass.
This commit is contained in:
2026-06-13 18:16:09 -07:00
parent 2953aea548
commit 482524bfe5
6 changed files with 86 additions and 84 deletions

View File

@@ -14,7 +14,6 @@ from dataclasses import dataclass, field
from pathlib import Path
from castle_core.config import (
CONTENT_DIR,
DATA_DIR,
SPECS_DIR,
CastleConfig,
@@ -98,8 +97,8 @@ def deploy(target_name: str | None = None, root: Path | None = None) -> DeployRe
result.deployed_count += 1
result.messages.append(_format_deployed(name, deployed))
# Handle frontend build artifacts
_copy_app_static(config, result.messages)
# Static frontends are served in place from their repo build output
# (the Caddyfile roots directly at <source>/<dist>) — no copy step.
# Save registry
save_registry(registry)
@@ -367,24 +366,6 @@ def _format_deployed(name: str, deployed: DeployedComponent) -> str:
return " ".join(parts)
def _copy_app_static(config: CastleConfig, messages: list[str]) -> None:
"""Copy frontend build outputs to ~/.castle/artifacts/content/<name>/."""
for name, comp in config.programs.items():
if comp.behavior != "frontend":
continue
if not (comp.build and comp.build.outputs):
continue
source_dir = comp.source_dir or name
for output in comp.build.outputs:
src = config.root / source_dir / output
if src.exists():
dest = CONTENT_DIR / name
if dest.exists():
shutil.rmtree(dest)
shutil.copytree(src, dest)
messages.append(f"Static: {src}{dest}")
def _desired_unit_files(registry: NodeRegistry) -> set[str]:
"""Exact set of unit filenames that should exist on disk for this registry."""
files: set[str] = set()