410a131cec
This session (frontend focus):
- Rebuild /apps/new as a 4-step wizard (Basics → Configure → Trigger → Review):
WizardRail, SourceKindPicker card grid, AppManifest review, per-step validation,
ConfirmDialog-based unsaved-changes guard.
- Extract lib/workload/sourceForms.ts (single source of truth for source_config)
+ {Image,Compose,Static,Dockerfile}SourceForm + StaticDiscoveryWizard; fold the
/apps/[id] edit form onto the same components (removes the duplication). Add
vitest + sourceForms unit tests.
- Branch preview environments UI: /chain is_preview/preview_branch + a Preview
environments panel on /apps/[id] (per-branch URLs, ConfirmDialog teardown, armed
state); RegistryImagePicker on the registry trigger and the image source.
- Fixes: image-inspect 404 -> admin-gated POST /api/discovery/image/inspect;
conflict-panel blur flicker; friendly localized discovery errors; CPU/Memory
label hints; dashboard + /apps "Total workloads" count only source_kind workloads
(drop stale trigger_kind gate); NPM cert/access-list name cache; EntityPicker
empty-list guard.
- Update CLAUDE.md frontend conventions + add a Build & Test section.
Also captures pre-existing in-progress platform work (not from this session):
workload notifications, Prometheus metrics export, store lockfile, health probes,
backup hardening, and related store/webhook/scheduler changes.
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package static
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/alexei/tinyforge/internal/store"
|
|
"github.com/alexei/tinyforge/internal/workload/plugin"
|
|
)
|
|
|
|
// teardown drops every artifact deploy created: the running container,
|
|
// the proxy route, the optional storage volume, and the container
|
|
// index row. Idempotent — a workload that never deployed is a no-op.
|
|
//
|
|
// Mirrors the legacy Manager.Remove + Stop combination: stop is
|
|
// implicit in RemoveContainer(force=true), and the volume removal
|
|
// happens only when storage was opted into (the named volume is
|
|
// otherwise nonexistent and best-effort delete would log a noisy
|
|
// warning).
|
|
func teardown(ctx context.Context, deps plugin.Deps, w plugin.Workload) error {
|
|
cfg, err := plugin.SourceConfigOf[Config](w)
|
|
if err != nil {
|
|
return fmt.Errorf("static source: decode config: %w", err)
|
|
}
|
|
|
|
_, prevContainer, err := loadState(deps, w)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if prevContainer == nil {
|
|
// Nothing was ever deployed — best-effort volume cleanup in
|
|
// case storage was provisioned but the deploy crashed before
|
|
// state landed, then return.
|
|
if cfg.StorageEnabled {
|
|
if err := deps.Docker.RemoveSiteVolume(ctx, siteVolumeKey(w)); err != nil {
|
|
slog.Debug("static site: storage volume cleanup", "site", w.Name, "error", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Drop proxy route first so traffic stops landing on a container
|
|
// that is about to disappear.
|
|
if prevContainer.ProxyRouteID != "" {
|
|
if err := deps.Proxy.DeleteRoute(ctx, prevContainer.ProxyRouteID); err != nil {
|
|
slog.Warn("static site: failed to remove proxy route", "site", w.Name, "error", err)
|
|
}
|
|
}
|
|
|
|
if prevContainer.ContainerID != "" {
|
|
if err := deps.Docker.RemoveContainer(ctx, prevContainer.ContainerID, true); err != nil {
|
|
slog.Warn("static site: failed to remove container", "site", w.Name, "error", err)
|
|
}
|
|
}
|
|
|
|
if cfg.StorageEnabled {
|
|
if err := deps.Docker.RemoveSiteVolume(ctx, siteVolumeKey(w)); err != nil {
|
|
slog.Warn("static site: failed to remove storage volume", "site", w.Name, "error", err)
|
|
}
|
|
}
|
|
|
|
// Delete the container row last so a partial failure leaves enough
|
|
// state for a retry. ErrNotFound is fine.
|
|
if err := deps.Store.DeleteContainer(prevContainer.ID); err != nil && !errors.Is(err, store.ErrNotFound) {
|
|
slog.Warn("static site: failed to delete container row", "site", w.Name, "error", err)
|
|
}
|
|
// The per-workload save-mutex is reference-counted (see state.go) and
|
|
// frees itself when the last holder releases, so teardown no longer
|
|
// deletes it explicitly — doing so could race a concurrent saveState.
|
|
return nil
|
|
}
|