739b67856a
Build / build (push) Successful in 10m39s
The clean-break delete that closes the workload-first refactor arc.
Net diff: ~30 backend files deleted, ~20 modified, ~12k LOC removed
on the Go side; entire /projects /stacks /sites /deploy frontend
trees gone; ~6.7k LOC removed on the Svelte/TypeScript side.
Backend
- API handlers gone: internal/api/{projects,stages,stage_env,stacks,
static_sites,deploys,instances,volume_browser}.go
- Store CRUD + tests gone: internal/store/{projects,stages,stage_env,
stacks,static_sites,static_site_secrets,deploys,poll_state,volumes,
workload_sync}.go (+ _test.go siblings)
- Legacy deployer pipeline gone: internal/deployer/{bluegreen,promote,
rollback,subdomain,resolver_test}.go; deployer.go trimmed to just the
dispatch surface used by the plugin pipeline
- internal/staticsite/{manager,healthcheck}.go and
internal/stack/manager.go gone (the rest of those packages stay as
helpers imported by the static + compose plugins)
- internal/registry/poller.go gone (legacy registry poller)
- internal/volume.ResolvePath gone; ResolveWorkloadPath stays
- internal/webhook: handleWebhook (project) + handleSiteWebhook (site)
gone; only POST /api/webhook/triggers/{secret} remains
- workload-side webhook URL handlers (getWorkloadWebhook +
regenerateWorkloadWebhook + EnsureWorkloadWebhookSecret +
SetWorkloadWebhookSecret + GetWorkloadByWebhookSecret) gone — they
minted URLs that would 404 against the new trigger-only ingress
- cmd/server/main.go: dropped staticsite.Manager, stack.Manager,
staticsite.HealthChecker, registry poller, SetSiteSyncTriggerer,
SetStaticSiteManager, SetStackManager, wireStaticBackend
- store/store.go: idempotent DROP TABLE IF EXISTS for every legacy
table (projects, stages, stage_env, volumes, deploys, deploy_logs,
poll_states, stacks, stack_revisions, stack_deploys, static_sites,
static_site_secrets); FK order children-then-parents
- store/models.go: dropped Project, Stage, Deploy, DeployLog, StageEnv,
Volume, StaticSite, StaticSiteSecret, Stack, StackRevision,
StackDeploy types; kept WorkloadKind constants as documented strings
- internal/store/helpers.go (new): BoolToInt, rowScanner,
GenerateWebhookSecret extracted from deleted CRUD files
- internal/api/secrets.go (new): forwards to store.GenerateWebhookSecret
so api + store paths share one secret-generation impl (no
panic-vs-UUID-fallback divergence)
- internal/reconciler/reconciler.go: dropped legacy stack-by-compose
+ static-site label paths; only canonical tinyforge.workload.id
dispatch remains
- providers (gitea_content/github_provider/gitlab_provider) gained
path-traversal rejection on every tree entry
- internal/webhook ParsedImage / ParseImageRef demoted to package-
private (no external callers)
Frontend
- /projects /stacks /sites /deploy routes deleted (entire trees)
- ProjectCard / InstanceCard / StaleContainerCard components deleted
- api.ts: dropped every project/stage/stack/site/deploy/instance
helper + types (Project, Stage, Stack, StaticSite, Deploy,
Instance, Volume, etc.); kept Workload, Container, App, Settings,
Registry, EventTrigger, LogScanRule, webhook envelopes
- WorkloadWebhook type + getWorkloadWebhook/regenerateWorkloadWebhook
api functions gone (mirror of the backend deletion above)
- web/src/routes/+layout.svelte: dropped /projects /sites /stacks
/deploy nav entries, trimmed quick-nav keymap
- web/src/routes/+page.svelte: dashboard rewrite — reads
listWorkloads + listContainers only; 4-card stat grid
(workloads/running/failed/stale) + recent workloads strip
- navCounts.ts, SystemHealthCard.svelte, ContainerLogs.svelte,
ContainerStats.svelte, StatusBadge.svelte, TagCombobox.svelte,
proxies/+page.svelte, containers/+page.svelte all rewired to the
workload-first surface
- AbortController plumbing on dashboard, nav-counts, stale page,
SystemHealthCard so navigation doesn't leave dangling fetches
- i18n: dropped projects.*, projectDetail.*, envEditor.*,
volumeEditor.*, volumeBrowser.*, quickDeploy.*, sites.*, stacks.*,
instance.*, confirm.* namespaces; en/ru parity preserved (1042
keys each)
Hardening from go-reviewer + security-reviewer + typescript-reviewer
subagent passes (0 CRITICAL across all three; 1 HIGH + ~12 MEDIUM
addressed inline before commit):
- Sec H1: dead-end workload webhook URL handlers (would mint URLs
that 404 the new trigger-only ingress) deleted across backend +
frontend
- Go M1: IsTerminalDeployStatus dropped (no production callers)
- Go M2: ParsedImage/ParseImageRef lowercased (in-package only)
- Go M6: generateWebhookSecret unified — api shim forwards to
store.GenerateWebhookSecret
- Doc/comment freshness: stage_id (no longer FK), ProxyRoute legacy
field names, workloadIDRow rationale, webhook_deliveries.target_type
enum, WebhookDeliveryLog component header
Doc
- WORKLOAD_REFACTOR_TODO: cutover marked DONE; all three Priority 1
items are now shipped. Next focus is Priority 3 polish (apps.* i18n
+ codemap entries) and Priority 4 tests.
Behavioral notes for operators upgrading from a pre-cutover build
- Existing rows in the dropped tables disappear on first boot.
- Legacy webhook URLs at /api/webhook/{secret} and
/api/webhook/sites/{secret} return 404; CI configs must repoint to
/api/webhook/triggers/{secret} (the trigger-split boot backfill
lifted any embedded workload secret onto a Trigger row, so the
secret value itself carries over).
- Frontend routes /projects /stacks /sites /deploy are gone; nav
links replaced with /apps and /triggers.
166 lines
4.6 KiB
Go
166 lines
4.6 KiB
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"log/slog"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/alexei/tinyforge/internal/crypto"
|
|
"github.com/alexei/tinyforge/internal/store"
|
|
)
|
|
|
|
// workloadEnvRow is the JSON shape returned to clients. Plaintext is
|
|
// redacted for encrypted entries — once a value is encrypted, the
|
|
// server treats it as write-only. To rotate, the operator submits a new
|
|
// value; to read, they have to look at the running container.
|
|
type workloadEnvRow struct {
|
|
ID string `json:"id"`
|
|
WorkloadID string `json:"workload_id"`
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
Encrypted bool `json:"encrypted"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
func (s *Server) listWorkloadEnv(w http.ResponseWriter, r *http.Request) {
|
|
id := chi.URLParam(r, "id")
|
|
if _, err := s.store.GetWorkloadByID(id); err != nil {
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
respondNotFound(w, "workload")
|
|
return
|
|
}
|
|
respondError(w, http.StatusInternalServerError, "get workload")
|
|
return
|
|
}
|
|
rows, err := s.store.ListWorkloadEnv(id)
|
|
if err != nil {
|
|
respondError(w, http.StatusInternalServerError, "list workload env")
|
|
return
|
|
}
|
|
out := make([]workloadEnvRow, 0, len(rows))
|
|
for _, e := range rows {
|
|
row := workloadEnvRow{
|
|
ID: e.ID,
|
|
WorkloadID: e.WorkloadID,
|
|
Key: e.Key,
|
|
Encrypted: e.Encrypted,
|
|
CreatedAt: e.CreatedAt,
|
|
UpdatedAt: e.UpdatedAt,
|
|
}
|
|
if e.Encrypted {
|
|
row.Value = "" // write-only after encryption
|
|
} else {
|
|
row.Value = e.Value
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
respondJSON(w, http.StatusOK, out)
|
|
}
|
|
|
|
// setWorkloadEnvRequest is the POST/PUT body. Encrypted=true causes the
|
|
// server to encrypt the value at rest with the global encryption key.
|
|
type setWorkloadEnvRequest struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
Encrypted bool `json:"encrypted"`
|
|
}
|
|
|
|
func (s *Server) setWorkloadEnv(w http.ResponseWriter, r *http.Request) {
|
|
id := chi.URLParam(r, "id")
|
|
if _, err := s.store.GetWorkloadByID(id); err != nil {
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
respondNotFound(w, "workload")
|
|
return
|
|
}
|
|
respondError(w, http.StatusInternalServerError, "get workload")
|
|
return
|
|
}
|
|
var req setWorkloadEnvRequest
|
|
if !decodeJSONStrict(w, r, &req) {
|
|
return
|
|
}
|
|
req.Key = strings.TrimSpace(req.Key)
|
|
if req.Key == "" {
|
|
respondError(w, http.StatusBadRequest, "key is required")
|
|
return
|
|
}
|
|
if !validEnvKey(req.Key) {
|
|
respondError(w, http.StatusBadRequest, "key must match [A-Za-z_][A-Za-z0-9_]*")
|
|
return
|
|
}
|
|
value := req.Value
|
|
if req.Encrypted && value != "" {
|
|
enc, err := crypto.Encrypt(s.encKey, value)
|
|
if err != nil {
|
|
respondError(w, http.StatusInternalServerError, "encrypt value")
|
|
return
|
|
}
|
|
value = enc
|
|
}
|
|
row, err := s.store.SetWorkloadEnv(store.WorkloadEnv{
|
|
WorkloadID: id,
|
|
Key: req.Key,
|
|
Value: value,
|
|
Encrypted: req.Encrypted,
|
|
})
|
|
if err != nil {
|
|
slog.Error("set workload env", "workload", id, "key", req.Key, "error", err)
|
|
respondError(w, http.StatusInternalServerError, "set workload env")
|
|
return
|
|
}
|
|
respondJSON(w, http.StatusOK, workloadEnvRow{
|
|
ID: row.ID,
|
|
WorkloadID: row.WorkloadID,
|
|
Key: row.Key,
|
|
Value: "", // never echo even fresh writes — caller already has it
|
|
Encrypted: row.Encrypted,
|
|
CreatedAt: row.CreatedAt,
|
|
UpdatedAt: row.UpdatedAt,
|
|
})
|
|
}
|
|
|
|
func (s *Server) deleteWorkloadEnv(w http.ResponseWriter, r *http.Request) {
|
|
envID := chi.URLParam(r, "envID")
|
|
if err := s.store.DeleteWorkloadEnv(envID); err != nil {
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
respondNotFound(w, "workload env")
|
|
return
|
|
}
|
|
respondError(w, http.StatusInternalServerError, "delete workload env")
|
|
return
|
|
}
|
|
respondJSON(w, http.StatusOK, map[string]string{"deleted": envID})
|
|
}
|
|
|
|
// Workload-level webhook URL handlers were dropped in the hard legacy
|
|
// cutover: the old `/api/webhook/workloads/{secret}` route is gone, so
|
|
// minting a workload secret would hand operators a URL that 404s. The
|
|
// inbound webhook surface is now exclusively first-class triggers
|
|
// (`/api/webhook/triggers/{secret}`); use the trigger CRUD + bindings
|
|
// endpoints to wire a workload to inbound deploys.
|
|
|
|
// validEnvKey accepts POSIX-style env names. Rejects anything that would
|
|
// confuse Docker's env parser (=, spaces, control chars).
|
|
func validEnvKey(k string) bool {
|
|
if len(k) == 0 || len(k) > 256 {
|
|
return false
|
|
}
|
|
for i, ch := range k {
|
|
switch {
|
|
case ch >= 'A' && ch <= 'Z',
|
|
ch >= 'a' && ch <= 'z',
|
|
ch == '_':
|
|
continue
|
|
case (ch >= '0' && ch <= '9') && i > 0:
|
|
continue
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|