StackPilot now manages exactly one Docker host: the one it runs on. The
stackpilot-agent sidecar and everything that proxied to it are gone — 4721
lines deleted against 657 added.
Deleted outright: agent/ (image, compose, env), agent_app.py, models/agent.py,
routers/agents.py (1200 lines), services/agent_service.py, the agent API client,
RemoteStackDetail, the host components and AgentStacksSection. That removes 57
API routes and the three /ws/agent-* proxies.
Threaded out everywhere else, which was the bulk of the work. Every API module
carried an optional agentId that switched the base path; every page that listed
Docker objects rendered one section per host behind a HostHeader; Files had a
host switcher; the New Stack editor and the template dialog had host selectors;
schedules, auto-update policies and stack summaries carried agent_id. All of it
is gone, and the typechecker drove the sweep — 85 files touched, tsc and the
build clean.
Two things the removal exposed as dead weight rather than merely unused:
compose_service kept an in-process busy set purely because the agent needed a
lock and has no database. With the agent gone that was a second source of truth
next to the real DB lock, so it is deleted; compute_status now reports only what
the containers say and the two callers that want "updating" overlay the lock.
StacksTable's linkBase prop only ever existed to point at /hosts/{id}/stacks.
The dashboard's "Hosts 1/1 online" KPI can no longer say anything else, so the
tile and the KPIs behind it are gone and the row is five wide.
Upgrading matters here. An existing install still has an agent table holding
each remote host's URL and bearer token — full Docker control of that host,
sitting in the database with nothing left to use it. _drop_removed_schema drops
it on first start, and drops the agent_id columns where the SQLite build
supports DROP COLUMN. Each statement runs in its own transaction on purpose: a
failed DDL poisons the transaction it is in, so sharing one would let an
unsupported column drop take the table drop down with it. test_agent_removal
covers both branches plus the fresh-install and idempotent cases, and an
end-to-end run against a seeded pre-0.48 database confirms the table is gone and
every /api/agents route answers 404.
Docstrings that justified a design by "shared with the agent, which has no
database" were rewritten rather than left lying: update_service's persistence
callback and image_status_store are still the right split (registry logic stays
testable without a database), but for that reason now, not the old one. The
README's multi-host sections are removed and an upgrade note explains what to do
with running agent containers; ROADMAP keeps its history behind a note saying
the feature it describes no longer exists.
CI no longer builds or pushes stackpilot-agent.
735 tests pass, ruff and tsc clean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dk43rmEeRfYi5wsLDbmfyG
139 lines
4.2 KiB
Python
139 lines
4.2 KiB
Python
"""Per-stack file-based secrets & configs (compose) — local host.
|
|
|
|
CRUD over the secret/config files stored in the stack directory, plus
|
|
attach/detach which rewrite the stack's compose file to reference (or stop
|
|
referencing) a secret/config from a service. A redeploy is required for changes
|
|
to take effect on running containers.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
|
from pydantic import BaseModel
|
|
from sqlmodel import Session
|
|
|
|
from auth import require_admin
|
|
from database import get_session
|
|
from models.user import User
|
|
from services import audit_service, secret_service
|
|
from services.compose_edit_service import EditError
|
|
from services.secret_service import SecretError
|
|
|
|
router = APIRouter(prefix="/api/stacks/{stack_id}/secrets", tags=["secrets"])
|
|
|
|
|
|
class SecretWrite(BaseModel):
|
|
kind: str = "secret" # "secret" | "config"
|
|
name: str
|
|
content: str
|
|
|
|
|
|
class AttachBody(BaseModel):
|
|
kind: str = "secret"
|
|
name: str
|
|
service: str
|
|
target: str | None = None # required for configs (mount path)
|
|
|
|
|
|
class DetachBody(BaseModel):
|
|
kind: str = "secret"
|
|
name: str
|
|
service: str
|
|
|
|
|
|
def _ip(request: Request) -> str:
|
|
return request.client.host if request.client else "unknown"
|
|
|
|
|
|
def _guard(fn, *args, **kwargs):
|
|
try:
|
|
return fn(*args, **kwargs)
|
|
except (SecretError, EditError) as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
|
|
|
|
def list_secrets(stack_id: str) -> list[dict]:
|
|
return secret_service.list_all(stack_id)
|
|
|
|
|
|
def write_secret(stack_id: str, body: SecretWrite) -> dict:
|
|
return _guard(secret_service.write_secret, stack_id, body.kind, body.name, body.content)
|
|
|
|
|
|
def delete_secret(stack_id: str, kind: str, name: str) -> dict:
|
|
_guard(secret_service.delete_secret, stack_id, kind, name)
|
|
return {"ok": True}
|
|
|
|
|
|
def attach_secret(stack_id: str, body: AttachBody) -> dict:
|
|
if not secret_service.exists(stack_id, body.kind, body.name):
|
|
raise HTTPException(status_code=404, detail="secret not found")
|
|
new_yaml = _guard(secret_service.attach, stack_id, body.kind, body.name, body.service, body.target)
|
|
return {"ok": True, "yaml": new_yaml}
|
|
|
|
|
|
def detach_secret(stack_id: str, body: DetachBody) -> dict:
|
|
new_yaml = _guard(secret_service.detach, stack_id, body.kind, body.name, body.service)
|
|
return {"ok": True, "yaml": new_yaml}
|
|
|
|
|
|
# --- HTTP endpoints (admin only; secrets are sensitive) ---
|
|
|
|
|
|
@router.get("")
|
|
def http_list(stack_id: str, _user: User = Depends(require_admin)) -> list[dict]:
|
|
return list_secrets(stack_id)
|
|
|
|
|
|
@router.put("")
|
|
def http_write(
|
|
stack_id: str, body: SecretWrite, request: Request,
|
|
session: Session = Depends(get_session), user: User = Depends(require_admin),
|
|
) -> dict:
|
|
result = write_secret(stack_id, body)
|
|
audit_service.record(
|
|
session, user=user.username, action="secret.write",
|
|
target=f"{stack_id}/{body.kind}/{body.name}", ip=_ip(request),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.delete("/{kind}/{name}")
|
|
def http_delete(
|
|
stack_id: str, kind: str, name: str, request: Request,
|
|
session: Session = Depends(get_session), user: User = Depends(require_admin),
|
|
) -> dict:
|
|
result = delete_secret(stack_id, kind, name)
|
|
audit_service.record(
|
|
session, user=user.username, action="secret.delete",
|
|
target=f"{stack_id}/{kind}/{name}", ip=_ip(request),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.post("/attach")
|
|
def http_attach(
|
|
stack_id: str, body: AttachBody, request: Request,
|
|
session: Session = Depends(get_session), user: User = Depends(require_admin),
|
|
) -> dict:
|
|
result = attach_secret(stack_id, body)
|
|
audit_service.record(
|
|
session, user=user.username, action="secret.attach",
|
|
target=f"{stack_id}/{body.kind}/{body.name}->{body.service}", ip=_ip(request),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.post("/detach")
|
|
def http_detach(
|
|
stack_id: str, body: DetachBody, request: Request,
|
|
session: Session = Depends(get_session), user: User = Depends(require_admin),
|
|
) -> dict:
|
|
result = detach_secret(stack_id, body)
|
|
audit_service.record(
|
|
session, user=user.username, action="secret.detach",
|
|
target=f"{stack_id}/{body.kind}/{body.name}->{body.service}", ip=_ip(request),
|
|
)
|
|
return result
|