From f8b87a4224069ee2a9928976dda6f64a6ab124e9 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:46 +0200 Subject: [PATCH 01/32] show CPU and memory for containers on Windows Docker hosts --- collector/main.go | 93 +++++++++++---- collector/main_test.go | 109 ++++++++++++++++++ src/lib/utils/memory-support.ts | 8 +- src/routes/api/environments/test/+server.ts | 7 +- .../environments/EnvironmentModal.svelte | 2 +- tests/memory-support.test.ts | 12 ++ 6 files changed, 204 insertions(+), 27 deletions(-) create mode 100644 collector/main_test.go diff --git a/collector/main.go b/collector/main.go index afafd09df..bbf9b8abc 100644 --- a/collector/main.go +++ b/collector/main.go @@ -82,6 +82,11 @@ type containerInfo struct { } type containerStats struct { + // Read/Preread timestamps and NumProcs are used for the Windows CPU formula, + // which has no system_cpu_usage to divide by (#1574). + Read string `json:"read"` + Preread string `json:"preread"` + NumProcs uint32 `json:"num_procs"` CPUStats struct { CPUUsage struct { TotalUsage uint64 `json:"total_usage"` @@ -97,13 +102,76 @@ type containerStats struct { } `json:"precpu_stats"` MemoryStats struct { Usage uint64 `json:"usage"` - Stats struct { + // Windows reports memory as privateworkingset (already cache-free) instead + // of usage; a nil pointer means the payload is a Unix one (#1574). + PrivateWorkingSet *uint64 `json:"privateworkingset"` + Stats struct { InactiveFile uint64 `json:"inactive_file"` TotalInactiveFile uint64 `json:"total_inactive_file"` } `json:"stats"` } `json:"memory_stats"` } +// calcCPUPercent mirrors src/lib/server/stats-calc-core.ts. Unix uses the +// cpu-vs-system delta ratio; Windows has no system_cpu_usage, so it uses the +// wall-clock formula (num_procs * elapsed) - detected by privateworkingset (#1574). +func calcCPUPercent(s *containerStats) float64 { + // Compare BEFORE subtracting: uint64 underflow (precpu > cpu on a first sample + // or a counter reset) would wrap to a huge positive and slip past a >0 guard, + // producing an absurd CPU%. A non-increasing counter means no usage -> 0. + cur := s.CPUStats.CPUUsage.TotalUsage + prev := s.PrecpuStats.CPUUsage.TotalUsage + if cur <= prev { + return 0 + } + cpuDelta := float64(cur - prev) + + if s.MemoryStats.PrivateWorkingSet != nil { + read, errR := time.Parse(time.RFC3339Nano, s.Read) + preread, errP := time.Parse(time.RFC3339Nano, s.Preread) + if errR != nil || errP != nil { + return 0 + } + // possIntervals = num_procs * elapsed-MILLISECONDS; cpu% = cpuDelta / (possIntervals*100). + // Matches the Docker CLI / Portainer Windows formula and the TS core. + elapsedMs := float64(read.Sub(preread).Milliseconds()) + possIntervals := float64(s.NumProcs) * elapsedMs + if possIntervals > 0 { + return cpuDelta / (possIntervals * 100) + } + return 0 + } + + curSys := s.CPUStats.SystemCPUUsage + prevSys := s.PrecpuStats.SystemCPUUsage + if curSys <= prevSys { + return 0 + } + sysDelta := float64(curSys - prevSys) + cpuCount := s.CPUStats.OnlineCPUs + if cpuCount == 0 { + cpuCount = 1 + } + return (cpuDelta / sysDelta) * float64(cpuCount) * 100 +} + +// calcMemUsage mirrors the TS core: Windows uses privateworkingset (cache-free), +// Unix subtracts inactive-file cache from usage. +func calcMemUsage(s *containerStats) uint64 { + if s.MemoryStats.PrivateWorkingSet != nil { + return *s.MemoryStats.PrivateWorkingSet + } + memUsage := s.MemoryStats.Usage + memCache := s.MemoryStats.Stats.InactiveFile + if memCache == 0 { + memCache = s.MemoryStats.Stats.TotalInactiveFile + } + if memCache > 0 && memCache < memUsage { + return memUsage - memCache + } + return memUsage +} + type dockerInfo struct { MemTotal int64 `json:"MemTotal"` NCPU int `json:"NCPU"` @@ -496,27 +564,8 @@ func (m *manager) collectMetrics(env *environment) { return } - cpuDelta := float64(stats.CPUStats.CPUUsage.TotalUsage - stats.PrecpuStats.CPUUsage.TotalUsage) - sysDelta := float64(stats.CPUStats.SystemCPUUsage - stats.PrecpuStats.SystemCPUUsage) - cpuCount := stats.CPUStats.OnlineCPUs - if cpuCount == 0 { - cpuCount = 1 - } - - var cpuPct float64 - if sysDelta > 0 && cpuDelta > 0 { - cpuPct = (cpuDelta / sysDelta) * float64(cpuCount) * 100 - } - - memUsage := stats.MemoryStats.Usage - memCache := stats.MemoryStats.Stats.InactiveFile - if memCache == 0 { - memCache = stats.MemoryStats.Stats.TotalInactiveFile - } - actualMem := memUsage - if memCache > 0 && memCache < memUsage { - actualMem = memUsage - memCache - } + cpuPct := calcCPUPercent(&stats) + actualMem := calcMemUsage(&stats) results[idx] = statsResult{cpu: cpuPct, mem: actualMem} }(i, c.ID) diff --git a/collector/main_test.go b/collector/main_test.go new file mode 100644 index 000000000..c82a411b2 --- /dev/null +++ b/collector/main_test.go @@ -0,0 +1,109 @@ +package main + +import ( + "encoding/json" + "math" + "testing" +) + +// mustStats decodes a JSON stats payload into containerStats for the tests. +func mustStats(t *testing.T, jsonStr string) *containerStats { + t.Helper() + var s containerStats + if err := json.Unmarshal([]byte(jsonStr), &s); err != nil { + t.Fatalf("decode: %v", err) + } + return &s +} + +const unixPayload = `{ + "read": "2026-09-15T10:00:01Z", + "preread": "2026-09-15T10:00:00Z", + "cpu_stats": {"cpu_usage": {"total_usage": 2000000000}, "system_cpu_usage": 20000000000, "online_cpus": 4}, + "precpu_stats": {"cpu_usage": {"total_usage": 1000000000}, "system_cpu_usage": 18000000000}, + "memory_stats": {"usage": 209715200, "stats": {"inactive_file": 52428800}} +}` + +// Windows: no system_cpu_usage, privateworkingset present, 1000ms elapsed, 2 procs. +const windowsPayload = `{ + "read": "2026-09-15T10:00:01.0000000Z", + "preread": "2026-09-15T10:00:00.0000000Z", + "num_procs": 2, + "cpu_stats": {"cpu_usage": {"total_usage": 500000000}}, + "precpu_stats": {"cpu_usage": {"total_usage": 400000000}}, + "memory_stats": {"privateworkingset": 134217728} +}` + +func closeTo(a, b float64) bool { return math.Abs(a-b) < 1e-6 } + +func TestCalcCPUPercentUnix(t *testing.T) { + // cpuDelta=1e9, sysDelta=2e9, cpuCount=4 -> 0.5*4*100 = 200 + got := calcCPUPercent(mustStats(t, unixPayload)) + if !closeTo(got, 200) { + t.Fatalf("unix cpu: got %v want 200", got) + } +} + +func TestCalcCPUPercentWindows(t *testing.T) { + // cpuDelta=1e8, elapsed=1000ms, num_procs=2 -> possIntervals=2000 + // cpu = cpuDelta / (possIntervals*100) = 1e8/(2000*100) = 500. Matches the TS core. + got := calcCPUPercent(mustStats(t, windowsPayload)) + want := 1e8 / (2 * 1000 * 100) + if !closeTo(got, want) { + t.Fatalf("windows cpu: got %v want %v", got, want) + } + if !closeTo(got, 500) { + t.Fatalf("windows cpu: got %v want 500", got) + } + if got <= 0 { + t.Fatalf("windows cpu must be > 0 (proves the Windows branch ran, not the Unix 0)") + } +} + +func TestCalcCPUPercentWindowsZeroElapsed(t *testing.T) { + s := mustStats(t, windowsPayload) + s.Preread = s.Read // no elapsed time + if got := calcCPUPercent(s); got != 0 { + t.Fatalf("zero elapsed must be 0, got %v", got) + } +} + +func TestCalcMemUsageUnix(t *testing.T) { + // 200MiB usage - 50MiB cache = 150MiB + got := calcMemUsage(mustStats(t, unixPayload)) + if got != 150*1024*1024 { + t.Fatalf("unix mem: got %d want %d", got, 150*1024*1024) + } +} + +func TestCalcMemUsageWindows(t *testing.T) { + // privateworkingset used directly, no cache subtraction + got := calcMemUsage(mustStats(t, windowsPayload)) + if got != 128*1024*1024 { + t.Fatalf("windows mem: got %d want %d", got, 128*1024*1024) + } + if got == 0 { + t.Fatalf("windows mem must not be 0 (the #1574 symptom)") + } +} + +func TestCalcCPUPercentCounterReset(t *testing.T) { + // precpu > cpu (counter reset / first sample). uint64 subtraction would wrap to a + // huge positive; the fix must return 0, not garbage. Both Unix and Windows branches. + unixReset := mustStats(t, `{"cpu_stats":{"cpu_usage":{"total_usage":1000},"system_cpu_usage":5000,"online_cpus":2},"precpu_stats":{"cpu_usage":{"total_usage":2000},"system_cpu_usage":4000},"memory_stats":{"usage":1000}}`) + if got := calcCPUPercent(unixReset); got != 0 { + t.Fatalf("unix counter reset must be 0 (no uint64 underflow garbage), got %v", got) + } + winReset := mustStats(t, `{"read":"2026-09-15T10:00:01Z","preread":"2026-09-15T10:00:00Z","num_procs":2,"cpu_stats":{"cpu_usage":{"total_usage":1000}},"precpu_stats":{"cpu_usage":{"total_usage":2000}},"memory_stats":{"privateworkingset":1000}}`) + if got := calcCPUPercent(winReset); got != 0 { + t.Fatalf("windows counter reset must be 0, got %v", got) + } +} + +func TestCalcCPUPercentSystemCounterReset(t *testing.T) { + // cpu increases but SYSTEM counter went backwards -> sysDelta underflow guard. + s := mustStats(t, `{"cpu_stats":{"cpu_usage":{"total_usage":2000},"system_cpu_usage":4000,"online_cpus":2},"precpu_stats":{"cpu_usage":{"total_usage":1000},"system_cpu_usage":5000},"memory_stats":{"usage":1000}}`) + if got := calcCPUPercent(s); got != 0 { + t.Fatalf("system counter reset must be 0, got %v", got) + } +} diff --git a/src/lib/utils/memory-support.ts b/src/lib/utils/memory-support.ts index 1e92ad148..95f93400e 100644 --- a/src/lib/utils/memory-support.ts +++ b/src/lib/utils/memory-support.ts @@ -20,10 +20,14 @@ export interface MemorySupportInfo { * `SwapLimit` are booleans; a missing/undefined field is treated as SUPPORTED (no * warning) so an older daemon or a partial info payload never produces a false alarm. */ -export function memorySupportFromInfo(info: { MemoryLimit?: boolean; SwapLimit?: boolean } | null | undefined): MemorySupportInfo { +export function memorySupportFromInfo(info: { MemoryLimit?: boolean; SwapLimit?: boolean; OSType?: string } | null | undefined): MemorySupportInfo { const memoryLimitSupported = info?.MemoryLimit !== false; const swapLimitSupported = info?.SwapLimit !== false; - return { warn: !memoryLimitSupported, memoryLimitSupported, swapLimitSupported }; + // cgroup memory accounting is a Linux concept. A Windows daemon reports + // MemoryLimit:false but reports per-container memory fine (via privateworkingset), + // so the "enable cgroup accounting" warning is wrong there - never warn (#1574). + const warn = !memoryLimitSupported && info?.OSType !== 'windows'; + return { warn, memoryLimitSupported, swapLimitSupported }; } /** Link to the manual section explaining how to enable cgroup memory accounting. */ diff --git a/src/routes/api/environments/test/+server.ts b/src/routes/api/environments/test/+server.ts index 9703e42cb..87ac8cc44 100644 --- a/src/routes/api/environments/test/+server.ts +++ b/src/routes/api/environments/test/+server.ts @@ -59,7 +59,7 @@ function buildDockerClientConfig(config: TestConnectionRequest): DockerClientCon * description: Pass environmentId to fall back to that saved environment's stored secrets (hawserToken, tlsKey) for any secret field left blank in the body, so Test connection works when editing without re-entering the token. * body: {connectionType:string!, socketPath:string, host:string, port:integer, protocol:string, tlsCa:string, tlsCert:string, tlsKey:string, tlsSkipVerify:boolean, hawserToken:string, environmentId:integer} * body-example: {"connectionType":"socket","socketPath":"/var/run/docker.sock"} - * resp-200: {success:boolean!, info:{serverVersion:string, containers:integer, images:integer, name:string, memoryLimitSupported:boolean}, hawser:{}} + * resp-200: {success:boolean!, info:{serverVersion:string, containers:integer, images:integer, name:string, memoryLimitSupported:boolean, showMemoryWarning:boolean}, hawser:{}} * resp-200-desc: success:false with a human-readable error message is also returned as HTTP 200 (connection failures are not transport errors) * resp-400: Host is required for direct/hawser-standard connection types * resp-403: The caller cannot access the environment named by environmentId @@ -188,7 +188,10 @@ export const POST: RequestHandler = async ({ request, cookies }) => { name: info.Name, // The kernel's cgroup memory controller: false => per-container memory // shows 0 (common on Raspberry Pi). The modal warns on this at create time. - memoryLimitSupported: memSupport.memoryLimitSupported + memoryLimitSupported: memSupport.memoryLimitSupported, + // Whether to actually show the cgroup-accounting warning. False on a + // Windows daemon, where MemoryLimit is false but memory reports fine (#1574). + showMemoryWarning: memSupport.warn }, hawser: hawserInfo }); diff --git a/src/routes/settings/environments/EnvironmentModal.svelte b/src/routes/settings/environments/EnvironmentModal.svelte index 2a4690ca2..4286f33b6 100644 --- a/src/routes/settings/environments/EnvironmentModal.svelte +++ b/src/routes/settings/environments/EnvironmentModal.svelte @@ -764,7 +764,7 @@ toast.success(`Connected! Docker ${result.info.serverVersion} - ${result.info.containers} containers`); // Docker reports the kernel's cgroup memory controller is off -> container // memory will show 0. Surface it now so the user isn't left guessing. - if (result.info.memoryLimitSupported === false) memWarnOpen = true; + if (result.info.showMemoryWarning) memWarnOpen = true; } } else { toast.error(result.error || 'Connection failed'); diff --git a/tests/memory-support.test.ts b/tests/memory-support.test.ts index c6692dd23..5d206e918 100644 --- a/tests/memory-support.test.ts +++ b/tests/memory-support.test.ts @@ -26,6 +26,18 @@ describe('memorySupportFromInfo', () => { expect(r.swapLimitSupported).toBe(false); }); + it('does NOT warn on a Windows daemon even though MemoryLimit is false (#1574)', () => { + // Windows reports MemoryLimit:false but per-container memory works fine, so the + // Linux cgroup-accounting warning is wrong there. + const r = memorySupportFromInfo({ MemoryLimit: false, SwapLimit: false, OSType: 'windows' }); + expect(r.warn).toBe(false); + expect(r.memoryLimitSupported).toBe(false); // still reflects the raw flag + }); + + it('still warns on a Linux daemon with MemoryLimit false (RPi case unchanged)', () => { + expect(memorySupportFromInfo({ MemoryLimit: false, OSType: 'linux' }).warn).toBe(true); + }); + it('doc url points at the manual anchor', () => { expect(MEMORY_SUPPORT_DOC_URL).toBe('https://dockhand.pro/manual/#troubleshooting-rpi-memory'); }); From 8af79ff4c59ff42bebec867e03b51380c51b2eda Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:46 +0200 Subject: [PATCH 02/32] add user-defined tags for containers and stacks with grid grouping --- drizzle-pg/0016_add_tags.sql | 31 + drizzle-pg/meta/0016_snapshot.json | 3817 ++++++++++++++++ drizzle-pg/meta/_journal.json | 7 + drizzle/0016_add_tags.sql | 31 + drizzle/meta/0016_snapshot.json | 3976 +++++++++++++++++ drizzle/meta/_journal.json | 7 + .../components/ContainerTagsSection.svelte | 66 + src/lib/components/StackTagsSection.svelte | 63 + src/lib/components/TagChips.svelte | 37 + src/lib/components/TagEditPopover.svelte | 141 + src/lib/components/TagIconPicker.svelte | 63 + src/lib/components/TagLucideIcon.svelte | 13 + src/lib/components/data-grid/grouping-core.ts | 70 + src/lib/openapi.generated.json | 1192 ++++- src/lib/server/db.ts | 127 +- src/lib/server/db/drizzle.ts | 3 + src/lib/server/db/schema/index.ts | 38 + src/lib/server/db/schema/pg-schema.ts | 35 + src/lib/stores/settings.ts | 11 + src/lib/utils/icons.ts | 29 +- src/lib/utils/tags-core.ts | 124 + src/routes/api/container-tags/+server.ts | 28 + .../api/container-tags/[name]/+server.ts | 51 + src/routes/api/settings/general/+server.ts | 27 +- src/routes/api/stack-tags/+server.ts | 28 + src/routes/api/stacks/[name]/tags/+server.ts | 51 + src/routes/api/tags/+server.ts | 49 + src/routes/api/tags/[id]/+server.ts | 68 + .../containers/EditContainerModal.svelte | 22 +- src/routes/settings/+page.svelte | 2 +- src/routes/settings/general/GeneralTab.svelte | 124 +- src/routes/settings/labels/LabelsTab.svelte | 3 + src/routes/settings/labels/TagsManager.svelte | 219 + src/routes/stacks/GitStackModal.svelte | 140 +- src/routes/stacks/StackModal.svelte | 9 + static/openapi.json | 1192 ++++- tests/grid-grouping-core.test.ts | 77 + tests/tags-core.test.ts | 91 + 38 files changed, 11709 insertions(+), 353 deletions(-) create mode 100644 drizzle-pg/0016_add_tags.sql create mode 100644 drizzle-pg/meta/0016_snapshot.json create mode 100644 drizzle/0016_add_tags.sql create mode 100644 drizzle/meta/0016_snapshot.json create mode 100644 src/lib/components/ContainerTagsSection.svelte create mode 100644 src/lib/components/StackTagsSection.svelte create mode 100644 src/lib/components/TagChips.svelte create mode 100644 src/lib/components/TagEditPopover.svelte create mode 100644 src/lib/components/TagIconPicker.svelte create mode 100644 src/lib/components/TagLucideIcon.svelte create mode 100644 src/lib/components/data-grid/grouping-core.ts create mode 100644 src/lib/utils/tags-core.ts create mode 100644 src/routes/api/container-tags/+server.ts create mode 100644 src/routes/api/container-tags/[name]/+server.ts create mode 100644 src/routes/api/stack-tags/+server.ts create mode 100644 src/routes/api/stacks/[name]/tags/+server.ts create mode 100644 src/routes/api/tags/+server.ts create mode 100644 src/routes/api/tags/[id]/+server.ts create mode 100644 src/routes/settings/labels/TagsManager.svelte create mode 100644 tests/grid-grouping-core.test.ts create mode 100644 tests/tags-core.test.ts diff --git a/drizzle-pg/0016_add_tags.sql b/drizzle-pg/0016_add_tags.sql new file mode 100644 index 000000000..11a5a668f --- /dev/null +++ b/drizzle-pg/0016_add_tags.sql @@ -0,0 +1,31 @@ +CREATE TABLE "container_tags" ( + "id" serial PRIMARY KEY NOT NULL, + "container_name" text NOT NULL, + "environment_id" integer, + "tag_id" integer NOT NULL, + "created_at" timestamp DEFAULT now(), + CONSTRAINT "container_tags_container_name_environment_id_tag_id_unique" UNIQUE("container_name","environment_id","tag_id") +); +--> statement-breakpoint +CREATE TABLE "stack_tags" ( + "id" serial PRIMARY KEY NOT NULL, + "stack_name" text NOT NULL, + "environment_id" integer, + "tag_id" integer NOT NULL, + "created_at" timestamp DEFAULT now(), + CONSTRAINT "stack_tags_stack_name_environment_id_tag_id_unique" UNIQUE("stack_name","environment_id","tag_id") +); +--> statement-breakpoint +CREATE TABLE "tags" ( + "id" serial PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "color" text DEFAULT 'slate' NOT NULL, + "icon" text, + "created_at" timestamp DEFAULT now() +); +--> statement-breakpoint +CREATE UNIQUE INDEX "tags_name_unique" ON "tags" (lower("name"));--> statement-breakpoint +ALTER TABLE "container_tags" ADD CONSTRAINT "container_tags_environment_id_environments_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."environments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "container_tags" ADD CONSTRAINT "container_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "stack_tags" ADD CONSTRAINT "stack_tags_environment_id_environments_id_fk" FOREIGN KEY ("environment_id") REFERENCES "public"."environments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "stack_tags" ADD CONSTRAINT "stack_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/drizzle-pg/meta/0016_snapshot.json b/drizzle-pg/meta/0016_snapshot.json new file mode 100644 index 000000000..0bfb46288 --- /dev/null +++ b/drizzle-pg/meta/0016_snapshot.json @@ -0,0 +1,3817 @@ +{ + "id": "1be6c489-8ecf-4a22-b2d3-d4b871238b2e", + "prevId": "7b17f0e4-3123-4178-a85a-93c6ea6a46d5", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.api_tokens": { + "name": "api_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_used": { + "name": "last_used", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "api_tokens_user_id_idx": { + "name": "api_tokens_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_tokens_token_prefix_idx": { + "name": "api_tokens_token_prefix_idx", + "columns": [ + { + "expression": "token_prefix", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_tokens_token_hash_unique": { + "name": "api_tokens_token_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "token_hash" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_logs": { + "name": "audit_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entity_name": { + "name": "entity_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "audit_logs_user_id_idx": { + "name": "audit_logs_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_logs_created_at_idx": { + "name": "audit_logs_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "audit_logs_user_id_users_id_fk": { + "name": "audit_logs_user_id_users_id_fk", + "tableFrom": "audit_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "audit_logs_environment_id_environments_id_fk": { + "name": "audit_logs_environment_id_environments_id_fk", + "tableFrom": "audit_logs", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_settings": { + "name": "auth_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "auth_enabled": { + "name": "auth_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "default_provider": { + "name": "default_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'local'" + }, + "session_timeout": { + "name": "session_timeout", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 86400 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auto_update_settings": { + "name": "auto_update_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'daily'" + }, + "cron_expression": { + "name": "cron_expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vulnerability_criteria": { + "name": "vulnerability_criteria", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'never'" + }, + "last_checked": { + "name": "last_checked", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_updated": { + "name": "last_updated", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "auto_update_settings_environment_id_environments_id_fk": { + "name": "auto_update_settings_environment_id_environments_id_fk", + "tableFrom": "auto_update_settings", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auto_update_settings_environment_id_container_name_unique": { + "name": "auto_update_settings_environment_id_container_name_unique", + "nullsNotDistinct": false, + "columns": [ + "environment_id", + "container_name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_configs": { + "name": "backup_configs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'container'" + }, + "target_name": { + "name": "target_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "destination_id": { + "name": "destination_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "all_volumes": { + "name": "all_volumes", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "selected_volumes": { + "name": "selected_volumes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stop_before_backup": { + "name": "stop_before_backup", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "schedule": { + "name": "schedule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retention": { + "name": "retention", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "options": { + "name": "options", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_backup_at": { + "name": "last_backup_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_backup_status": { + "name": "last_backup_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "backup_configs_environment_id_environments_id_fk": { + "name": "backup_configs_environment_id_environments_id_fk", + "tableFrom": "backup_configs", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "backup_configs_destination_id_backup_destinations_id_fk": { + "name": "backup_configs_destination_id_backup_destinations_id_fk", + "tableFrom": "backup_configs", + "tableTo": "backup_destinations", + "columnsFrom": [ + "destination_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.backup_destinations": { + "name": "backup_destinations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "env_vars": { + "name": "env_vars", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "host_path": { + "name": "host_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cacert": { + "name": "cacert", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tls_client_cert": { + "name": "tls_client_cert", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "policies": { + "name": "policies", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_test_at": { + "name": "last_test_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_test_status": { + "name": "last_test_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_test_error": { + "name": "last_test_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "backup_destinations_name_unique": { + "name": "backup_destinations_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.config_sets": { + "name": "config_sets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "env_vars": { + "name": "env_vars", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ports": { + "name": "ports", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "volumes": { + "name": "volumes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "network_mode": { + "name": "network_mode", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'bridge'" + }, + "restart_policy": { + "name": "restart_policy", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'no'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "config_sets_name_unique": { + "name": "config_sets_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.container_events": { + "name": "container_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "container_id": { + "name": "container_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_attributes": { + "name": "actor_attributes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "container_events_env_timestamp_idx": { + "name": "container_events_env_timestamp_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "container_events_environment_id_environments_id_fk": { + "name": "container_events_environment_id_environments_id_fk", + "tableFrom": "container_events", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.container_icon_overrides": { + "name": "container_icon_overrides", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "container_icon_overrides_environment_id_environments_id_fk": { + "name": "container_icon_overrides_environment_id_environments_id_fk", + "tableFrom": "container_icon_overrides", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "container_icon_overrides_container_name_environment_id_unique": { + "name": "container_icon_overrides_container_name_environment_id_unique", + "nullsNotDistinct": false, + "columns": [ + "container_name", + "environment_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.container_tags": { + "name": "container_tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_id": { + "name": "tag_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "container_tags_environment_id_environments_id_fk": { + "name": "container_tags_environment_id_environments_id_fk", + "tableFrom": "container_tags", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "container_tags_tag_id_tags_id_fk": { + "name": "container_tags_tag_id_tags_id_fk", + "tableFrom": "container_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "container_tags_container_name_environment_id_tag_id_unique": { + "name": "container_tags_container_name_environment_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "container_name", + "environment_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environment_notifications": { + "name": "environment_notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "notification_id": { + "name": "notification_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "event_types": { + "name": "event_types", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "environment_notifications_environment_id_environments_id_fk": { + "name": "environment_notifications_environment_id_environments_id_fk", + "tableFrom": "environment_notifications", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environment_notifications_notification_id_notification_settings_id_fk": { + "name": "environment_notifications_notification_id_notification_settings_id_fk", + "tableFrom": "environment_notifications", + "tableTo": "notification_settings", + "columnsFrom": [ + "notification_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "environment_notifications_environment_id_notification_id_unique": { + "name": "environment_notifications_environment_id_notification_id_unique", + "nullsNotDistinct": false, + "columns": [ + "environment_id", + "notification_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.environments": { + "name": "environments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 2375 + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'http'" + }, + "tls_ca": { + "name": "tls_ca", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tls_cert": { + "name": "tls_cert", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tls_key": { + "name": "tls_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tls_skip_verify": { + "name": "tls_skip_verify", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'globe'" + }, + "collect_activity": { + "name": "collect_activity", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "collect_metrics": { + "name": "collect_metrics", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "highlight_changes": { + "name": "highlight_changes", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connection_type": { + "name": "connection_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'socket'" + }, + "socket_path": { + "name": "socket_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'/var/run/docker.sock'" + }, + "hawser_token": { + "name": "hawser_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hawser_last_seen": { + "name": "hawser_last_seen", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "hawser_agent_id": { + "name": "hawser_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hawser_agent_name": { + "name": "hawser_agent_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hawser_version": { + "name": "hawser_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hawser_capabilities": { + "name": "hawser_capabilities", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "environments_name_unique": { + "name": "environments_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.git_credentials": { + "name": "git_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ssh_private_key": { + "name": "ssh_private_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ssh_passphrase": { + "name": "ssh_passphrase", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "git_credentials_name_unique": { + "name": "git_credentials_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.git_repositories": { + "name": "git_repositories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'main'" + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'docker-compose.yml'" + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "auto_update": { + "name": "auto_update", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "auto_update_schedule": { + "name": "auto_update_schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'daily'" + }, + "auto_update_cron": { + "name": "auto_update_cron", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'0 3 * * *'" + }, + "webhook_enabled": { + "name": "webhook_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "webhook_secret": { + "name": "webhook_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync": { + "name": "last_sync", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_commit": { + "name": "last_commit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sync_status": { + "name": "sync_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "git_repositories_credential_id_git_credentials_id_fk": { + "name": "git_repositories_credential_id_git_credentials_id_fk", + "tableFrom": "git_repositories", + "tableTo": "git_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "git_repositories_name_unique": { + "name": "git_repositories_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.git_stacks": { + "name": "git_stacks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'docker-compose.yml'" + }, + "env_file_path": { + "name": "env_file_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auto_update": { + "name": "auto_update", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "auto_update_schedule": { + "name": "auto_update_schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'daily'" + }, + "auto_update_cron": { + "name": "auto_update_cron", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'0 3 * * *'" + }, + "webhook_enabled": { + "name": "webhook_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "webhook_secret": { + "name": "webhook_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "context_dir": { + "name": "context_dir", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "build_on_deploy": { + "name": "build_on_deploy", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "no_build_cache": { + "name": "no_build_cache", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "repull_images": { + "name": "repull_images", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "force_redeploy": { + "name": "force_redeploy", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "last_sync": { + "name": "last_sync", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_commit": { + "name": "last_commit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sync_status": { + "name": "sync_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "synced_files": { + "name": "synced_files", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "git_stacks_environment_id_environments_id_fk": { + "name": "git_stacks_environment_id_environments_id_fk", + "tableFrom": "git_stacks", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "git_stacks_repository_id_git_repositories_id_fk": { + "name": "git_stacks_repository_id_git_repositories_id_fk", + "tableFrom": "git_stacks", + "tableTo": "git_repositories", + "columnsFrom": [ + "repository_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "git_stacks_stack_name_environment_id_unique": { + "name": "git_stacks_stack_name_environment_id_unique", + "nullsNotDistinct": false, + "columns": [ + "stack_name", + "environment_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hawser_tokens": { + "name": "hawser_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "last_used": { + "name": "last_used", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "hawser_tokens_environment_id_environments_id_fk": { + "name": "hawser_tokens_environment_id_environments_id_fk", + "tableFrom": "hawser_tokens", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "hawser_tokens_token_unique": { + "name": "hawser_tokens_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.host_metrics": { + "name": "host_metrics", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cpu_percent": { + "name": "cpu_percent", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "memory_percent": { + "name": "memory_percent", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "memory_used": { + "name": "memory_used", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "memory_total": { + "name": "memory_total", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "host_metrics_env_timestamp_idx": { + "name": "host_metrics_env_timestamp_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "timestamp", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "host_metrics_environment_id_environments_id_fk": { + "name": "host_metrics_environment_id_environments_id_fk", + "tableFrom": "host_metrics", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ldap_config": { + "name": "ldap_config", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "server_url": { + "name": "server_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bind_dn": { + "name": "bind_dn", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bind_password": { + "name": "bind_password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "base_dn": { + "name": "base_dn", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_filter": { + "name": "user_filter", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'(uid={{username}})'" + }, + "username_attribute": { + "name": "username_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'uid'" + }, + "email_attribute": { + "name": "email_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'mail'" + }, + "display_name_attribute": { + "name": "display_name_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'cn'" + }, + "group_base_dn": { + "name": "group_base_dn", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "group_filter": { + "name": "group_filter", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "admin_group": { + "name": "admin_group", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role_mappings": { + "name": "role_mappings", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tls_enabled": { + "name": "tls_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "tls_ca": { + "name": "tls_ca", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification_settings": { + "name": "notification_settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_types": { + "name": "event_types", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oidc_config": { + "name": "oidc_config", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "issuer_url": { + "name": "issuer_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "redirect_uri": { + "name": "redirect_uri", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'openid profile email'" + }, + "username_claim": { + "name": "username_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'preferred_username'" + }, + "email_claim": { + "name": "email_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'email'" + }, + "display_name_claim": { + "name": "display_name_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'name'" + }, + "admin_claim": { + "name": "admin_claim", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "admin_value": { + "name": "admin_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role_mappings_claim": { + "name": "role_mappings_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'groups'" + }, + "role_mappings": { + "name": "role_mappings", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pending_container_updates": { + "name": "pending_container_updates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "container_id": { + "name": "container_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_image": { + "name": "current_image", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "has_image_update": { + "name": "has_image_update", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "newer_version": { + "name": "newer_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pending_container_updates_environment_id_environments_id_fk": { + "name": "pending_container_updates_environment_id_environments_id_fk", + "tableFrom": "pending_container_updates", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pending_container_updates_environment_id_container_id_unique": { + "name": "pending_container_updates_environment_id_container_id_unique", + "nullsNotDistinct": false, + "columns": [ + "environment_id", + "container_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.registries": { + "name": "registries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "registries_name_unique": { + "name": "registries_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_system": { + "name": "is_system", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_ids": { + "name": "environment_ids", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "roles_name_unique": { + "name": "roles_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.schedule_executions": { + "name": "schedule_executions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schedule_id": { + "name": "schedule_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "entity_name": { + "name": "entity_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "triggered_by": { + "name": "triggered_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "triggered_at": { + "name": "triggered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "duration": { + "name": "duration", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "logs": { + "name": "logs", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "schedule_executions_type_id_idx": { + "name": "schedule_executions_type_id_idx", + "columns": [ + { + "expression": "schedule_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "schedule_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "schedule_executions_entity_env_idx": { + "name": "schedule_executions_entity_env_idx", + "columns": [ + { + "expression": "entity_name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "schedule_executions_environment_id_environments_id_fk": { + "name": "schedule_executions_environment_id_environments_id_fk", + "tableFrom": "schedule_executions", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.secret_providers": { + "name": "secret_providers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "secret_providers_name_unique": { + "name": "secret_providers_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "sessions_user_id_idx": { + "name": "sessions_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_expires_at_idx": { + "name": "sessions_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stack_environment_variables": { + "name": "stack_environment_variables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_secret": { + "name": "is_secret", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "stack_environment_variables_environment_id_environments_id_fk": { + "name": "stack_environment_variables_environment_id_environments_id_fk", + "tableFrom": "stack_environment_variables", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "stack_environment_variables_stack_name_environment_id_key_unique": { + "name": "stack_environment_variables_stack_name_environment_id_key_unique", + "nullsNotDistinct": false, + "columns": [ + "stack_name", + "environment_id", + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stack_events": { + "name": "stack_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "stack_events_environment_id_environments_id_fk": { + "name": "stack_events_environment_id_environments_id_fk", + "tableFrom": "stack_events", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stack_sources": { + "name": "stack_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "source_type": { + "name": "source_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'internal'" + }, + "git_repository_id": { + "name": "git_repository_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "git_stack_id": { + "name": "git_stack_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "env_path": { + "name": "env_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "secret_provider_id": { + "name": "secret_provider_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "injected_secret_keys": { + "name": "injected_secret_keys", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "stack_sources_environment_id_environments_id_fk": { + "name": "stack_sources_environment_id_environments_id_fk", + "tableFrom": "stack_sources", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stack_sources_git_repository_id_git_repositories_id_fk": { + "name": "stack_sources_git_repository_id_git_repositories_id_fk", + "tableFrom": "stack_sources", + "tableTo": "git_repositories", + "columnsFrom": [ + "git_repository_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stack_sources_git_stack_id_git_stacks_id_fk": { + "name": "stack_sources_git_stack_id_git_stacks_id_fk", + "tableFrom": "stack_sources", + "tableTo": "git_stacks", + "columnsFrom": [ + "git_stack_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stack_sources_secret_provider_id_secret_providers_id_fk": { + "name": "stack_sources_secret_provider_id_secret_providers_id_fk", + "tableFrom": "stack_sources", + "tableTo": "secret_providers", + "columnsFrom": [ + "secret_provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "stack_sources_stack_name_environment_id_unique": { + "name": "stack_sources_stack_name_environment_id_unique", + "nullsNotDistinct": false, + "columns": [ + "stack_name", + "environment_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.stack_tags": { + "name": "stack_tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_id": { + "name": "tag_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "stack_tags_environment_id_environments_id_fk": { + "name": "stack_tags_environment_id_environments_id_fk", + "tableFrom": "stack_tags", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stack_tags_tag_id_tags_id_fk": { + "name": "stack_tags_tag_id_tags_id_fk", + "tableFrom": "stack_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "stack_tags_stack_name_environment_id_tag_id_unique": { + "name": "stack_tags_stack_name_environment_id_tag_id_unique", + "nullsNotDistinct": false, + "columns": [ + "stack_name", + "environment_id", + "tag_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'slate'" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tags_name_unique": { + "name": "tags_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.template_sources": { + "name": "template_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "builtin": { + "name": "builtin", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "template_sources_source_id_unique": { + "name": "template_sources_source_id_unique", + "nullsNotDistinct": false, + "columns": [ + "source_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_preferences": { + "name": "user_preferences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_preferences_user_id_users_id_fk": { + "name": "user_preferences_user_id_users_id_fk", + "tableFrom": "user_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_preferences_environment_id_environments_id_fk": { + "name": "user_preferences_environment_id_environments_id_fk", + "tableFrom": "user_preferences", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_preferences_user_id_environment_id_key_unique": { + "name": "user_preferences_user_id_environment_id_key_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id", + "environment_id", + "key" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_environment_id_environments_id_fk": { + "name": "user_roles_environment_id_environments_id_fk", + "tableFrom": "user_roles", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_roles_user_id_role_id_environment_id_unique": { + "name": "user_roles_user_id_role_id_environment_id_unique", + "nullsNotDistinct": false, + "columns": [ + "user_id", + "role_id", + "environment_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_provider": { + "name": "auth_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'local'" + }, + "mfa_enabled": { + "name": "mfa_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "mfa_secret": { + "name": "mfa_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "last_login": { + "name": "last_login", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vulnerability_scans": { + "name": "vulnerability_scans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image_name": { + "name": "image_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scanner": { + "name": "scanner", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scanned_at": { + "name": "scanned_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "scan_duration": { + "name": "scan_duration", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "critical_count": { + "name": "critical_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "high_count": { + "name": "high_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "medium_count": { + "name": "medium_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "low_count": { + "name": "low_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "negligible_count": { + "name": "negligible_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "unknown_count": { + "name": "unknown_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "vulnerabilities": { + "name": "vulnerabilities", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "vulnerability_scans_env_image_idx": { + "name": "vulnerability_scans_env_image_idx", + "columns": [ + { + "expression": "environment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "image_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vulnerability_scans_environment_id_environments_id_fk": { + "name": "vulnerability_scans_environment_id_environments_id_fk", + "tableFrom": "vulnerability_scans", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle-pg/meta/_journal.json b/drizzle-pg/meta/_journal.json index 15869d271..535ead793 100644 --- a/drizzle-pg/meta/_journal.json +++ b/drizzle-pg/meta/_journal.json @@ -113,6 +113,13 @@ "when": 1788099526949, "tag": "0015_deploy_run_index", "breakpoints": true + }, + { + "idx": 16, + "version": "7", + "when": 1789748940854, + "tag": "0016_add_tags", + "breakpoints": true } ] } \ No newline at end of file diff --git a/drizzle/0016_add_tags.sql b/drizzle/0016_add_tags.sql new file mode 100644 index 000000000..6342bacfd --- /dev/null +++ b/drizzle/0016_add_tags.sql @@ -0,0 +1,31 @@ +CREATE TABLE `container_tags` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `container_name` text NOT NULL, + `environment_id` integer, + `tag_id` integer NOT NULL, + `created_at` text DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`environment_id`) REFERENCES `environments`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `container_tags_container_name_environment_id_tag_id_unique` ON `container_tags` (`container_name`,`environment_id`,`tag_id`);--> statement-breakpoint +CREATE TABLE `stack_tags` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `stack_name` text NOT NULL, + `environment_id` integer, + `tag_id` integer NOT NULL, + `created_at` text DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`environment_id`) REFERENCES `environments`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `stack_tags_stack_name_environment_id_tag_id_unique` ON `stack_tags` (`stack_name`,`environment_id`,`tag_id`);--> statement-breakpoint +CREATE TABLE `tags` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL, + `color` text DEFAULT 'slate' NOT NULL, + `icon` text, + `created_at` text DEFAULT CURRENT_TIMESTAMP +); +--> statement-breakpoint +CREATE UNIQUE INDEX `tags_name_unique` ON `tags` (`name` COLLATE NOCASE); \ No newline at end of file diff --git a/drizzle/meta/0016_snapshot.json b/drizzle/meta/0016_snapshot.json new file mode 100644 index 000000000..663ddf414 --- /dev/null +++ b/drizzle/meta/0016_snapshot.json @@ -0,0 +1,3976 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "730cf06b-a48f-46c9-8c0e-41a1433264fb", + "prevId": "015e998b-f154-417d-9122-eef38fca253c", + "tables": { + "api_tokens": { + "name": "api_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_used": { + "name": "last_used", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "api_tokens_token_hash_unique": { + "name": "api_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + }, + "api_tokens_user_id_idx": { + "name": "api_tokens_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "api_tokens_token_prefix_idx": { + "name": "api_tokens_token_prefix_idx", + "columns": [ + "token_prefix" + ], + "isUnique": false + } + }, + "foreignKeys": { + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "audit_logs": { + "name": "audit_logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "entity_name": { + "name": "entity_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "audit_logs_user_id_idx": { + "name": "audit_logs_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "audit_logs_created_at_idx": { + "name": "audit_logs_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "audit_logs_user_id_users_id_fk": { + "name": "audit_logs_user_id_users_id_fk", + "tableFrom": "audit_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "audit_logs_environment_id_environments_id_fk": { + "name": "audit_logs_environment_id_environments_id_fk", + "tableFrom": "audit_logs", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "auth_settings": { + "name": "auth_settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "auth_enabled": { + "name": "auth_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "default_provider": { + "name": "default_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'local'" + }, + "session_timeout": { + "name": "session_timeout", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 86400 + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "auto_update_settings": { + "name": "auto_update_settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'daily'" + }, + "cron_expression": { + "name": "cron_expression", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "vulnerability_criteria": { + "name": "vulnerability_criteria", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'never'" + }, + "last_checked": { + "name": "last_checked", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_updated": { + "name": "last_updated", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "auto_update_settings_environment_id_container_name_unique": { + "name": "auto_update_settings_environment_id_container_name_unique", + "columns": [ + "environment_id", + "container_name" + ], + "isUnique": true + } + }, + "foreignKeys": { + "auto_update_settings_environment_id_environments_id_fk": { + "name": "auto_update_settings_environment_id_environments_id_fk", + "tableFrom": "auto_update_settings", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "backup_configs": { + "name": "backup_configs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'container'" + }, + "target_name": { + "name": "target_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "destination_id": { + "name": "destination_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "all_volumes": { + "name": "all_volumes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "selected_volumes": { + "name": "selected_volumes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stop_before_backup": { + "name": "stop_before_backup", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "schedule": { + "name": "schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "retention": { + "name": "retention", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "options": { + "name": "options", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_backup_at": { + "name": "last_backup_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_backup_status": { + "name": "last_backup_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "backup_configs_environment_id_environments_id_fk": { + "name": "backup_configs_environment_id_environments_id_fk", + "tableFrom": "backup_configs", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "backup_configs_destination_id_backup_destinations_id_fk": { + "name": "backup_configs_destination_id_backup_destinations_id_fk", + "tableFrom": "backup_configs", + "tableTo": "backup_destinations", + "columnsFrom": [ + "destination_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "backup_destinations": { + "name": "backup_destinations", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "repository": { + "name": "repository", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "env_vars": { + "name": "env_vars", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "flags": { + "name": "flags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_path": { + "name": "host_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cacert": { + "name": "cacert", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tls_client_cert": { + "name": "tls_client_cert", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "policies": { + "name": "policies", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_test_at": { + "name": "last_test_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_test_status": { + "name": "last_test_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_test_error": { + "name": "last_test_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "backup_destinations_name_unique": { + "name": "backup_destinations_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "config_sets": { + "name": "config_sets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "env_vars": { + "name": "env_vars", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ports": { + "name": "ports", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "volumes": { + "name": "volumes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "network_mode": { + "name": "network_mode", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'bridge'" + }, + "restart_policy": { + "name": "restart_policy", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'no'" + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "config_sets_name_unique": { + "name": "config_sets_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "container_events": { + "name": "container_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "container_id": { + "name": "container_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "actor_attributes": { + "name": "actor_attributes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "container_events_env_timestamp_idx": { + "name": "container_events_env_timestamp_idx", + "columns": [ + "environment_id", + "timestamp" + ], + "isUnique": false + } + }, + "foreignKeys": { + "container_events_environment_id_environments_id_fk": { + "name": "container_events_environment_id_environments_id_fk", + "tableFrom": "container_events", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "container_icon_overrides": { + "name": "container_icon_overrides", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "container_icon_overrides_container_name_environment_id_unique": { + "name": "container_icon_overrides_container_name_environment_id_unique", + "columns": [ + "container_name", + "environment_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "container_icon_overrides_environment_id_environments_id_fk": { + "name": "container_icon_overrides_environment_id_environments_id_fk", + "tableFrom": "container_icon_overrides", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "container_tags": { + "name": "container_tags", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag_id": { + "name": "tag_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "container_tags_container_name_environment_id_tag_id_unique": { + "name": "container_tags_container_name_environment_id_tag_id_unique", + "columns": [ + "container_name", + "environment_id", + "tag_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "container_tags_environment_id_environments_id_fk": { + "name": "container_tags_environment_id_environments_id_fk", + "tableFrom": "container_tags", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "container_tags_tag_id_tags_id_fk": { + "name": "container_tags_tag_id_tags_id_fk", + "tableFrom": "container_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "environment_notifications": { + "name": "environment_notifications", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "notification_id": { + "name": "notification_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "event_types": { + "name": "event_types", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "environment_notifications_environment_id_notification_id_unique": { + "name": "environment_notifications_environment_id_notification_id_unique", + "columns": [ + "environment_id", + "notification_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "environment_notifications_environment_id_environments_id_fk": { + "name": "environment_notifications_environment_id_environments_id_fk", + "tableFrom": "environment_notifications", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "environment_notifications_notification_id_notification_settings_id_fk": { + "name": "environment_notifications_notification_id_notification_settings_id_fk", + "tableFrom": "environment_notifications", + "tableTo": "notification_settings", + "columnsFrom": [ + "notification_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "environments": { + "name": "environments", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 2375 + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'http'" + }, + "tls_ca": { + "name": "tls_ca", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tls_cert": { + "name": "tls_cert", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tls_key": { + "name": "tls_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tls_skip_verify": { + "name": "tls_skip_verify", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'globe'" + }, + "collect_activity": { + "name": "collect_activity", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "collect_metrics": { + "name": "collect_metrics", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "highlight_changes": { + "name": "highlight_changes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "connection_type": { + "name": "connection_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'socket'" + }, + "socket_path": { + "name": "socket_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'/var/run/docker.sock'" + }, + "hawser_token": { + "name": "hawser_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hawser_last_seen": { + "name": "hawser_last_seen", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hawser_agent_id": { + "name": "hawser_agent_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hawser_agent_name": { + "name": "hawser_agent_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hawser_version": { + "name": "hawser_version", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hawser_capabilities": { + "name": "hawser_capabilities", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "environments_name_unique": { + "name": "environments_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "git_credentials": { + "name": "git_credentials", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'none'" + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ssh_private_key": { + "name": "ssh_private_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ssh_passphrase": { + "name": "ssh_passphrase", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "git_credentials_name_unique": { + "name": "git_credentials_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "git_repositories": { + "name": "git_repositories", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'main'" + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'docker-compose.yml'" + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auto_update": { + "name": "auto_update", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "auto_update_schedule": { + "name": "auto_update_schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'daily'" + }, + "auto_update_cron": { + "name": "auto_update_cron", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'0 3 * * *'" + }, + "webhook_enabled": { + "name": "webhook_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "webhook_secret": { + "name": "webhook_secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_sync": { + "name": "last_sync", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_commit": { + "name": "last_commit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_status": { + "name": "sync_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'pending'" + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "git_repositories_name_unique": { + "name": "git_repositories_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": { + "git_repositories_credential_id_git_credentials_id_fk": { + "name": "git_repositories_credential_id_git_credentials_id_fk", + "tableFrom": "git_repositories", + "tableTo": "git_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "git_stacks": { + "name": "git_stacks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "repository_id": { + "name": "repository_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'docker-compose.yml'" + }, + "env_file_path": { + "name": "env_file_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auto_update": { + "name": "auto_update", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "auto_update_schedule": { + "name": "auto_update_schedule", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'daily'" + }, + "auto_update_cron": { + "name": "auto_update_cron", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'0 3 * * *'" + }, + "webhook_enabled": { + "name": "webhook_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "webhook_secret": { + "name": "webhook_secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "context_dir": { + "name": "context_dir", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "build_on_deploy": { + "name": "build_on_deploy", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "no_build_cache": { + "name": "no_build_cache", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "repull_images": { + "name": "repull_images", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "force_redeploy": { + "name": "force_redeploy", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "last_sync": { + "name": "last_sync", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_commit": { + "name": "last_commit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_status": { + "name": "sync_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'pending'" + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "synced_files": { + "name": "synced_files", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "git_stacks_stack_name_environment_id_unique": { + "name": "git_stacks_stack_name_environment_id_unique", + "columns": [ + "stack_name", + "environment_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "git_stacks_environment_id_environments_id_fk": { + "name": "git_stacks_environment_id_environments_id_fk", + "tableFrom": "git_stacks", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "git_stacks_repository_id_git_repositories_id_fk": { + "name": "git_stacks_repository_id_git_repositories_id_fk", + "tableFrom": "git_stacks", + "tableTo": "git_repositories", + "columnsFrom": [ + "repository_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "hawser_tokens": { + "name": "hawser_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_active": { + "name": "is_active", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "last_used": { + "name": "last_used", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "hawser_tokens_token_unique": { + "name": "hawser_tokens_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "hawser_tokens_environment_id_environments_id_fk": { + "name": "hawser_tokens_environment_id_environments_id_fk", + "tableFrom": "hawser_tokens", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "host_metrics": { + "name": "host_metrics", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_percent": { + "name": "cpu_percent", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "memory_percent": { + "name": "memory_percent", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "memory_used": { + "name": "memory_used", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "memory_total": { + "name": "memory_total", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "host_metrics_env_timestamp_idx": { + "name": "host_metrics_env_timestamp_idx", + "columns": [ + "environment_id", + "timestamp" + ], + "isUnique": false + } + }, + "foreignKeys": { + "host_metrics_environment_id_environments_id_fk": { + "name": "host_metrics_environment_id_environments_id_fk", + "tableFrom": "host_metrics", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ldap_config": { + "name": "ldap_config", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "server_url": { + "name": "server_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "bind_dn": { + "name": "bind_dn", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bind_password": { + "name": "bind_password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "base_dn": { + "name": "base_dn", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_filter": { + "name": "user_filter", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'(uid={{username}})'" + }, + "username_attribute": { + "name": "username_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'uid'" + }, + "email_attribute": { + "name": "email_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'mail'" + }, + "display_name_attribute": { + "name": "display_name_attribute", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'cn'" + }, + "group_base_dn": { + "name": "group_base_dn", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "group_filter": { + "name": "group_filter", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "admin_group": { + "name": "admin_group", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role_mappings": { + "name": "role_mappings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tls_enabled": { + "name": "tls_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "tls_ca": { + "name": "tls_ca", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "notification_settings": { + "name": "notification_settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "event_types": { + "name": "event_types", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oidc_config": { + "name": "oidc_config", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "issuer_url": { + "name": "issuer_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirect_uri": { + "name": "redirect_uri", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'openid profile email'" + }, + "username_claim": { + "name": "username_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'preferred_username'" + }, + "email_claim": { + "name": "email_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'email'" + }, + "display_name_claim": { + "name": "display_name_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'name'" + }, + "admin_claim": { + "name": "admin_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "admin_value": { + "name": "admin_value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role_mappings_claim": { + "name": "role_mappings_claim", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'groups'" + }, + "role_mappings": { + "name": "role_mappings", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "pending_container_updates": { + "name": "pending_container_updates", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "container_id": { + "name": "container_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "current_image": { + "name": "current_image", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "has_image_update": { + "name": "has_image_update", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "newer_version": { + "name": "newer_version", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checked_at": { + "name": "checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "pending_container_updates_environment_id_container_id_unique": { + "name": "pending_container_updates_environment_id_container_id_unique", + "columns": [ + "environment_id", + "container_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "pending_container_updates_environment_id_environments_id_fk": { + "name": "pending_container_updates_environment_id_environments_id_fk", + "tableFrom": "pending_container_updates", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "registries": { + "name": "registries", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_default": { + "name": "is_default", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "registries_name_unique": { + "name": "registries_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "roles": { + "name": "roles", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_system": { + "name": "is_system", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_ids": { + "name": "environment_ids", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "roles_name_unique": { + "name": "roles_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "schedule_executions": { + "name": "schedule_executions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_id": { + "name": "schedule_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "entity_name": { + "name": "entity_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "triggered_by": { + "name": "triggered_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "triggered_at": { + "name": "triggered_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "duration": { + "name": "duration", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "logs": { + "name": "logs", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "schedule_executions_type_id_idx": { + "name": "schedule_executions_type_id_idx", + "columns": [ + "schedule_type", + "schedule_id" + ], + "isUnique": false + }, + "schedule_executions_entity_env_idx": { + "name": "schedule_executions_entity_env_idx", + "columns": [ + "entity_name", + "environment_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "schedule_executions_environment_id_environments_id_fk": { + "name": "schedule_executions_environment_id_environments_id_fk", + "tableFrom": "schedule_executions", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "secret_providers": { + "name": "secret_providers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "secret_providers_name_unique": { + "name": "secret_providers_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "sessions": { + "name": "sessions", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "sessions_user_id_idx": { + "name": "sessions_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "sessions_expires_at_idx": { + "name": "sessions_expires_at_idx", + "columns": [ + "expires_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "stack_environment_variables": { + "name": "stack_environment_variables", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "is_secret": { + "name": "is_secret", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "stack_environment_variables_stack_name_environment_id_key_unique": { + "name": "stack_environment_variables_stack_name_environment_id_key_unique", + "columns": [ + "stack_name", + "environment_id", + "key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "stack_environment_variables_environment_id_environments_id_fk": { + "name": "stack_environment_variables_environment_id_environments_id_fk", + "tableFrom": "stack_environment_variables", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "stack_events": { + "name": "stack_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "stack_events_environment_id_environments_id_fk": { + "name": "stack_events_environment_id_environments_id_fk", + "tableFrom": "stack_events", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "stack_sources": { + "name": "stack_sources", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_type": { + "name": "source_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'internal'" + }, + "git_repository_id": { + "name": "git_repository_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "git_stack_id": { + "name": "git_stack_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "compose_path": { + "name": "compose_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "env_path": { + "name": "env_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "secret_provider_id": { + "name": "secret_provider_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "injected_secret_keys": { + "name": "injected_secret_keys", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "stack_sources_stack_name_environment_id_unique": { + "name": "stack_sources_stack_name_environment_id_unique", + "columns": [ + "stack_name", + "environment_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "stack_sources_environment_id_environments_id_fk": { + "name": "stack_sources_environment_id_environments_id_fk", + "tableFrom": "stack_sources", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stack_sources_git_repository_id_git_repositories_id_fk": { + "name": "stack_sources_git_repository_id_git_repositories_id_fk", + "tableFrom": "stack_sources", + "tableTo": "git_repositories", + "columnsFrom": [ + "git_repository_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stack_sources_git_stack_id_git_stacks_id_fk": { + "name": "stack_sources_git_stack_id_git_stacks_id_fk", + "tableFrom": "stack_sources", + "tableTo": "git_stacks", + "columnsFrom": [ + "git_stack_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "stack_sources_secret_provider_id_secret_providers_id_fk": { + "name": "stack_sources_secret_provider_id_secret_providers_id_fk", + "tableFrom": "stack_sources", + "tableTo": "secret_providers", + "columnsFrom": [ + "secret_provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "stack_tags": { + "name": "stack_tags", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "stack_name": { + "name": "stack_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag_id": { + "name": "tag_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "stack_tags_stack_name_environment_id_tag_id_unique": { + "name": "stack_tags_stack_name_environment_id_tag_id_unique", + "columns": [ + "stack_name", + "environment_id", + "tag_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "stack_tags_environment_id_environments_id_fk": { + "name": "stack_tags_environment_id_environments_id_fk", + "tableFrom": "stack_tags", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "stack_tags_tag_id_tags_id_fk": { + "name": "stack_tags_tag_id_tags_id_fk", + "tableFrom": "stack_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tags": { + "name": "tags", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'slate'" + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "tags_name_unique": { + "name": "tags_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "template_sources": { + "name": "template_sources", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "source_id": { + "name": "source_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "builtin": { + "name": "builtin", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "template_sources_source_id_unique": { + "name": "template_sources_source_id_unique", + "columns": [ + "source_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_preferences": { + "name": "user_preferences", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "user_preferences_user_id_environment_id_key_unique": { + "name": "user_preferences_user_id_environment_id_key_unique", + "columns": [ + "user_id", + "environment_id", + "key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "user_preferences_user_id_users_id_fk": { + "name": "user_preferences_user_id_users_id_fk", + "tableFrom": "user_preferences", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_preferences_environment_id_environments_id_fk": { + "name": "user_preferences_environment_id_environments_id_fk", + "tableFrom": "user_preferences", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_roles": { + "name": "user_roles", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "user_roles_user_id_role_id_environment_id_unique": { + "name": "user_roles_user_id_role_id_environment_id_unique", + "columns": [ + "user_id", + "role_id", + "environment_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_environment_id_environments_id_fk": { + "name": "user_roles_environment_id_environments_id_fk", + "tableFrom": "user_roles", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auth_provider": { + "name": "auth_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'local'" + }, + "mfa_enabled": { + "name": "mfa_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + }, + "mfa_secret": { + "name": "mfa_secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_active": { + "name": "is_active", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": true + }, + "last_login": { + "name": "last_login", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "users_username_unique": { + "name": "users_username_unique", + "columns": [ + "username" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "vulnerability_scans": { + "name": "vulnerability_scans", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "environment_id": { + "name": "environment_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "image_name": { + "name": "image_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scanner": { + "name": "scanner", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scanned_at": { + "name": "scanned_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scan_duration": { + "name": "scan_duration", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "critical_count": { + "name": "critical_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "high_count": { + "name": "high_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "medium_count": { + "name": "medium_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "low_count": { + "name": "low_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "negligible_count": { + "name": "negligible_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "unknown_count": { + "name": "unknown_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "vulnerabilities": { + "name": "vulnerabilities", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "vulnerability_scans_env_image_idx": { + "name": "vulnerability_scans_env_image_idx", + "columns": [ + "environment_id", + "image_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "vulnerability_scans_environment_id_environments_id_fk": { + "name": "vulnerability_scans_environment_id_environments_id_fk", + "tableFrom": "vulnerability_scans", + "tableTo": "environments", + "columnsFrom": [ + "environment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 44367adb7..efb919e4c 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -113,6 +113,13 @@ "when": 1788099517358, "tag": "0015_deploy_run_index", "breakpoints": true + }, + { + "idx": 16, + "version": "6", + "when": 1789748940121, + "tag": "0016_add_tags", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/lib/components/ContainerTagsSection.svelte b/src/lib/components/ContainerTagsSection.svelte new file mode 100644 index 000000000..4c287cf26 --- /dev/null +++ b/src/lib/components/ContainerTagsSection.svelte @@ -0,0 +1,66 @@ + + +
+ apply(assigned.filter((id) => id !== t.id))} /> + + {#if assignedTags.length === 0} + {emptyHint} + {/if} +
diff --git a/src/lib/components/StackTagsSection.svelte b/src/lib/components/StackTagsSection.svelte new file mode 100644 index 000000000..c808c7082 --- /dev/null +++ b/src/lib/components/StackTagsSection.svelte @@ -0,0 +1,63 @@ + + +
+ apply(assigned.filter((id) => id !== t.id))} /> + +
diff --git a/src/lib/components/TagChips.svelte b/src/lib/components/TagChips.svelte new file mode 100644 index 000000000..4d4426246 --- /dev/null +++ b/src/lib/components/TagChips.svelte @@ -0,0 +1,37 @@ + + +{#if tags.length} +
+ {#each tags as tag (tag.id)} + {@const hex = tagHex(tag.color)} + + {#if tag.icon} + + {:else} + + {/if} + {tag.name} + {#if onRemove} + + {/if} + + {/each} +
+{/if} diff --git a/src/lib/components/TagEditPopover.svelte b/src/lib/components/TagEditPopover.svelte new file mode 100644 index 000000000..a62a20f10 --- /dev/null +++ b/src/lib/components/TagEditPopover.svelte @@ -0,0 +1,141 @@ + + + + + {#snippet child({ props })} + + {/snippet} + + + { if (e.key === 'Enter' && canCreate) create(); }} /> + + {#if canCreate} + {@const hex = tagHex(newColor)} +
+
Create new tag
+ +
+ + {#if newIcon}{:else}{/if} + {normalizeTag(query)} + +
+
+ {#each TAG_COLORS as c} + + {/each} +
+ +
+ +
+ + {#each iconResults as ic (ic)} + + {/each} +
+
+ +
+ {/if} + +
+ {#if filtered.length === 0 && !canCreate} +
No tags
+ {/if} + {#each filtered as tag (tag.id)} + {@const isSel = selected.includes(tag.id)} + + {/each} +
+
+
diff --git a/src/lib/components/TagIconPicker.svelte b/src/lib/components/TagIconPicker.svelte new file mode 100644 index 000000000..1d6d978ae --- /dev/null +++ b/src/lib/components/TagIconPicker.svelte @@ -0,0 +1,63 @@ + + + + + {#snippet child({ props })} + + {/snippet} + + + +
+ + {#each results as ic (ic)} + + {/each} +
+
+
diff --git a/src/lib/components/TagLucideIcon.svelte b/src/lib/components/TagLucideIcon.svelte new file mode 100644 index 000000000..e1ee51c9d --- /dev/null +++ b/src/lib/components/TagLucideIcon.svelte @@ -0,0 +1,13 @@ + + + diff --git a/src/lib/components/data-grid/grouping-core.ts b/src/lib/components/data-grid/grouping-core.ts new file mode 100644 index 000000000..4564dae8d --- /dev/null +++ b/src/lib/components/data-grid/grouping-core.ts @@ -0,0 +1,70 @@ +// Pure grouping logic for the DataGrid. Kept import-light + unit-tested so the +// grid component stays glue. A row's group descriptor is supplied by the caller +// (e.g. containers group by their tag combination); this module only partitions +// and orders, it does not know about tags. + +/** What `groupBy(item)` returns for one row. `null` = ungrouped (the trailing group). */ +export interface GroupDescriptor { + /** Stable identity of the group (rows with the same key share a group). */ + key: string; + /** Human label shown in the header. */ + label: string; + /** Optional accent colour (hex) for the header + left band. */ + color?: string | null; + /** Optional icon names shown in the header (e.g. one per tag in the combo). */ + icons?: (string | null)[]; + /** + * Sort weight for ordering groups against each other. Lower comes first. + * Ungrouped rows use +Infinity so they always trail. Defaults to 0. + */ + order?: number; +} + +export interface DataGridGroup { + key: string; + label: string; + color: string | null; + icons: (string | null)[]; + items: T[]; +} + +/** Sentinel key for the "no group" bucket (rows whose groupBy returned null). */ +export const UNGROUPED_KEY = '__ungrouped__'; + +/** + * Partition `data` into ordered groups. Row order WITHIN a group is preserved + * (the caller pre-sorts `data`), so grouping composes with column sorting. + * Group order: by `order` weight, then first-appearance, so it is stable and + * independent of object identity. The ungrouped bucket always trails. + */ +export function groupData( + data: T[], + groupBy: (item: T) => GroupDescriptor | null, + ungroupedLabel = 'Untagged' +): DataGridGroup[] { + const groups = new Map & { order: number; seq: number }>(); + let seq = 0; + + for (const item of data) { + const desc = groupBy(item); + const key = desc ? desc.key : UNGROUPED_KEY; + let g = groups.get(key); + if (!g) { + g = { + key, + label: desc ? desc.label : ungroupedLabel, + color: desc?.color ?? null, + icons: desc?.icons ?? [], + items: [], + order: desc ? (desc.order ?? 0) : Number.POSITIVE_INFINITY, + seq: seq++ + }; + groups.set(key, g); + } + g.items.push(item); + } + + return [...groups.values()] + .sort((a, b) => a.order - b.order || a.seq - b.seq) + .map(({ order: _order, seq: _seq, ...g }) => g); +} diff --git a/src/lib/openapi.generated.json b/src/lib/openapi.generated.json index ae4621899..134146e4d 100644 --- a/src/lib/openapi.generated.json +++ b/src/lib/openapi.generated.json @@ -38,6 +38,9 @@ { "name": "container-icons" }, + { + "name": "container-tags" + }, { "name": "containers" }, @@ -131,12 +134,18 @@ { "name": "settings" }, + { + "name": "stack-tags" + }, { "name": "stacks" }, { "name": "system" }, + { + "name": "tags" + }, { "name": "templates" }, @@ -6375,6 +6384,206 @@ ] } }, + "/api/container-tags": { + "get": { + "operationId": "get_api_container-tags", + "tags": [ + "container-tags" + ], + "summary": "List all container tag assignments for an environment as a name -> tagIds map", + "parameters": [ + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "A JSON object mapping container name to its array of tag ids" + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "description": "Returns every container that has tags assigned in the given environment, so the containers list can render and filter by tag in one request instead of one lookup per row." + } + }, + "/api/container-tags/{name}": { + "get": { + "operationId": "get_api_container-tags_name", + "tags": [ + "container-tags" + ], + "summary": "Get the tag ids assigned to one container (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "put": { + "operationId": "put_api_container-tags_name", + "tags": [ + "container-tags" + ], + "summary": "Replace the tag ids assigned to one container (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:edit)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + } + } + }, "/api/containers": { "get": { "operationId": "get_api_containers", @@ -6646,11 +6855,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6695,11 +6904,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "force", @@ -6773,11 +6982,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6848,11 +7057,11 @@ { "name": "envId", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6941,13 +7150,13 @@ } } }, - "/api/containers/{id}/files": { - "get": { - "operationId": "get_api_containers_id_files", + "/api/containers/{id}/exec/run": { + "post": { + "operationId": "post_api_containers_id_exec_run", "tags": [ "containers" ], - "summary": "List the contents of a directory inside a container's filesystem", + "summary": "Run a finite command in a container and wait for the result, returning stdout, stderr and the exit code (a non-interactive alternative to the terminal exec endpoint). Intended for short commands - the request is bounded by a ~30s ceiling on remote (Hawser/TCP) environments; use the interactive terminal for long-running work.", "parameters": [ { "name": "id", @@ -6959,45 +7168,58 @@ "description": "Container ID or name (from GET /api/containers)" }, { - "name": "env", + "name": "envId", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" - }, - { - "name": "path", - "in": "query", - "required": false, - "schema": { - "type": "string" - }, - "description": "Absolute directory path inside the container (default \"/\")" - }, - { - "name": "simpleLs", - "in": "query", - "required": false, - "schema": { - "type": "boolean" - }, - "description": "Use a lightweight `ls` listing instead of a full stat of each entry" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { "200": { - "description": "Directory listing (entries with name, type, size and permission metadata)" + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "stdout": { + "type": "string" + }, + "stderr": { + "type": "string" + }, + "exitCode": { + "type": "integer" + } + }, + "required": [ + "stdout", + "stderr", + "exitCode" + ] + }, + "example": { + "stdout": "string", + "stderr": "string", + "exitCode": 0 + } + } + } }, - "403": { - "description": "Permission denied (needs containers:exec)" + "400": { + "description": "Missing or invalid cmd (must be a non-empty array of strings)" }, - "404": { - "description": "Container not found" + "401": { + "description": "Not authenticated" + }, + "403": { + "description": "Permission denied" }, "500": { - "description": "Failed to list the directory" + "description": "Failed to run the command" } }, "security": [ @@ -7007,16 +7229,51 @@ { "bearerAuth": [] } - ] - } - }, - "/api/containers/{id}/files/chmod": { - "post": { - "operationId": "post_api_containers_id_files_chmod", - "tags": [ - "containers" ], - "summary": "Change the mode (permissions) of a file or directory inside a container (requires the 'exec' permission)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "cmd": { + "type": "array", + "items": { + "type": "string" + } + }, + "user": { + "type": "string" + }, + "workingDir": { + "type": "string" + } + }, + "required": [ + "cmd" + ] + }, + "example": { + "cmd": [ + "sh", + "-c", + "echo hi && exit 3" + ], + "workingDir": "/app" + } + } + } + } + } + }, + "/api/containers/{id}/files": { + "get": { + "operationId": "get_api_containers_id_files", + "tags": [ + "containers" + ], + "summary": "List the contents of a directory inside a container's filesystem", "parameters": [ { "name": "id", @@ -7030,11 +7287,80 @@ { "name": "env", "in": "query", + "required": true, + "schema": { + "type": "integer" + }, + "description": "The target environment ID the container lives in (from GET /api/environments)" + }, + { + "name": "path", + "in": "query", + "required": false, + "schema": { + "type": "string" + }, + "description": "Absolute directory path inside the container (default \"/\")" + }, + { + "name": "simpleLs", + "in": "query", "required": false, + "schema": { + "type": "boolean" + }, + "description": "Use a lightweight `ls` listing instead of a full stat of each entry" + } + ], + "responses": { + "200": { + "description": "Directory listing (entries with name, type, size and permission metadata)" + }, + "403": { + "description": "Permission denied (needs containers:exec)" + }, + "404": { + "description": "Container not found" + }, + "500": { + "description": "Failed to list the directory" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + } + }, + "/api/containers/{id}/files/chmod": { + "post": { + "operationId": "post_api_containers_id_files_chmod", + "tags": [ + "containers" + ], + "summary": "Change the mode (permissions) of a file or directory inside a container (requires the 'exec' permission)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container ID or name (from GET /api/containers)" + }, + { + "name": "env", + "in": "query", + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7127,6 +7453,123 @@ } } }, + "/api/containers/{id}/files/chown": { + "post": { + "operationId": "post_api_containers_id_files_chown", + "tags": [ + "containers" + ], + "summary": "Change the owner (and optional group) of a file or directory inside a container (requires the 'exec' permission)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container ID or name (from GET /api/containers)" + }, + { + "name": "env", + "in": "query", + "required": true, + "schema": { + "type": "integer" + }, + "description": "The target environment ID the container lives in (from GET /api/environments)" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "path": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "recursive": { + "type": "boolean" + } + }, + "required": [ + "success", + "path", + "owner", + "recursive" + ] + }, + "example": { + "success": true, + "path": "/app/data", + "owner": "1000:1000", + "recursive": true + } + } + } + }, + "400": { + "description": "Path or owner missing, an invalid owner spec, or the container is not running" + }, + "403": { + "description": "Permission denied, read-only file system, or operation not permitted" + }, + "404": { + "description": "Path not found" + }, + "500": { + "description": "Failed to change ownership" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "recursive": { + "type": "boolean" + } + }, + "required": [ + "path", + "owner" + ] + }, + "example": { + "path": "/app/data", + "owner": "1000:1000", + "recursive": true + } + } + } + } + } + }, "/api/containers/{id}/files/content": { "get": { "operationId": "get_api_containers_id_files_content", @@ -7147,11 +7590,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7234,11 +7677,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7347,11 +7790,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7370,6 +7813,9 @@ }, "type": { "type": "string" + }, + "owner": { + "type": "string" } }, "required": [ @@ -7381,7 +7827,8 @@ "example": { "success": true, "path": "/app/data", - "type": "directory" + "type": "directory", + "owner": "1000:1000" } } } @@ -7422,6 +7869,9 @@ }, "type": { "type": "string" + }, + "owner": { + "type": "string" } }, "required": [ @@ -7431,7 +7881,8 @@ }, "example": { "path": "/app/data", - "type": "directory" + "type": "directory", + "owner": "1000:1000" } } } @@ -7458,11 +7909,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7544,11 +7995,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7616,11 +8067,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7727,11 +8178,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7810,18 +8261,11 @@ "schema": { "type": "object", "properties": { - "files": { - "type": "array", - "items": { - "type": "string", - "format": "binary" - }, - "description": "One or more files to write into the target directory" + "owner": { + "type": "string", + "description": "Optional owner (\"user\", \"user:group\", \"uid\" or \"uid:gid\") to chown the uploaded files to; defaults to the container's configured user" } - }, - "required": [ - "files" - ] + } } } } @@ -7848,11 +8292,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7896,11 +8340,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "tail", @@ -7989,11 +8433,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "tail", @@ -8062,11 +8506,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8128,11 +8572,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8221,11 +8665,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8290,11 +8734,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8398,11 +8842,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8467,11 +8911,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8586,11 +9030,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8655,11 +9099,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8747,11 +9191,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8813,11 +9257,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9094,11 +9538,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "versions", @@ -9207,11 +9651,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9354,11 +9798,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9424,11 +9868,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9517,11 +9961,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9725,11 +10169,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9764,11 +10208,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "debug", @@ -12579,6 +13023,9 @@ }, "memoryLimitSupported": { "type": "boolean" + }, + "showMemoryWarning": { + "type": "boolean" } } }, @@ -12598,7 +13045,8 @@ "containers": 0, "images": 0, "name": "string", - "memoryLimitSupported": true + "memoryLimitSupported": true, + "showMemoryWarning": true }, "hawser": {} } @@ -20201,7 +20649,7 @@ "description": "Successful response" }, "400": { - "description": "A supplied field has the wrong type (e.g. editorIndentGuides not a boolean)" + "description": "A supplied field has the wrong type or an invalid value (e.g. editorIndentGuides not a boolean, or an unknown editorTheme)" }, "401": { "description": "Not authenticated" @@ -20257,6 +20705,9 @@ }, "editorIndentGuides": { "type": "boolean" + }, + "editorTheme": { + "type": "string" } } }, @@ -20271,7 +20722,8 @@ "animateIcons": true, "coloredActionButtons": true, "actionIconSize": "string", - "editorIndentGuides": true + "editorIndentGuides": true, + "editorTheme": "string" } } } @@ -23813,6 +24265,9 @@ "editorIndentGuides": { "type": "boolean" }, + "inlineTagEditing": { + "type": "boolean" + }, "coloredActionButtons": { "type": "boolean" }, @@ -23882,6 +24337,9 @@ "editorFont": { "type": "string" }, + "editorTheme": { + "type": "string" + }, "eventCleanupCron": { "type": "string" }, @@ -23980,6 +24438,7 @@ "example": { "animateIcons": true, "editorIndentGuides": true, + "inlineTagEditing": true, "coloredActionButtons": true, "lightTheme": "string", "darkTheme": "string", @@ -24004,6 +24463,7 @@ "deployLogReconcileEnabled": true, "downloadFormat": "string", "editorFont": "string", + "editorTheme": "string", "eventCleanupCron": "string", "eventCleanupEnabled": true, "eventCollectionMode": "string", @@ -24667,6 +25127,43 @@ "security": [] } }, + "/api/stack-tags": { + "get": { + "operationId": "get_api_stack-tags", + "tags": [ + "stack-tags" + ], + "summary": "List all stack tag assignments for an environment as a name -> tagIds map", + "parameters": [ + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "A JSON object mapping stack name to its array of tag ids" + }, + "403": { + "description": "Permission denied (needs stacks:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "description": "Returns every stack that has tags assigned in the given environment, so the stacks list can render and filter by tag in one request." + } + }, "/api/stacks": { "get": { "operationId": "get_api_stacks", @@ -26836,6 +27333,166 @@ ] } }, + "/api/stacks/{name}/tags": { + "get": { + "operationId": "get_api_stacks_name_tags", + "tags": [ + "stacks" + ], + "summary": "Get the tag ids assigned to one stack (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Stack name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs stacks:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "put": { + "operationId": "put_api_stacks_name_tags", + "tags": [ + "stacks" + ], + "summary": "Replace the tag ids assigned to one stack (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Stack name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs stacks:edit)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + } + } + }, "/api/stacks/{name}/validate": { "post": { "operationId": "post_api_stacks_name_validate", @@ -28011,6 +28668,303 @@ ] } }, + "/api/tags": { + "get": { + "operationId": "get_api_tags", + "tags": [ + "tags" + ], + "summary": "List the global tag catalog (name + colour)", + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tags": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "color": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "color" + ] + } + } + }, + "required": [ + "tags" + ] + }, + "example": { + "tags": [ + { + "id": 3, + "name": "auth", + "color": "green" + } + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "post": { + "operationId": "post_api_tags", + "tags": [ + "tags" + ], + "summary": "Create a tag (or return the existing one with the same name) in the global catalog", + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "color" + ] + }, + "example": { + "id": 3, + "name": "auth", + "color": "green", + "icon": "shield" + } + } + } + }, + "400": { + "description": "Missing or invalid tag name" + }, + "403": { + "description": "Permission denied (admin only)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + }, + "required": [ + "name" + ] + }, + "example": { + "name": "auth", + "color": "green", + "icon": "shield" + } + } + } + } + } + }, + "/api/tags/{id}": { + "put": { + "operationId": "put_api_tags_id", + "tags": [ + "tags" + ], + "summary": "Update a global catalog tag's name and/or colour", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Tag id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + } + }, + "required": [ + "success" + ] + }, + "example": { + "success": true + } + } + } + }, + "400": { + "description": "Invalid tag id or name" + }, + "403": { + "description": "Permission denied (admin only)" + }, + "409": { + "description": "A tag with that name already exists" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + } + }, + "example": { + "color": "blue", + "icon": "cloud" + } + } + } + } + }, + "delete": { + "operationId": "delete_api_tags_id", + "tags": [ + "tags" + ], + "summary": "Delete a catalog tag (removes it from every container and stack)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Tag id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + } + }, + "required": [ + "success" + ] + }, + "example": { + "success": true + } + } + } + }, + "400": { + "description": "Invalid tag id" + }, + "403": { + "description": "Permission denied (admin only)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + } + }, "/api/templates": { "get": { "operationId": "get_api_templates", diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index a382a11b3..7cee5b847 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -6,6 +6,7 @@ */ import type { SecretProviderConfig, SecretProviderType } from './secretproviders/shared'; +import { normalizeColor, type Tag, type TagColor } from '$lib/utils/tags-core'; import { mergeProviderConfigForWrite } from './secretproviders/shared'; import { db, @@ -44,6 +45,9 @@ import { secretProviders, stackSources, containerIconOverrides, + tags, + containerTags, + stackTags, vulnerabilityScans, auditLogs, containerEvents, @@ -552,8 +556,9 @@ export async function getUserThemePreferences(userId: number): Promise<{ coloredActionButtons: boolean; actionIconSize: string; editorIndentGuides: boolean; + editorTheme: string; }> { - const [lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, animateIcons, coloredActionButtons, actionIconSize, editorIndentGuides] = await Promise.all([ + const [lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, animateIcons, coloredActionButtons, actionIconSize, editorIndentGuides, editorTheme] = await Promise.all([ getUserSetting(userId, 'light_theme'), getUserSetting(userId, 'dark_theme'), getUserSetting(userId, 'font'), @@ -564,7 +569,8 @@ export async function getUserThemePreferences(userId: number): Promise<{ getUserSetting(userId, 'animate_icons'), getUserSetting(userId, 'colored_action_buttons'), getUserSetting(userId, 'action_icon_size'), - getUserSetting(userId, 'editor_indent_guides') + getUserSetting(userId, 'editor_indent_guides'), + getUserSetting(userId, 'editor_theme') ]); return { lightTheme: lightTheme || 'default', @@ -580,13 +586,14 @@ export async function getUserThemePreferences(userId: number): Promise<{ coloredActionButtons: coloredActionButtons === 'true', actionIconSize: actionIconSize || 'normal', // Default OFF — only true when explicitly stored (#1410) - editorIndentGuides: editorIndentGuides === 'true' + editorIndentGuides: editorIndentGuides === 'true', + editorTheme: editorTheme || 'default' }; } export async function setUserThemePreferences( userId: number, - prefs: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string; editorIndentGuides?: boolean } + prefs: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string; editorIndentGuides?: boolean; editorTheme?: string } ): Promise { const updates: Promise[] = []; if (prefs.lightTheme !== undefined) { @@ -622,6 +629,9 @@ export async function setUserThemePreferences( if (prefs.editorIndentGuides !== undefined) { updates.push(setUserSetting(userId, 'editor_indent_guides', prefs.editorIndentGuides ? 'true' : 'false')); } + if (prefs.editorTheme !== undefined) { + updates.push(setUserSetting(userId, 'editor_theme', prefs.editorTheme)); + } await Promise.all(updates); } @@ -3274,6 +3284,115 @@ export async function deleteContainerIconOverride(containerName: string, environ .where(and(eq(containerIconOverrides.containerName, containerName), containerEnvClause(environmentId))); } +// ============================================================================= +// TAGS (user-defined organizational tags) +// GLOBAL tag catalog (name + colour, unique on name) plus per-env assignment rows +// keyed by container/stack name. Distinct from Docker labels. +// ============================================================================= + +function envClause(col: any, environmentId: number | null) { + return environmentId !== null ? eq(col, environmentId) : isNull(col); +} + +function toTag(r: { id: number; name: string; color: string; icon: string | null }): Tag { + return { id: r.id, name: r.name, color: normalizeColor(r.color), icon: r.icon ?? null }; +} + +/** The whole tag catalog (global - not env-scoped). */ +export async function getTags(): Promise { + const rows = await db.select().from(tags).orderBy(tags.name); + return rows.map(toTag); +} + +/** + * Get an existing catalog tag by name, or create it. Matching is case-INSENSITIVE + * (so "Prod" and "prod" are the same tag), consistent with the rename collision + * check and the UI dedup. Done in JS over the (small, curated) catalog rather than + * a LOWER() query so it stays dialect-portable across SQLite and Postgres. + */ +export async function getOrCreateTag(name: string, color: TagColor, icon?: string | null): Promise { + const lower = name.toLowerCase(); + const findExisting = async () => + (await db.select().from(tags)).find((t) => t.name.toLowerCase() === lower); + const existing = await findExisting(); + if (existing) return toTag(existing); + // A concurrent same-name create races here; the case-insensitive unique index + // (COLLATE NOCASE / lower(name), see migration 0016) makes the loser's insert + // throw even for a case variant. Swallow it and re-select the winner so + // getOrCreateTag stays idempotent instead of surfacing a 500. + try { + await db.insert(tags).values({ name, color, icon: icon ?? null }); + } catch { + /* unique violation - the winner is found by the re-select below */ + } + return toTag((await findExisting())!); +} + +/** Update a catalog tag's name/colour/icon. `icon: null` clears it. */ +export async function updateTag(tagId: number, patch: { name?: string; color?: TagColor; icon?: string | null }): Promise { + const set: Record = {}; + if (patch.name !== undefined) set.name = patch.name; + if (patch.color !== undefined) set.color = patch.color; + if (patch.icon !== undefined) set.icon = patch.icon; + if (Object.keys(set).length === 0) return; + await db.update(tags).set(set).where(eq(tags.id, tagId)); +} + +/** Delete a catalog tag (assignments in every environment cascade away). */ +export async function deleteTag(tagId: number): Promise { + await db.delete(tags).where(eq(tags.id, tagId)); +} + +/** Tag ids assigned to one container. */ +export async function getContainerTagIds(containerName: string, environmentId: number | null): Promise { + const rows = await db.select().from(containerTags) + .where(and(eq(containerTags.containerName, containerName), envClause(containerTags.environmentId, environmentId))); + return rows.map((r) => r.tagId); +} + +/** All container assignments in an environment as a name -> tagId[] map (no N+1). */ +export async function getContainerTagsMap(environmentId: number | null): Promise> { + const rows = await db.select().from(containerTags).where(envClause(containerTags.environmentId, environmentId)); + const map: Record = {}; + for (const r of rows) (map[r.containerName] ??= []).push(r.tagId); + return map; +} + +/** Replace a container's tag assignments. */ +export async function setContainerTagIds(containerName: string, environmentId: number | null, tagIds: number[]): Promise { + await db.delete(containerTags) + .where(and(eq(containerTags.containerName, containerName), envClause(containerTags.environmentId, environmentId))); + const ids = [...new Set(tagIds)]; + if (ids.length) { + await db.insert(containerTags).values(ids.map((tagId) => ({ containerName, environmentId, tagId }))); + } +} + +/** Tag ids assigned to one stack. */ +export async function getStackTagIds(stackName: string, environmentId: number | null): Promise { + const rows = await db.select().from(stackTags) + .where(and(eq(stackTags.stackName, stackName), envClause(stackTags.environmentId, environmentId))); + return rows.map((r) => r.tagId); +} + +/** All stack assignments in an environment as a name -> tagId[] map. */ +export async function getStackTagsMap(environmentId: number | null): Promise> { + const rows = await db.select().from(stackTags).where(envClause(stackTags.environmentId, environmentId)); + const map: Record = {}; + for (const r of rows) (map[r.stackName] ??= []).push(r.tagId); + return map; +} + +/** Replace a stack's tag assignments. */ +export async function setStackTagIds(stackName: string, environmentId: number | null, tagIds: number[]): Promise { + await db.delete(stackTags) + .where(and(eq(stackTags.stackName, stackName), envClause(stackTags.environmentId, environmentId))); + const ids = [...new Set(tagIds)]; + if (ids.length) { + await db.insert(stackTags).values(ids.map((tagId) => ({ stackName, environmentId, tagId }))); + } +} + // ============================================================================= // VULNERABILITY SCAN RESULTS // ============================================================================= diff --git a/src/lib/server/db/drizzle.ts b/src/lib/server/db/drizzle.ts index 2e04126d9..a0cc6285e 100644 --- a/src/lib/server/db/drizzle.ts +++ b/src/lib/server/db/drizzle.ts @@ -926,6 +926,9 @@ export const gitStacks = schemaProxy.gitStacks; export const secretProviders = schemaProxy.secretProviders; export const stackSources = schemaProxy.stackSources; export const containerIconOverrides = schemaProxy.containerIconOverrides; +export const tags = schemaProxy.tags; +export const containerTags = schemaProxy.containerTags; +export const stackTags = schemaProxy.stackTags; export const vulnerabilityScans = schemaProxy.vulnerabilityScans; export const auditLogs = schemaProxy.auditLogs; export const containerEvents = schemaProxy.containerEvents; diff --git a/src/lib/server/db/schema/index.ts b/src/lib/server/db/schema/index.ts index 7337abaf9..7d77a0e66 100644 --- a/src/lib/server/db/schema/index.ts +++ b/src/lib/server/db/schema/index.ts @@ -383,6 +383,44 @@ export const containerIconOverrides = sqliteTable('container_icon_overrides', { containerIconEnvUnique: unique().on(table.containerName, table.environmentId) })); +// User-defined organizational tags for containers and stacks. +// Distinct from Docker labels. The catalog below is GLOBAL (one 'prod'/'infra'/etc +// across the whole instance, unique on name). Assignments (container_tags/stack_tags) +// ARE env-scoped and keyed by the container/stack NAME (stable across recreation), so +// which containers/stacks carry a tag is decided per environment. +export const tags = sqliteTable('tags', { + id: integer('id').primaryKey({ autoIncrement: true }), + name: text('name').notNull(), + color: text('color').notNull().default('slate'), // one of the fixed palette (tags-core.ts) + icon: text('icon'), // optional lucide icon name; null = default tag icon + createdAt: text('created_at').default(sql`CURRENT_TIMESTAMP`) +}, (table) => ({ + // Unique on name. The migration makes the index case-INSENSITIVE (COLLATE NOCASE + // on sqlite, lower(name) on pg) so "Prod" and "prod" are the same tag even under + // a concurrent create; drizzle's DSL can't express that, so it lives in 0016. + tagNameUnique: unique().on(table.name) +})); + +export const containerTags = sqliteTable('container_tags', { + id: integer('id').primaryKey({ autoIncrement: true }), + containerName: text('container_name').notNull(), + environmentId: integer('environment_id').references(() => environments.id, { onDelete: 'cascade' }), + tagId: integer('tag_id').notNull().references(() => tags.id, { onDelete: 'cascade' }), + createdAt: text('created_at').default(sql`CURRENT_TIMESTAMP`) +}, (table) => ({ + containerTagUnique: unique().on(table.containerName, table.environmentId, table.tagId) +})); + +export const stackTags = sqliteTable('stack_tags', { + id: integer('id').primaryKey({ autoIncrement: true }), + stackName: text('stack_name').notNull(), + environmentId: integer('environment_id').references(() => environments.id, { onDelete: 'cascade' }), + tagId: integer('tag_id').notNull().references(() => tags.id, { onDelete: 'cascade' }), + createdAt: text('created_at').default(sql`CURRENT_TIMESTAMP`) +}, (table) => ({ + stackTagUnique: unique().on(table.stackName, table.environmentId, table.tagId) +})); + export const stackEnvironmentVariables = sqliteTable('stack_environment_variables', { id: integer('id').primaryKey({ autoIncrement: true }), stackName: text('stack_name').notNull(), diff --git a/src/lib/server/db/schema/pg-schema.ts b/src/lib/server/db/schema/pg-schema.ts index 021301bd0..3d626d9e8 100644 --- a/src/lib/server/db/schema/pg-schema.ts +++ b/src/lib/server/db/schema/pg-schema.ts @@ -385,6 +385,41 @@ export const containerIconOverrides = pgTable('container_icon_overrides', { containerIconEnvUnique: unique().on(table.containerName, table.environmentId) })); +// User-defined organizational tags for containers and stacks. Distinct +// from Docker labels. GLOBAL tag catalog (unique on name, not env-scoped); assignment +// rows (container_tags/stack_tags) are keyed by name and stay env-scoped. +export const tags = pgTable('tags', { + id: serial('id').primaryKey(), + name: text('name').notNull(), + color: text('color').notNull().default('slate'), + icon: text('icon'), + createdAt: timestamp('created_at', { mode: 'string' }).defaultNow() +}, (table) => ({ + // Case-INSENSITIVE unique on name (lower(name) in the migration) so "Prod" and + // "prod" collide; drizzle's DSL can't express that, so it lives in 0016. + tagNameUnique: unique().on(table.name) +})); + +export const containerTags = pgTable('container_tags', { + id: serial('id').primaryKey(), + containerName: text('container_name').notNull(), + environmentId: integer('environment_id').references(() => environments.id, { onDelete: 'cascade' }), + tagId: integer('tag_id').notNull().references(() => tags.id, { onDelete: 'cascade' }), + createdAt: timestamp('created_at', { mode: 'string' }).defaultNow() +}, (table) => ({ + containerTagUnique: unique().on(table.containerName, table.environmentId, table.tagId) +})); + +export const stackTags = pgTable('stack_tags', { + id: serial('id').primaryKey(), + stackName: text('stack_name').notNull(), + environmentId: integer('environment_id').references(() => environments.id, { onDelete: 'cascade' }), + tagId: integer('tag_id').notNull().references(() => tags.id, { onDelete: 'cascade' }), + createdAt: timestamp('created_at', { mode: 'string' }).defaultNow() +}, (table) => ({ + stackTagUnique: unique().on(table.stackName, table.environmentId, table.tagId) +})); + export const stackEnvironmentVariables = pgTable('stack_environment_variables', { id: serial('id').primaryKey(), stackName: text('stack_name').notNull(), diff --git a/src/lib/stores/settings.ts b/src/lib/stores/settings.ts index 1173f86d5..d7bb2fafc 100644 --- a/src/lib/stores/settings.ts +++ b/src/lib/stores/settings.ts @@ -23,6 +23,7 @@ export interface AppSettings { confirmDestructive: boolean; showStoppedContainers: boolean; highlightUpdates: boolean; + inlineTagEditing: boolean; showGitCommitHash: boolean; timeFormat: TimeFormat; dateFormat: DateFormat; @@ -71,6 +72,7 @@ const DEFAULT_SETTINGS: AppSettings = { confirmDestructive: true, showStoppedContainers: true, highlightUpdates: true, + inlineTagEditing: false, showGitCommitHash: false, timeFormat: '24h', dateFormat: 'DD.MM.YYYY', @@ -164,6 +166,7 @@ function createSettingsStore() { confirmDestructive: settings.confirmDestructive ?? DEFAULT_SETTINGS.confirmDestructive, showStoppedContainers: settings.showStoppedContainers ?? DEFAULT_SETTINGS.showStoppedContainers, highlightUpdates: settings.highlightUpdates ?? DEFAULT_SETTINGS.highlightUpdates, + inlineTagEditing: settings.inlineTagEditing ?? DEFAULT_SETTINGS.inlineTagEditing, showGitCommitHash: settings.showGitCommitHash ?? DEFAULT_SETTINGS.showGitCommitHash, timeFormat: settings.timeFormat ?? DEFAULT_SETTINGS.timeFormat, dateFormat: settings.dateFormat ?? DEFAULT_SETTINGS.dateFormat, @@ -227,6 +230,7 @@ function createSettingsStore() { confirmDestructive: updatedSettings.confirmDestructive ?? DEFAULT_SETTINGS.confirmDestructive, showStoppedContainers: updatedSettings.showStoppedContainers ?? DEFAULT_SETTINGS.showStoppedContainers, highlightUpdates: updatedSettings.highlightUpdates ?? DEFAULT_SETTINGS.highlightUpdates, + inlineTagEditing: updatedSettings.inlineTagEditing ?? DEFAULT_SETTINGS.inlineTagEditing, showGitCommitHash: updatedSettings.showGitCommitHash ?? DEFAULT_SETTINGS.showGitCommitHash, timeFormat: updatedSettings.timeFormat ?? DEFAULT_SETTINGS.timeFormat, dateFormat: updatedSettings.dateFormat ?? DEFAULT_SETTINGS.dateFormat, @@ -321,6 +325,13 @@ function createSettingsStore() { return newSettings; }); }, + setInlineTagEditing: (value: boolean) => { + update((current) => { + const newSettings = { ...current, inlineTagEditing: value }; + saveSettings({ inlineTagEditing: value }); + return newSettings; + }); + }, setUseSelfhstIcons: (value: boolean) => { update((current) => { const newSettings = { ...current, useSelfhstIcons: value }; diff --git a/src/lib/utils/icons.ts b/src/lib/utils/icons.ts index a06f82296..4c99f8521 100644 --- a/src/lib/utils/icons.ts +++ b/src/lib/utils/icons.ts @@ -9,7 +9,11 @@ import { Anchor, Ship, Plane, Rocket, Car, Bike, TrainFront, Bus, Truck, Activity, BarChart3, ChartLine, ChartPie, TrendingUp, Gauge, Timer, Mail, MessageSquare, Phone, Video, Camera, Music, Headphones, Volume2, - MapPin, Map, Compass, Navigation, Flag, Bookmark, Target + MapPin, Map, Compass, Navigation, Flag, Bookmark, Target, + Apple, Asterisk, Beer, BellRing, Book, CircleDot, CloudRain, CloudUpload, Dot, Droplet, + File, Filter, Fish, Flashlight, Flower2, GraduationCap, Highlighter, Layers3, + LayoutDashboard, LayoutGrid, ListMusic, MemoryStick, MessageCircle, Music2, PenTool, Play, + QrCode, Reply, Search, Share2, ShoppingBag, SlidersHorizontal, ToggleLeft, UserCog, UtensilsCrossed } from 'lucide-svelte'; import type { ComponentType } from 'svelte'; @@ -36,7 +40,28 @@ const iconMap: Record = { 'mail': Mail, 'message-square': MessageSquare, 'phone': Phone, 'video': Video, 'camera': Camera, 'music': Music, 'headphones': Headphones, 'volume-2': Volume2, 'map-pin': MapPin, 'map': Map, 'compass': Compass, 'navigation': Navigation, - 'flag': Flag, 'bookmark': Bookmark, 'target': Target + 'flag': Flag, 'bookmark': Bookmark, 'target': Target, + 'folder': Folder, 'file': File, 'file-text': FileText, 'files': Files, 'image': ImageIcon, + 'film': Film, 'play': Play, 'music-2': Music2, 'list-music': ListMusic, 'podcast': Podcast, + 'gamepad': Gamepad2, 'dices': Dices, 'puzzle': Puzzle, 'trophy': Trophy, 'medal': Medal, 'ticket': Ticket, + 'cloud-download': CloudDownload, 'cloud-upload': CloudUpload, 'download': Download, 'upload': Upload, + 'share': Share2, 'rss': Rss, 'link': Link, + 'users': Users, 'user': User, 'user-cog': UserCog, 'contact': Contact, 'bot': Bot, 'brain': BrainCircuit, + 'bell': Bell, 'bell-ring': BellRing, 'calendar': Calendar, 'clock': Clock, 'alarm-clock': AlarmClock, 'hourglass': Hourglass, + 'shopping-cart': ShoppingCart, 'shopping-bag': ShoppingBag, 'credit-card': CreditCard, 'wallet': Wallet, + 'dollar-sign': DollarSign, 'receipt': Receipt, 'banknote': Banknote, + 'coffee': Coffee, 'pizza': Pizza, 'utensils': UtensilsCrossed, 'beer': Beer, 'wine': Wine, 'apple': Apple, + 'leaf': Leaf, 'tree': TreePine, 'flower': Flower2, 'bug': Bug, 'cat': Cat, 'dog': Dog, 'fish': Fish, 'bird': Bird, + 'palette': Palette, 'brush': Brush, 'pen-tool': PenTool, 'grid': Grid3x3, 'layout-grid': LayoutGrid, 'dashboard': LayoutDashboard, + 'memory-stick': MemoryStick, 'usb': Usb, 'plug': Plug, 'battery': Battery, 'power': Power, 'bluetooth': Bluetooth, + 'layers-3': Layers3, 'workflow': Workflow, 'boxes': Boxes, 'component': Component, 'blocks': Blocks, + 'thermometer': Thermometer, 'droplet': Droplet, 'wind': Wind, 'umbrella': Umbrella, 'cloud-rain': CloudRain, + 'lightbulb': Lightbulb, 'flashlight': Flashlight, 'fingerprint': Fingerprint, 'scan-line': ScanLine, + 'qr-code': QrCode, 'webhook': Webhook, + 'book': Book, 'book-open': BookOpen, 'graduation-cap': GraduationCap, 'newspaper': Newspaper, + 'feather': Feather, 'pencil': Pencil, 'highlighter': Highlighter, + 'inbox': Inbox, 'send': Send, 'reply': Reply, 'at-sign': AtSign, 'hash': Hash, 'message-circle': MessageCircle, 'megaphone': Megaphone, + 'filter': Filter, 'search': Search, 'sliders': SlidersHorizontal, 'toggle': ToggleLeft, 'circle-dot': CircleDot, 'dot': Dot, 'asterisk': Asterisk }; export function getIconComponent(iconName: string): ComponentType { diff --git a/src/lib/utils/tags-core.ts b/src/lib/utils/tags-core.ts new file mode 100644 index 000000000..9ccda36bc --- /dev/null +++ b/src/lib/utils/tags-core.ts @@ -0,0 +1,124 @@ +/** + * Pure helpers for user-defined container/stack tags. Distinct from + * Docker labels - these are Dockhand's own organizational tags. No I/O so they are + * unit-testable and shared by the API and the UI. + */ + +/** Max length of a single tag. */ +export const MAX_TAG_LENGTH = 32; + +// A curated, vibrant tag palette: distinct, well-spaced hues (no near-duplicate +// grays or shades). Rendered via inline styles, so it needs no Tailwind class per +// colour. The stored value is the KEY; the UI looks up the hex here. +export const TAG_HEX: Record = { + slate: '#64748b', + graphite: '#334155', + ruby: '#e11d48', + red: '#ef4444', + coral: '#fb7185', + orange: '#f97316', + amber: '#f59e0b', + gold: '#eab308', + lime: '#84cc16', + green: '#22c55e', + emerald: '#10b981', + forest: '#15803d', + teal: '#14b8a6', + cyan: '#06b6d4', + sky: '#0ea5e9', + blue: '#3b82f6', + indigo: '#6366f1', + royal: '#4338ca', + violet: '#8b5cf6', + purple: '#a855f7', + grape: '#7e22ce', + fuchsia: '#d946ef', + magenta: '#c026d3', + pink: '#ec4899' +}; + +/** All palette colour keys, in display order. */ +export const TAG_COLORS = Object.keys(TAG_HEX); +export type TagColor = string; +export const DEFAULT_TAG_COLOR: TagColor = 'slate'; + +/** Coerce an arbitrary colour value to a palette colour, defaulting to slate. */ +export function normalizeColor(raw: unknown): TagColor { + return typeof raw === 'string' && raw in TAG_HEX ? raw : DEFAULT_TAG_COLOR; +} + +/** The hex for a colour key (falls back to the default). */ +export function tagHex(color: string): string { + return TAG_HEX[color] ?? TAG_HEX[DEFAULT_TAG_COLOR]; +} + +/** A tag as stored/returned: catalog id, name, colour, and an optional lucide icon. */ +export interface Tag { + id: number; + name: string; + color: TagColor; + icon?: string | null; +} + +// A tag is a short human label: letters, digits, spaces, and `_ - . /` (so +// "home cloud", "web/proxy", "v2.0" all work). No control chars or other punctuation. +const TAG_CHARS = /^[A-Za-z0-9 _.\-/]+$/; + +/** + * Normalise a single tag: trim and collapse internal whitespace. Returns null if it + * is empty or otherwise invalid (too long, illegal characters). + */ +export function normalizeTag(raw: unknown): string | null { + if (typeof raw !== 'string') return null; + const t = raw.trim().replace(/\s+/g, ' '); + if (!t) return null; + if (t.length > MAX_TAG_LENGTH) return null; + if (!TAG_CHARS.test(t)) return null; + return t; +} + +export type TagFilterMode = 'all' | 'any'; + +/** + * True if an item's tags satisfy the filter. `mode` 'all' requires every selected + * tag id (AND); 'any' requires at least one (OR). An empty filter matches everything; + * a non-empty filter never matches an untagged item. + */ +export function matchesTagFilter( + itemTagIds: number[] | undefined, + filterTagIds: number[], + mode: TagFilterMode = 'all' +): boolean { + if (!filterTagIds.length) return true; + if (!itemTagIds || !itemTagIds.length) return false; + const have = new Set(itemTagIds); + return mode === 'any' + ? filterTagIds.some((id) => have.has(id)) + : filterTagIds.every((id) => have.has(id)); +} + +/** + * Build a DataGrid group descriptor for an item's unique tag COMBINATION (used by + * the containers/stacks "group by tag" mode). Returns null for an untagged item so + * it falls into the trailing "Untagged" bucket. The combination key is the sorted + * tag ids joined with '+', so a container tagged prod+infra forms its own group, + * distinct from just prod. Order weight puts fewer-tag groups first, tie-broken by + * first tag id, so ordering is stable. + */ +export function tagGroupDescriptor(tags: Tag[]): { + key: string; + label: string; + color: string; + icons: (string | null)[]; + order: number; +} | null { + if (!tags.length) return null; + const sorted = tags.slice().sort((a, b) => a.id - b.id); + return { + key: sorted.map((t) => t.id).join('+'), + label: sorted.map((t) => t.name).join(' + '), + color: tagHex(sorted[0].color), + icons: sorted.map((t) => t.icon ?? null), + order: sorted.length * 1e6 + sorted[0].id + }; +} diff --git a/src/routes/api/container-tags/+server.ts b/src/routes/api/container-tags/+server.ts new file mode 100644 index 000000000..c81227636 --- /dev/null +++ b/src/routes/api/container-tags/+server.ts @@ -0,0 +1,28 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { getContainerTagsMap } from '$lib/server/db'; + +function parseEnv(raw: string | null): number | null { + if (!raw) return null; + const n = parseInt(raw, 10); + return Number.isNaN(n) ? null : n; +} + +/** + * @openapi + * summary: List all container tag assignments for an environment as a name -> tagIds map + * description: Returns every container that has tags assigned in the given environment, so the containers list can render and filter by tag in one request instead of one lookup per row. + * query: env:integer Environment id + * resp-200: A JSON object mapping container name to its array of tag ids + * resp-200-example: {"plex":[1,5],"authelia":[3]} + * resp-403: Permission denied (needs containers:view) + */ +export const GET: RequestHandler = async ({ url, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('containers', 'view', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + return json(await getContainerTagsMap(envId)); +}; diff --git a/src/routes/api/container-tags/[name]/+server.ts b/src/routes/api/container-tags/[name]/+server.ts new file mode 100644 index 000000000..ef7d7b167 --- /dev/null +++ b/src/routes/api/container-tags/[name]/+server.ts @@ -0,0 +1,51 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { getContainerTagIds, setContainerTagIds } from '$lib/server/db'; + +function parseEnv(raw: string | null): number | null { + if (!raw) return null; + const n = parseInt(raw, 10); + return Number.isNaN(n) ? null : n; +} + +/** + * @openapi + * summary: Get the tag ids assigned to one container (by name) + * path: name:string! Container name + * query: env:integer Environment id + * resp-200: {tagIds:array!} + * resp-200-example: {"tagIds":[3,7]} + * resp-403: Permission denied (needs containers:view) + */ +export const GET: RequestHandler = async ({ params, url, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('containers', 'view', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + return json({ tagIds: await getContainerTagIds(params.name, envId) }); +}; + +/** + * @openapi + * summary: Replace the tag ids assigned to one container (by name) + * path: name:string! Container name + * query: env:integer Environment id + * body: {tagIds:array!} + * body-example: {"tagIds":[3,7]} + * resp-200: {tagIds:array!} + * resp-200-example: {"tagIds":[3,7]} + * resp-403: Permission denied (needs containers:edit) + */ +export const PUT: RequestHandler = async ({ params, url, request, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('containers', 'edit', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + const body = await request.json().catch(() => ({})); + const tagIds = Array.isArray(body.tagIds) ? body.tagIds.filter((n: unknown) => Number.isInteger(n)) : []; + await setContainerTagIds(params.name, envId, tagIds); + return json({ tagIds }); +}; diff --git a/src/routes/api/settings/general/+server.ts b/src/routes/api/settings/general/+server.ts index ad61214c4..43fddf92c 100644 --- a/src/routes/api/settings/general/+server.ts +++ b/src/routes/api/settings/general/+server.ts @@ -41,6 +41,7 @@ import { sendToEventSubprocess, sendToMetricsSubprocess } from '$lib/server/subp import { DEFAULT_GRYPE_IMAGE, DEFAULT_TRIVY_IMAGE } from '$lib/server/scanner'; import { DEFAULT_HELPER_IMAGE } from '$lib/server/backups/restic'; import { DEFAULT_STACK_LOG_OPERATIONS, sanitizeStackLogOperations, parseStackLogOperationsStorage, type StackLogOperation } from '$lib/utils/stack-log-operations'; +import { isValidEditorThemeId } from '$lib/utils/editor-themes'; // The real engine default (version-pinned, `-baseline`-aware). NOT a hardcoded // `:latest` — that would advertise a floating tag the backup engine never uses and, @@ -59,6 +60,7 @@ export interface GeneralSettings { confirmDestructive: boolean; showStoppedContainers: boolean; highlightUpdates: boolean; + inlineTagEditing: boolean; coloredActionButtons: boolean; actionIconSize: ActionIconSize; timeFormat: TimeFormat; @@ -91,6 +93,7 @@ export interface GeneralSettings { gridFontSize: string; terminalFont: string; editorFont: string; + editorTheme: string; // Compact ports compactPorts: boolean; // Show exposed (internal) ports @@ -141,6 +144,7 @@ const DEFAULT_SETTINGS: Omit { confirmDestructive, showStoppedContainers, highlightUpdates, + inlineTagEditing, coloredActionButtons, actionIconSize, timeFormat, @@ -278,6 +284,7 @@ export const GET: RequestHandler = async ({ cookies }) => { gridFontSize, terminalFont, editorFont, + editorTheme, compactPorts, showExposedPorts, showGitCommitHash, @@ -303,6 +310,7 @@ export const GET: RequestHandler = async ({ cookies }) => { getSetting('confirm_destructive'), getSetting('show_stopped_containers'), getSetting('highlight_updates'), + getSetting('inline_tag_editing'), getSetting('colored_action_buttons'), getSetting('action_icon_size'), getSetting('time_format'), @@ -333,6 +341,7 @@ export const GET: RequestHandler = async ({ cookies }) => { getSetting('theme_grid_font_size'), getSetting('theme_terminal_font'), getSetting('theme_editor_font'), + getSetting('theme_editor_theme'), getSetting('compact_ports'), getSetting('show_exposed_ports'), getSetting('show_git_commit_hash'), @@ -360,6 +369,7 @@ export const GET: RequestHandler = async ({ cookies }) => { confirmDestructive: confirmDestructive ?? DEFAULT_SETTINGS.confirmDestructive, showStoppedContainers: showStoppedContainers ?? DEFAULT_SETTINGS.showStoppedContainers, highlightUpdates: highlightUpdates ?? DEFAULT_SETTINGS.highlightUpdates, + inlineTagEditing: inlineTagEditing ?? DEFAULT_SETTINGS.inlineTagEditing, coloredActionButtons: coloredActionButtons ?? DEFAULT_SETTINGS.coloredActionButtons, actionIconSize: (VALID_ACTION_ICON_SIZES.includes(actionIconSize as ActionIconSize) ? actionIconSize : DEFAULT_SETTINGS.actionIconSize) as ActionIconSize, timeFormat: timeFormat ?? DEFAULT_SETTINGS.timeFormat, @@ -392,6 +402,7 @@ export const GET: RequestHandler = async ({ cookies }) => { gridFontSize: gridFontSize ?? DEFAULT_SETTINGS.gridFontSize, terminalFont: terminalFont ?? DEFAULT_SETTINGS.terminalFont, editorFont: editorFont ?? DEFAULT_SETTINGS.editorFont, + editorTheme: editorTheme ?? DEFAULT_SETTINGS.editorTheme, compactPorts: compactPorts ?? DEFAULT_SETTINGS.compactPorts, showGitCommitHash: showGitCommitHash ?? DEFAULT_SETTINGS.showGitCommitHash, showExposedPorts: showExposedPorts ?? DEFAULT_SETTINGS.showExposedPorts, @@ -426,7 +437,7 @@ export const GET: RequestHandler = async ({ cookies }) => { * @openapi * summary: Update global general settings (all fields optional; only supplied keys are written) * description: A large flat settings bag - theme/fonts, scanner defaults, cleanup schedules, event/metrics collection, editor options (e.g. editorIndentGuides), and more. - * body: {animateIcons:boolean, editorIndentGuides:boolean, coloredActionButtons:boolean, lightTheme:string, darkTheme:string, defaultTimezone:string, logBufferSizeKb:integer, externalStackPaths:string, actionIconSize:string, compactPorts:boolean, confirmDestructive:boolean, dateFormat:string, defaultBackupImage:string, defaultComposeTemplate:string, defaultGrypeArgs:string, defaultGrypeImage:string, defaultScannerDns:array, defaultScannerNetworkMode:string, defaultTrivyArgs:string, defaultTrivyImage:string, deployLogReconcileCron:string, deployLogReconcileEnabled:boolean, downloadFormat:string, editorFont:string, eventCleanupCron:string, eventCleanupEnabled:boolean, eventCollectionMode:string, eventPollInterval:integer, eventRetentionDays:integer, font:string, fontSize:string, formatLogTimestamps:boolean, gridFontSize:string, highlightUpdates:boolean, honorProxyLabels:boolean, labelFilterMode:string, logMaxLines:integer, metricsCollectionInterval:integer, primaryStackLocation:string, protectScannerImages:boolean, scannerCleanupCron:string, scannerCleanupEnabled:boolean, scheduleCleanupCron:string, scheduleCleanupEnabled:boolean, scheduleRetentionDays:integer, showExposedPorts:boolean, showGitCommitHash:boolean, showImageChangelogLinks:boolean, showStoppedContainers:boolean, showWhatsNew:boolean, terminalFont:string, timeFormat:string, useSelfhstIcons:boolean, stackLogOperations:array} + * body: {animateIcons:boolean, editorIndentGuides:boolean, inlineTagEditing:boolean, coloredActionButtons:boolean, lightTheme:string, darkTheme:string, defaultTimezone:string, logBufferSizeKb:integer, externalStackPaths:string, actionIconSize:string, compactPorts:boolean, confirmDestructive:boolean, dateFormat:string, defaultBackupImage:string, defaultComposeTemplate:string, defaultGrypeArgs:string, defaultGrypeImage:string, defaultScannerDns:array, defaultScannerNetworkMode:string, defaultTrivyArgs:string, defaultTrivyImage:string, deployLogReconcileCron:string, deployLogReconcileEnabled:boolean, downloadFormat:string, editorFont:string, editorTheme:string, eventCleanupCron:string, eventCleanupEnabled:boolean, eventCollectionMode:string, eventPollInterval:integer, eventRetentionDays:integer, font:string, fontSize:string, formatLogTimestamps:boolean, gridFontSize:string, highlightUpdates:boolean, honorProxyLabels:boolean, labelFilterMode:string, logMaxLines:integer, metricsCollectionInterval:integer, primaryStackLocation:string, protectScannerImages:boolean, scannerCleanupCron:string, scannerCleanupEnabled:boolean, scheduleCleanupCron:string, scheduleCleanupEnabled:boolean, scheduleRetentionDays:integer, showExposedPorts:boolean, showGitCommitHash:boolean, showImageChangelogLinks:boolean, showStoppedContainers:boolean, showWhatsNew:boolean, terminalFont:string, timeFormat:string, useSelfhstIcons:boolean, stackLogOperations:array} * resp-403: Permission denied (needs settings:edit) * resp-500: Failed to save settings */ @@ -438,7 +449,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { try { const body = await request.json(); - const { confirmDestructive, showStoppedContainers, highlightUpdates, coloredActionButtons, actionIconSize, timeFormat, dateFormat, downloadFormat, defaultGrypeArgs, defaultTrivyArgs, scheduleRetentionDays, eventRetentionDays, scheduleCleanupCron, eventCleanupCron, scheduleCleanupEnabled, eventCleanupEnabled, scannerCleanupCron, scannerCleanupEnabled, deployLogReconcileCron, deployLogReconcileEnabled, logBufferSizeKb, logMaxLines, defaultTimezone, eventCollectionMode, eventPollInterval, metricsCollectionInterval, lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, compactPorts, showExposedPorts, showGitCommitHash, formatLogTimestamps, externalStackPaths, primaryStackLocation, defaultGrypeImage, defaultTrivyImage, defaultComposeTemplate, labelFilterMode, defaultBackupImage, honorProxyLabels, showImageChangelogLinks, useSelfhstIcons, animateIcons, editorIndentGuides, protectScannerImages, showWhatsNew, defaultScannerNetworkMode, defaultScannerDns, stackLogOperations } = body; + const { confirmDestructive, showStoppedContainers, highlightUpdates, inlineTagEditing, coloredActionButtons, actionIconSize, timeFormat, dateFormat, downloadFormat, defaultGrypeArgs, defaultTrivyArgs, scheduleRetentionDays, eventRetentionDays, scheduleCleanupCron, eventCleanupCron, scheduleCleanupEnabled, eventCleanupEnabled, scannerCleanupCron, scannerCleanupEnabled, deployLogReconcileCron, deployLogReconcileEnabled, logBufferSizeKb, logMaxLines, defaultTimezone, eventCollectionMode, eventPollInterval, metricsCollectionInterval, lightTheme, darkTheme, font, fontSize, gridFontSize, terminalFont, editorFont, editorTheme, compactPorts, showExposedPorts, showGitCommitHash, formatLogTimestamps, externalStackPaths, primaryStackLocation, defaultGrypeImage, defaultTrivyImage, defaultComposeTemplate, labelFilterMode, defaultBackupImage, honorProxyLabels, showImageChangelogLinks, useSelfhstIcons, animateIcons, editorIndentGuides, protectScannerImages, showWhatsNew, defaultScannerNetworkMode, defaultScannerDns, stackLogOperations } = body; if (confirmDestructive !== undefined) { await setSetting('confirm_destructive', confirmDestructive); @@ -449,6 +460,9 @@ export const POST: RequestHandler = async ({ request, cookies }) => { if (highlightUpdates !== undefined) { await setSetting('highlight_updates', highlightUpdates); } + if (inlineTagEditing !== undefined) { + await setSetting('inline_tag_editing', inlineTagEditing); + } if (coloredActionButtons !== undefined) { await setSetting('colored_action_buttons', coloredActionButtons); } @@ -557,6 +571,9 @@ export const POST: RequestHandler = async ({ request, cookies }) => { if (editorFont !== undefined && VALID_EDITOR_FONTS.includes(editorFont)) { await setSetting('theme_editor_font', editorFont); } + if (editorTheme !== undefined && isValidEditorThemeId(editorTheme)) { + await setSetting('theme_editor_theme', editorTheme); + } if (showGitCommitHash !== undefined) { await setSetting('show_git_commit_hash', showGitCommitHash); } @@ -643,6 +660,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { confirmDestructiveVal, showStoppedContainersVal, highlightUpdatesVal, + inlineTagEditingVal, coloredActionButtonsVal, actionIconSizeVal, timeFormatVal, @@ -673,6 +691,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { gridFontSizeVal, terminalFontVal, editorFontVal, + editorThemeVal, compactPortsVal, showExposedPortsVal, showGitCommitHashVal, @@ -698,6 +717,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { getSetting('confirm_destructive'), getSetting('show_stopped_containers'), getSetting('highlight_updates'), + getSetting('inline_tag_editing'), getSetting('colored_action_buttons'), getSetting('action_icon_size'), getSetting('time_format'), @@ -728,6 +748,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { getSetting('theme_grid_font_size'), getSetting('theme_terminal_font'), getSetting('theme_editor_font'), + getSetting('theme_editor_theme'), getSetting('compact_ports'), getSetting('show_exposed_ports'), getSetting('show_git_commit_hash'), @@ -755,6 +776,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { confirmDestructive: confirmDestructiveVal ?? DEFAULT_SETTINGS.confirmDestructive, showStoppedContainers: showStoppedContainersVal ?? DEFAULT_SETTINGS.showStoppedContainers, highlightUpdates: highlightUpdatesVal ?? DEFAULT_SETTINGS.highlightUpdates, + inlineTagEditing: inlineTagEditingVal ?? DEFAULT_SETTINGS.inlineTagEditing, coloredActionButtons: coloredActionButtonsVal ?? DEFAULT_SETTINGS.coloredActionButtons, actionIconSize: (VALID_ACTION_ICON_SIZES.includes(actionIconSizeVal as ActionIconSize) ? actionIconSizeVal : DEFAULT_SETTINGS.actionIconSize) as ActionIconSize, timeFormat: timeFormatVal ?? DEFAULT_SETTINGS.timeFormat, @@ -787,6 +809,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => { gridFontSize: gridFontSizeVal ?? DEFAULT_SETTINGS.gridFontSize, terminalFont: terminalFontVal ?? DEFAULT_SETTINGS.terminalFont, editorFont: editorFontVal ?? DEFAULT_SETTINGS.editorFont, + editorTheme: editorThemeVal ?? DEFAULT_SETTINGS.editorTheme, compactPorts: compactPortsVal ?? DEFAULT_SETTINGS.compactPorts, showExposedPorts: showExposedPortsVal ?? DEFAULT_SETTINGS.showExposedPorts, showGitCommitHash: showGitCommitHashVal ?? DEFAULT_SETTINGS.showGitCommitHash, diff --git a/src/routes/api/stack-tags/+server.ts b/src/routes/api/stack-tags/+server.ts new file mode 100644 index 000000000..21663fcad --- /dev/null +++ b/src/routes/api/stack-tags/+server.ts @@ -0,0 +1,28 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { getStackTagsMap } from '$lib/server/db'; + +function parseEnv(raw: string | null): number | null { + if (!raw) return null; + const n = parseInt(raw, 10); + return Number.isNaN(n) ? null : n; +} + +/** + * @openapi + * summary: List all stack tag assignments for an environment as a name -> tagIds map + * description: Returns every stack that has tags assigned in the given environment, so the stacks list can render and filter by tag in one request. + * query: env:integer Environment id + * resp-200: A JSON object mapping stack name to its array of tag ids + * resp-200-example: {"nextcloud":[2],"traefik":[4]} + * resp-403: Permission denied (needs stacks:view) + */ +export const GET: RequestHandler = async ({ url, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('stacks', 'view', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + return json(await getStackTagsMap(envId)); +}; diff --git a/src/routes/api/stacks/[name]/tags/+server.ts b/src/routes/api/stacks/[name]/tags/+server.ts new file mode 100644 index 000000000..d2182163e --- /dev/null +++ b/src/routes/api/stacks/[name]/tags/+server.ts @@ -0,0 +1,51 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { getStackTagIds, setStackTagIds } from '$lib/server/db'; + +function parseEnv(raw: string | null): number | null { + if (!raw) return null; + const n = parseInt(raw, 10); + return Number.isNaN(n) ? null : n; +} + +/** + * @openapi + * summary: Get the tag ids assigned to one stack (by name) + * path: name:string! Stack name + * query: env:integer Environment id + * resp-200: {tagIds:array!} + * resp-200-example: {"tagIds":[3]} + * resp-403: Permission denied (needs stacks:view) + */ +export const GET: RequestHandler = async ({ params, url, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('stacks', 'view', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + return json({ tagIds: await getStackTagIds(params.name, envId) }); +}; + +/** + * @openapi + * summary: Replace the tag ids assigned to one stack (by name) + * path: name:string! Stack name + * query: env:integer Environment id + * body: {tagIds:array!} + * body-example: {"tagIds":[3]} + * resp-200: {tagIds:array!} + * resp-200-example: {"tagIds":[3]} + * resp-403: Permission denied (needs stacks:edit) + */ +export const PUT: RequestHandler = async ({ params, url, request, cookies }) => { + const auth = await authorize(cookies); + const envId = parseEnv(url.searchParams.get('env')); + if (auth.authEnabled && !(await auth.can('stacks', 'edit', envId ?? undefined))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + const body = await request.json().catch(() => ({})); + const tagIds = Array.isArray(body.tagIds) ? body.tagIds.filter((n: unknown) => Number.isInteger(n)) : []; + await setStackTagIds(params.name, envId, tagIds); + return json({ tagIds }); +}; diff --git a/src/routes/api/tags/+server.ts b/src/routes/api/tags/+server.ts new file mode 100644 index 000000000..987e89f88 --- /dev/null +++ b/src/routes/api/tags/+server.ts @@ -0,0 +1,49 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { getTags, getOrCreateTag } from '$lib/server/db'; +import { normalizeTag, normalizeColor } from '$lib/utils/tags-core'; + +/** + * @openapi + * summary: List the global tag catalog (name + colour) + * resp-200: {tags:array<{id:integer!, name:string!, color:string!}>!} + * resp-200-example: {"tags":[{"id":3,"name":"auth","color":"green"}]} + * resp-403: Permission denied (needs containers:view) + */ +export const GET: RequestHandler = async ({ cookies }) => { + const auth = await authorize(cookies); + // Anyone who can view containers can read the catalog (needed to assign tags); + // only admins can mutate it (POST/PUT/DELETE below). + if (auth.authEnabled && !(await auth.can('containers', 'view'))) { + return json({ error: 'Permission denied' }, { status: 403 }); + } + return json({ tags: await getTags() }); +}; + +/** + * @openapi + * summary: Create a tag (or return the existing one with the same name) in the global catalog + * body: {name:string!, color:string, icon:string} + * body-example: {"name":"auth","color":"green","icon":"shield"} + * resp-200: {id:integer!, name:string!, color:string!, icon:string} + * resp-200-example: {"id":3,"name":"auth","color":"green","icon":"shield"} + * resp-400: Missing or invalid tag name + * resp-403: Permission denied (admin only) + */ +export const POST: RequestHandler = async ({ request, cookies }) => { + const auth = await authorize(cookies); + // The catalog is global and shared across every environment, so only admins may + // create tags. Non-admins can assign existing tags (per-env assignment endpoints). + if (auth.authEnabled && !auth.isAdmin) { + return json({ error: 'Only an administrator can manage the tag catalog' }, { status: 403 }); + } + const body = await request.json().catch(() => ({})); + const name = normalizeTag(body.name); + if (!name) { + return json({ error: 'A valid tag name is required' }, { status: 400 }); + } + const icon = typeof body.icon === 'string' && body.icon.trim() ? body.icon.trim() : null; + const tag = await getOrCreateTag(name, normalizeColor(body.color), icon); + return json(tag); +}; diff --git a/src/routes/api/tags/[id]/+server.ts b/src/routes/api/tags/[id]/+server.ts new file mode 100644 index 000000000..db8740fa2 --- /dev/null +++ b/src/routes/api/tags/[id]/+server.ts @@ -0,0 +1,68 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { authorize } from '$lib/server/authorize'; +import { updateTag, deleteTag, getTags } from '$lib/server/db'; +import { normalizeTag, normalizeColor, TAG_COLORS } from '$lib/utils/tags-core'; + +/** + * @openapi + * summary: Update a global catalog tag's name and/or colour + * path: id:integer! Tag id + * body: {name:string, color:string, icon:string} + * body-example: {"color":"blue","icon":"cloud"} + * resp-200: {success:boolean!} + * resp-400: Invalid tag id or name + * resp-403: Permission denied (admin only) + * resp-409: A tag with that name already exists + */ +export const PUT: RequestHandler = async ({ params, request, cookies }) => { + const auth = await authorize(cookies); + // The tag catalog is global; only admins may rename/recolour a tag. + if (auth.authEnabled && !auth.isAdmin) { + return json({ error: 'Only an administrator can manage the tag catalog' }, { status: 403 }); + } + const tagId = parseInt(params.id, 10); + if (Number.isNaN(tagId)) return json({ error: 'Invalid tag id' }, { status: 400 }); + + const body = await request.json().catch(() => ({})); + const patch: { name?: string; color?: string; icon?: string | null } = {}; + if (body.name !== undefined) { + const name = normalizeTag(body.name); + if (!name) return json({ error: 'A valid tag name is required' }, { status: 400 }); + // Reject a rename that would collide with another tag (unique on name). + const clash = (await getTags()).some( + (t) => t.id !== tagId && t.name.toLowerCase() === name.toLowerCase() + ); + if (clash) return json({ error: `A tag named "${name}" already exists` }, { status: 409 }); + patch.name = name; + } + if (body.color !== undefined && (TAG_COLORS as readonly string[]).includes(body.color)) { + patch.color = normalizeColor(body.color); + } + // icon: a non-empty string sets it; null or '' clears it back to the default tag icon. + if (body.icon !== undefined) { + patch.icon = typeof body.icon === 'string' && body.icon.trim() ? body.icon.trim() : null; + } + await updateTag(tagId, patch); + return json({ success: true }); +}; + +/** + * @openapi + * summary: Delete a catalog tag (removes it from every container and stack) + * path: id:integer! Tag id + * resp-200: {success:boolean!} + * resp-400: Invalid tag id + * resp-403: Permission denied (admin only) + */ +export const DELETE: RequestHandler = async ({ params, cookies }) => { + const auth = await authorize(cookies); + // The tag catalog is global; only admins may delete a tag (cascades to all envs). + if (auth.authEnabled && !auth.isAdmin) { + return json({ error: 'Only an administrator can manage the tag catalog' }, { status: 403 }); + } + const tagId = parseInt(params.id, 10); + if (Number.isNaN(tagId)) return json({ error: 'Invalid tag id' }, { status: 400 }); + await deleteTag(tagId); + return json({ success: true }); +}; diff --git a/src/routes/containers/EditContainerModal.svelte b/src/routes/containers/EditContainerModal.svelte index 35a25cfac..ff4e62f35 100644 --- a/src/routes/containers/EditContainerModal.svelte +++ b/src/routes/containers/EditContainerModal.svelte @@ -3,6 +3,7 @@ import { Button } from '$lib/components/ui/button'; import { Pencil, Check, Loader2, X, Layers, Settings, Archive } from 'lucide-svelte'; import { currentEnvironment, appendEnvParam } from '$lib/stores/environment'; + import ContainerTagsSection from '$lib/components/ContainerTagsSection.svelte'; import { page } from '$app/stores'; // BETA GATE: backups feature flag import { focusFirstInput } from '$lib/utils'; import ContainerIcon from '$lib/components/ContainerIcon.svelte'; @@ -130,6 +131,7 @@ } } let command = $state(''); + let entrypoint = $state(''); let restartPolicy = $state('no'); let restartMaxRetries = $state(''); let networkMode = $state('bridge'); @@ -218,6 +220,7 @@ name: string; image: string; command: string; + entrypoint: string; restartPolicy: string; networkMode: string; portMappings: typeof portMappings; @@ -392,6 +395,9 @@ command = data.Config.Cmd ? data.Config.Cmd.map((arg: string) => arg.includes(' ') ? `"${arg}"` : arg ).join(' ') : ''; + entrypoint = data.Config.Entrypoint ? data.Config.Entrypoint.map((arg: string) => + arg.includes(' ') ? `"${arg}"` : arg + ).join(' ') : ''; restartPolicy = data.HostConfig.RestartPolicy?.Name || 'no'; restartMaxRetries = data.HostConfig.RestartPolicy?.MaximumRetryCount ?? ''; @@ -609,6 +615,7 @@ name, image, command, + entrypoint, restartPolicy, networkMode, portMappings: JSON.parse(JSON.stringify(portMappings)), @@ -687,6 +694,7 @@ if (name.trim() !== originalConfig.name) return true; if (image.trim() !== originalConfig.image) return true; if (command.trim() !== originalConfig.command) return true; + if (entrypoint.trim() !== originalConfig.entrypoint) return true; if (restartPolicy !== originalConfig.restartPolicy) return true; if (networkMode !== originalConfig.networkMode) return true; @@ -773,6 +781,7 @@ return JSON.stringify({ image: image.trim(), command: command.trim(), + entrypoint: entrypoint.trim(), restartPolicy, networkMode, portMappings: portMappings.filter(p => p.containerPort && p.hostPort), @@ -790,6 +799,7 @@ return JSON.stringify({ image: originalConfig.image, command: originalConfig.command, + entrypoint: originalConfig.entrypoint, restartPolicy: originalConfig.restartPolicy, networkMode: originalConfig.networkMode, portMappings: originalConfig.portMappings.filter(p => p.containerPort && p.hostPort), @@ -936,7 +946,10 @@ labelsObj[l.key] = l.value; }); - const cmd = command.trim() ? parseShellCommand(command.trim()) : undefined; + // null (not undefined) when cleared, so JSON.stringify keeps the key and + // the server's merge treats it as "clear" and falls back to the image CMD. + const cmd = command.trim() ? parseShellCommand(command.trim()) : null; + const entrypointArr = entrypoint.trim() ? parseShellCommand(entrypoint.trim()) : null; let healthcheck: any = undefined; if (healthcheckEnabled && healthcheckCommand.trim()) { @@ -1008,6 +1021,7 @@ env: env.length > 0 ? env : null, labels: labelsObj, cmd, + entrypoint: entrypointArr, restartPolicy, restartMaxRetries: restartPolicy === 'on-failure' && restartMaxRetries !== '' ? Number(restartMaxRetries) : null, networkMode, @@ -1268,6 +1282,11 @@ {/if} +
+ Tags + +
+ - Labels + Labels and tags diff --git a/src/routes/settings/general/GeneralTab.svelte b/src/routes/settings/general/GeneralTab.svelte index b55bae5c4..e9811644d 100644 --- a/src/routes/settings/general/GeneralTab.svelte +++ b/src/routes/settings/general/GeneralTab.svelte @@ -18,6 +18,7 @@ import NavigationSelector from '$lib/components/NavigationSelector.svelte'; import AnimateIconsToggle from '$lib/components/AnimateIconsToggle.svelte'; import IndentGuidesToggle from '$lib/components/IndentGuidesToggle.svelte'; + import EditorThemeSelector from '$lib/components/EditorThemeSelector.svelte'; import ColoredActionsToggle from '$lib/components/ColoredActionsToggle.svelte'; import SemverCheckConfig from '$lib/components/SemverCheckConfig.svelte'; import { onMount } from 'svelte'; @@ -27,6 +28,7 @@ let confirmDestructive = $derived($appSettings.confirmDestructive); let showStoppedContainers = $derived($appSettings.showStoppedContainers); let highlightUpdates = $derived($appSettings.highlightUpdates); + let inlineTagEditing = $derived($appSettings.inlineTagEditing); let compactPorts = $derived($appSettings.compactPorts); let showExposedPorts = $derived($appSettings.showExposedPorts); let showGitCommitHash = $derived($appSettings.showGitCommitHash); @@ -432,6 +434,28 @@ services:

Highlight container rows in amber when updates are available

+
+
+ + + + + + +

Tags can always be managed in the Labels and tags settings tab and in a container's or stack's edit dialog. This only controls the extra tag button on the list rows.

+
+
+ { + appSettings.setInlineTagEditing(checked); + toast.success(checked ? 'Inline tag editing enabled' : 'Inline tag editing disabled'); + }} + disabled={!$canAccess('settings', 'edit')} + /> +
+

Show a tag button on container and stack rows to tag them directly

+
@@ -570,53 +594,53 @@ services:

Show URLs inferred from Traefik and Pangolin labels alongside dockhand.url

+
-
- - { - appSettings.setTimeFormat(newFormat as '12h' | '24h'); - toast.success(`Time format set to ${newFormat === '12h' ? '12-hour (AM/PM)' : '24-hour'}`); - }} - disabled={!$canAccess('settings', 'edit')} - /> -
-

Display timestamps in 12-hour (AM/PM) or 24-hour format

-
-
-
- - { - if (value) { - appSettings.setDateFormat(value as DateFormat); - toast.success(`Date format set to ${value}`); - } - }} - disabled={!$canAccess('settings', 'edit')} - > - - - {dateFormat} - - - {#each dateFormatOptions as option} - -
- {option.label} - {option.example} -
-
- {/each} -
-
+
+
+ + { + appSettings.setTimeFormat(newFormat as '12h' | '24h'); + toast.success(`Time format set to ${newFormat === '12h' ? '12-hour (AM/PM)' : '24-hour'}`); + }} + disabled={!$canAccess('settings', 'edit')} + /> +
+
+ + { + if (value) { + appSettings.setDateFormat(value as DateFormat); + toast.success(`Date format set to ${value}`); + } + }} + disabled={!$canAccess('settings', 'edit')} + > + + + {dateFormat} + + + {#each dateFormatOptions as option} + +
+ {option.label} + {option.example} +
+
+ {/each} +
+
+
-

How dates are displayed throughout the app

+

How timestamps and dates are displayed throughout the app

@@ -641,6 +665,12 @@ services: {/if} + + {#if !$authStore.authEnabled || globalThemeLoaded} +
+ +
+ {/if} @@ -1265,14 +1295,14 @@ services:
- +

- Controls how multiple selected labels filter environments on the dashboard. + Controls how multiple selected environment labels filter environments on the dashboard. "Any": shows environments that have at least one of the selected labels. "All": shows only environments that have every selected label.

diff --git a/src/routes/settings/labels/LabelsTab.svelte b/src/routes/settings/labels/LabelsTab.svelte index c49e38a6c..c10047d17 100644 --- a/src/routes/settings/labels/LabelsTab.svelte +++ b/src/routes/settings/labels/LabelsTab.svelte @@ -14,6 +14,7 @@ import { getLabelColors, COLOR_PALETTE, hexToRgba } from '$lib/utils/label-colors'; import { canAccess } from '$lib/stores/auth'; import { toast } from 'svelte-sonner'; + import TagsManager from './TagsManager.svelte'; interface LabelInfo { label: string; @@ -379,6 +380,8 @@ {/if} + +
diff --git a/src/routes/settings/labels/TagsManager.svelte b/src/routes/settings/labels/TagsManager.svelte new file mode 100644 index 000000000..08ec5c9cd --- /dev/null +++ b/src/routes/settings/labels/TagsManager.svelte @@ -0,0 +1,219 @@ + + + + +
+
+ +
+ Tags + + Organize containers and stacks with your own tags. Tags are shared across all environments; which containers and stacks carry a tag is set per environment. + {#if !canEdit} Only an administrator can create or edit tags.{/if} + +
+
+
+
+ + {#if canEdit} + +
+ { if (e.key === 'Enter') create(); }} /> + + + {#snippet child({ props })} + + {/snippet} + + +
+ {#each TAG_COLORS as c} + + {/each} +
+
+
+ (newIcon = i)} /> + +
+ {/if} + + {#if loading} +

Loading...

+ {:else if tags.length === 0} +
No tags yet
+ {:else} +
+ {#each tags as tag (tag.id)} +
+ {#if editId === tag.id} + { if (e.key === 'Enter') saveEdit(tag); if (e.key === 'Escape') editId = null; }} /> + + {:else} + {@const hex = tagHex(tag.color)} + + {#if tag.icon}{:else}{/if} + {tag.name} + + {#if canEdit} + + colorPopoverId = o ? tag.id : null}> + + {#snippet child({ props })} + + {/snippet} + + +
+ {#each TAG_COLORS as c} + + {/each} +
+
+
+ + setIcon(tag, i)} /> + + remove(tag)} + > + {#snippet children({ open })} + + {/snippet} + + {/if} + {/if} +
+ {/each} +
+ {/if} +
+
diff --git a/src/routes/stacks/GitStackModal.svelte b/src/routes/stacks/GitStackModal.svelte index 77a150d85..77fbee287 100644 --- a/src/routes/stacks/GitStackModal.svelte +++ b/src/routes/stacks/GitStackModal.svelte @@ -23,9 +23,11 @@ import IconPickerModal from './IconPickerModal.svelte'; import ComposeOutputModal from './ComposeOutputModal.svelte'; import StackIcon from '$lib/components/StackIcon.svelte'; + import StackTagsSection from '$lib/components/StackTagsSection.svelte'; import { appendEnvParam } from '$lib/stores/environment'; import { persistStackIcon } from '$lib/utils/stack-icon'; import { type EnvVar, type ValidationResult } from '$lib/components/StackEnvVarsEditor.svelte'; + import { mergeGitStackEnvVars, isGitStackOverride } from '$lib/env-merge'; import { toast } from 'svelte-sonner'; import { focusFirstInput } from '$lib/utils'; import { readJobResponse } from '$lib/utils/sse-fetch'; @@ -377,13 +379,10 @@ } } - async function loadEnvFileContents(path: string) { - if (!gitStack || !path) { - fileEnvVars = {}; - return; - } - - loadingFileVars = true; + // Read one .env file from the synced clone (repo-root-relative path). Not-found / + // error yields {} so a missing file is harmless. + async function readRepoEnvFile(path: string): Promise> { + if (!gitStack || !path) return {}; try { const response = await fetch(`/api/git/stacks/${gitStack.id}/env-files`, { method: 'POST', @@ -392,11 +391,32 @@ }); if (response.ok) { const data = await response.json(); - fileEnvVars = data.vars || {}; + return data.vars || {}; } } catch (e) { - console.error('Failed to load env file contents:', e); + console.error('Failed to read env file contents:', e); + } + return {}; + } + + // Populate fileEnvVars with what the deploy sees: the compose-dir default .env as + // the base, then the explicit envFilePath layered on top (deploy applies the custom + // env file second). This is the diff base for save AND the file base for the merge. + async function loadEnvFileContents(explicitPath: string | null) { + if (!gitStack) { fileEnvVars = {}; + return; + } + loadingFileVars = true; + try { + const composeDir = (formComposePath || 'compose.yaml').replace(/[^/]*$/, ''); + const defaultEnvPath = `${composeDir}.env`; + const base = await readRepoEnvFile(defaultEnvPath); + const overlay = + explicitPath && explicitPath !== defaultEnvPath + ? await readRepoEnvFile(explicitPath) + : {}; + fileEnvVars = { ...base, ...overlay }; } finally { loadingFileVars = false; } @@ -478,16 +498,12 @@ return; } - // Convert to EnvVar array - preserve existing user entries that aren't in repo - const existingUserVars = envVars.filter(v => v.key.trim() && !(v.key in vars)); - const newVars: EnvVar[] = Object.entries(vars).map(([key, value]) => ({ - key, - value, - isSecret: false - })); - - envVars = [...newVars, ...existingUserVars]; + // Refresh the file base from the repo, then merge the current editor state on + // top so re-populating never clobbers the user's values. Any editor value that + // differs from the fresh repo (a real edit, or a secret) wins; keys the user + // never touched follow the refreshed repo value. fileEnvVars = vars; + envVars = mergeGitStackEnvVars(vars, envVars.filter((v) => v.key.trim())); toast.success(`Loaded ${count} variable${count === 1 ? '' : 's'}`, { description: 'You can now customize values before deploying' @@ -551,12 +567,19 @@ formBranch = gitStack.branch ?? null; // Load env files and overrides SYNCHRONOUSLY to avoid race conditions - // Wait for all loads to complete before allowing any other effect to run + // Wait for all loads to complete before allowing any other effect to run. + // Always read the repo .env (default compose-dir .env + explicit envFilePath) + // so the editor can show the full effective set, not just DB overrides. await Promise.all([ loadEnvFiles(), loadEnvVarsOverrides(), - gitStack.envFilePath ? loadEnvFileContents(gitStack.envFilePath) : Promise.resolve() + loadEnvFileContents(gitStack.envFilePath) ]); + + // Merge repo .env (base) with DB overrides/secrets so untouched populated + // vars stay visible on reopen. The save filter still drops file-equal + // non-secrets, keeping the DB override-only (git-sync pickup intact). + envVars = mergeGitStackEnvVars(fileEnvVars, envVars); } else { formRepoMode = repositories.length > 0 ? 'existing' : 'new'; formRepositoryId = null; @@ -690,14 +713,10 @@ formError = ''; try { - // Only save vars that are actual overrides (differ from file) or new (not in file) - // This ensures file updates from git are picked up on next sync - const overrideVars = envVars.filter(v => { - if (!v.key.trim()) return false; - const fileValue = fileEnvVars[v.key]; - // Save if: not in file (new var), value differs from file, or is a secret - return fileValue === undefined || v.value !== fileValue || v.isSecret; - }); + // Store only actual overrides (differ from file / new / secret) so file updates + // from git are picked up on next sync. Shared predicate keeps this in step with + // the merge round-trip guard and the re-populate preserve step. + const overrideVars = envVars.filter((v) => isGitStackOverride(v, fileEnvVars)); let body: any = { stackName: formStackName, @@ -1176,6 +1195,13 @@ {/if}
+ {#if gitStack?.stackName} +
+ + +
+ {/if} + {#if gitStack && selectedRepo}
@@ -1489,36 +1515,34 @@ showInterpolationHint={true} > {#snippet headerActions()} - {#if !gitStack} -
- - - - - - -
-

Clone the repository and load environment variables from the .env file (in compose directory) and additional env file (if specified), so you can see what you can override.

-
-
-
-
- {/if} +
+ + + + + + +
+

Clone the repository and load environment variables from the .env file (in compose directory) and additional env file (if specified), so you can see what you can override.

+
+
+
+
{/snippet}
diff --git a/src/routes/stacks/StackModal.svelte b/src/routes/stacks/StackModal.svelte index ca1db673a..8c7e63994 100644 --- a/src/routes/stacks/StackModal.svelte +++ b/src/routes/stacks/StackModal.svelte @@ -23,6 +23,7 @@ import FilesystemBrowser from './FilesystemBrowser.svelte'; import IconPickerModal from './IconPickerModal.svelte'; import StackIcon from '$lib/components/StackIcon.svelte'; + import StackTagsSection from '$lib/components/StackTagsSection.svelte'; import PathBarItem from './PathBarItem.svelte'; import * as Tooltip from '$lib/components/ui/tooltip'; import { Badge } from '$lib/components/ui/badge'; @@ -2293,6 +2294,14 @@
{:else} + + {#if mode === 'edit' && stackName} +
+ + +
+ {/if} + {#if mode === 'create'}
diff --git a/static/openapi.json b/static/openapi.json index ae4621899..134146e4d 100644 --- a/static/openapi.json +++ b/static/openapi.json @@ -38,6 +38,9 @@ { "name": "container-icons" }, + { + "name": "container-tags" + }, { "name": "containers" }, @@ -131,12 +134,18 @@ { "name": "settings" }, + { + "name": "stack-tags" + }, { "name": "stacks" }, { "name": "system" }, + { + "name": "tags" + }, { "name": "templates" }, @@ -6375,6 +6384,206 @@ ] } }, + "/api/container-tags": { + "get": { + "operationId": "get_api_container-tags", + "tags": [ + "container-tags" + ], + "summary": "List all container tag assignments for an environment as a name -> tagIds map", + "parameters": [ + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "A JSON object mapping container name to its array of tag ids" + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "description": "Returns every container that has tags assigned in the given environment, so the containers list can render and filter by tag in one request instead of one lookup per row." + } + }, + "/api/container-tags/{name}": { + "get": { + "operationId": "get_api_container-tags_name", + "tags": [ + "container-tags" + ], + "summary": "Get the tag ids assigned to one container (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "put": { + "operationId": "put_api_container-tags_name", + "tags": [ + "container-tags" + ], + "summary": "Replace the tag ids assigned to one container (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:edit)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3, + 7 + ] + } + } + } + } + } + }, "/api/containers": { "get": { "operationId": "get_api_containers", @@ -6646,11 +6855,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6695,11 +6904,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "force", @@ -6773,11 +6982,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6848,11 +7057,11 @@ { "name": "envId", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -6941,13 +7150,13 @@ } } }, - "/api/containers/{id}/files": { - "get": { - "operationId": "get_api_containers_id_files", + "/api/containers/{id}/exec/run": { + "post": { + "operationId": "post_api_containers_id_exec_run", "tags": [ "containers" ], - "summary": "List the contents of a directory inside a container's filesystem", + "summary": "Run a finite command in a container and wait for the result, returning stdout, stderr and the exit code (a non-interactive alternative to the terminal exec endpoint). Intended for short commands - the request is bounded by a ~30s ceiling on remote (Hawser/TCP) environments; use the interactive terminal for long-running work.", "parameters": [ { "name": "id", @@ -6959,45 +7168,58 @@ "description": "Container ID or name (from GET /api/containers)" }, { - "name": "env", + "name": "envId", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" - }, - { - "name": "path", - "in": "query", - "required": false, - "schema": { - "type": "string" - }, - "description": "Absolute directory path inside the container (default \"/\")" - }, - { - "name": "simpleLs", - "in": "query", - "required": false, - "schema": { - "type": "boolean" - }, - "description": "Use a lightweight `ls` listing instead of a full stat of each entry" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { "200": { - "description": "Directory listing (entries with name, type, size and permission metadata)" + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "stdout": { + "type": "string" + }, + "stderr": { + "type": "string" + }, + "exitCode": { + "type": "integer" + } + }, + "required": [ + "stdout", + "stderr", + "exitCode" + ] + }, + "example": { + "stdout": "string", + "stderr": "string", + "exitCode": 0 + } + } + } }, - "403": { - "description": "Permission denied (needs containers:exec)" + "400": { + "description": "Missing or invalid cmd (must be a non-empty array of strings)" }, - "404": { - "description": "Container not found" + "401": { + "description": "Not authenticated" + }, + "403": { + "description": "Permission denied" }, "500": { - "description": "Failed to list the directory" + "description": "Failed to run the command" } }, "security": [ @@ -7007,16 +7229,51 @@ { "bearerAuth": [] } - ] - } - }, - "/api/containers/{id}/files/chmod": { - "post": { - "operationId": "post_api_containers_id_files_chmod", - "tags": [ - "containers" ], - "summary": "Change the mode (permissions) of a file or directory inside a container (requires the 'exec' permission)", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "cmd": { + "type": "array", + "items": { + "type": "string" + } + }, + "user": { + "type": "string" + }, + "workingDir": { + "type": "string" + } + }, + "required": [ + "cmd" + ] + }, + "example": { + "cmd": [ + "sh", + "-c", + "echo hi && exit 3" + ], + "workingDir": "/app" + } + } + } + } + } + }, + "/api/containers/{id}/files": { + "get": { + "operationId": "get_api_containers_id_files", + "tags": [ + "containers" + ], + "summary": "List the contents of a directory inside a container's filesystem", "parameters": [ { "name": "id", @@ -7030,11 +7287,80 @@ { "name": "env", "in": "query", + "required": true, + "schema": { + "type": "integer" + }, + "description": "The target environment ID the container lives in (from GET /api/environments)" + }, + { + "name": "path", + "in": "query", + "required": false, + "schema": { + "type": "string" + }, + "description": "Absolute directory path inside the container (default \"/\")" + }, + { + "name": "simpleLs", + "in": "query", "required": false, + "schema": { + "type": "boolean" + }, + "description": "Use a lightweight `ls` listing instead of a full stat of each entry" + } + ], + "responses": { + "200": { + "description": "Directory listing (entries with name, type, size and permission metadata)" + }, + "403": { + "description": "Permission denied (needs containers:exec)" + }, + "404": { + "description": "Container not found" + }, + "500": { + "description": "Failed to list the directory" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + } + }, + "/api/containers/{id}/files/chmod": { + "post": { + "operationId": "post_api_containers_id_files_chmod", + "tags": [ + "containers" + ], + "summary": "Change the mode (permissions) of a file or directory inside a container (requires the 'exec' permission)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container ID or name (from GET /api/containers)" + }, + { + "name": "env", + "in": "query", + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7127,6 +7453,123 @@ } } }, + "/api/containers/{id}/files/chown": { + "post": { + "operationId": "post_api_containers_id_files_chown", + "tags": [ + "containers" + ], + "summary": "Change the owner (and optional group) of a file or directory inside a container (requires the 'exec' permission)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Container ID or name (from GET /api/containers)" + }, + { + "name": "env", + "in": "query", + "required": true, + "schema": { + "type": "integer" + }, + "description": "The target environment ID the container lives in (from GET /api/environments)" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "path": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "recursive": { + "type": "boolean" + } + }, + "required": [ + "success", + "path", + "owner", + "recursive" + ] + }, + "example": { + "success": true, + "path": "/app/data", + "owner": "1000:1000", + "recursive": true + } + } + } + }, + "400": { + "description": "Path or owner missing, an invalid owner spec, or the container is not running" + }, + "403": { + "description": "Permission denied, read-only file system, or operation not permitted" + }, + "404": { + "description": "Path not found" + }, + "500": { + "description": "Failed to change ownership" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "recursive": { + "type": "boolean" + } + }, + "required": [ + "path", + "owner" + ] + }, + "example": { + "path": "/app/data", + "owner": "1000:1000", + "recursive": true + } + } + } + } + } + }, "/api/containers/{id}/files/content": { "get": { "operationId": "get_api_containers_id_files_content", @@ -7147,11 +7590,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7234,11 +7677,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7347,11 +7790,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7370,6 +7813,9 @@ }, "type": { "type": "string" + }, + "owner": { + "type": "string" } }, "required": [ @@ -7381,7 +7827,8 @@ "example": { "success": true, "path": "/app/data", - "type": "directory" + "type": "directory", + "owner": "1000:1000" } } } @@ -7422,6 +7869,9 @@ }, "type": { "type": "string" + }, + "owner": { + "type": "string" } }, "required": [ @@ -7431,7 +7881,8 @@ }, "example": { "path": "/app/data", - "type": "directory" + "type": "directory", + "owner": "1000:1000" } } } @@ -7458,11 +7909,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7544,11 +7995,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7616,11 +8067,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7727,11 +8178,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "path", @@ -7810,18 +8261,11 @@ "schema": { "type": "object", "properties": { - "files": { - "type": "array", - "items": { - "type": "string", - "format": "binary" - }, - "description": "One or more files to write into the target directory" + "owner": { + "type": "string", + "description": "Optional owner (\"user\", \"user:group\", \"uid\" or \"uid:gid\") to chown the uploaded files to; defaults to the container's configured user" } - }, - "required": [ - "files" - ] + } } } } @@ -7848,11 +8292,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -7896,11 +8340,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "tail", @@ -7989,11 +8433,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "tail", @@ -8062,11 +8506,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8128,11 +8572,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8221,11 +8665,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8290,11 +8734,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8398,11 +8842,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8467,11 +8911,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8586,11 +9030,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8655,11 +9099,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8747,11 +9191,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -8813,11 +9257,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9094,11 +9538,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "versions", @@ -9207,11 +9651,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9354,11 +9798,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9424,11 +9868,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9517,11 +9961,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9725,11 +10169,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" } ], "responses": { @@ -9764,11 +10208,11 @@ { "name": "env", "in": "query", - "required": false, + "required": true, "schema": { "type": "integer" }, - "description": "The target environment ID (omit for the local/default Docker host) (from GET /api/environments)" + "description": "The target environment ID the container lives in (from GET /api/environments)" }, { "name": "debug", @@ -12579,6 +13023,9 @@ }, "memoryLimitSupported": { "type": "boolean" + }, + "showMemoryWarning": { + "type": "boolean" } } }, @@ -12598,7 +13045,8 @@ "containers": 0, "images": 0, "name": "string", - "memoryLimitSupported": true + "memoryLimitSupported": true, + "showMemoryWarning": true }, "hawser": {} } @@ -20201,7 +20649,7 @@ "description": "Successful response" }, "400": { - "description": "A supplied field has the wrong type (e.g. editorIndentGuides not a boolean)" + "description": "A supplied field has the wrong type or an invalid value (e.g. editorIndentGuides not a boolean, or an unknown editorTheme)" }, "401": { "description": "Not authenticated" @@ -20257,6 +20705,9 @@ }, "editorIndentGuides": { "type": "boolean" + }, + "editorTheme": { + "type": "string" } } }, @@ -20271,7 +20722,8 @@ "animateIcons": true, "coloredActionButtons": true, "actionIconSize": "string", - "editorIndentGuides": true + "editorIndentGuides": true, + "editorTheme": "string" } } } @@ -23813,6 +24265,9 @@ "editorIndentGuides": { "type": "boolean" }, + "inlineTagEditing": { + "type": "boolean" + }, "coloredActionButtons": { "type": "boolean" }, @@ -23882,6 +24337,9 @@ "editorFont": { "type": "string" }, + "editorTheme": { + "type": "string" + }, "eventCleanupCron": { "type": "string" }, @@ -23980,6 +24438,7 @@ "example": { "animateIcons": true, "editorIndentGuides": true, + "inlineTagEditing": true, "coloredActionButtons": true, "lightTheme": "string", "darkTheme": "string", @@ -24004,6 +24463,7 @@ "deployLogReconcileEnabled": true, "downloadFormat": "string", "editorFont": "string", + "editorTheme": "string", "eventCleanupCron": "string", "eventCleanupEnabled": true, "eventCollectionMode": "string", @@ -24667,6 +25127,43 @@ "security": [] } }, + "/api/stack-tags": { + "get": { + "operationId": "get_api_stack-tags", + "tags": [ + "stack-tags" + ], + "summary": "List all stack tag assignments for an environment as a name -> tagIds map", + "parameters": [ + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "A JSON object mapping stack name to its array of tag ids" + }, + "403": { + "description": "Permission denied (needs stacks:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "description": "Returns every stack that has tags assigned in the given environment, so the stacks list can render and filter by tag in one request." + } + }, "/api/stacks": { "get": { "operationId": "get_api_stacks", @@ -26836,6 +27333,166 @@ ] } }, + "/api/stacks/{name}/tags": { + "get": { + "operationId": "get_api_stacks_name_tags", + "tags": [ + "stacks" + ], + "summary": "Get the tag ids assigned to one stack (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Stack name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs stacks:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "put": { + "operationId": "put_api_stacks_name_tags", + "tags": [ + "stacks" + ], + "summary": "Replace the tag ids assigned to one stack (by name)", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Stack name" + }, + { + "name": "env", + "in": "query", + "required": false, + "schema": { + "type": "integer" + }, + "description": "Environment id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs stacks:edit)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tagIds": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + "required": [ + "tagIds" + ] + }, + "example": { + "tagIds": [ + 3 + ] + } + } + } + } + } + }, "/api/stacks/{name}/validate": { "post": { "operationId": "post_api_stacks_name_validate", @@ -28011,6 +28668,303 @@ ] } }, + "/api/tags": { + "get": { + "operationId": "get_api_tags", + "tags": [ + "tags" + ], + "summary": "List the global tag catalog (name + colour)", + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "tags": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "color": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "color" + ] + } + } + }, + "required": [ + "tags" + ] + }, + "example": { + "tags": [ + { + "id": 3, + "name": "auth", + "color": "green" + } + ] + } + } + } + }, + "403": { + "description": "Permission denied (needs containers:view)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + }, + "post": { + "operationId": "post_api_tags", + "tags": [ + "tags" + ], + "summary": "Create a tag (or return the existing one with the same name) in the global catalog", + "parameters": [], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + }, + "required": [ + "id", + "name", + "color" + ] + }, + "example": { + "id": 3, + "name": "auth", + "color": "green", + "icon": "shield" + } + } + } + }, + "400": { + "description": "Missing or invalid tag name" + }, + "403": { + "description": "Permission denied (admin only)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + }, + "required": [ + "name" + ] + }, + "example": { + "name": "auth", + "color": "green", + "icon": "shield" + } + } + } + } + } + }, + "/api/tags/{id}": { + "put": { + "operationId": "put_api_tags_id", + "tags": [ + "tags" + ], + "summary": "Update a global catalog tag's name and/or colour", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Tag id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + } + }, + "required": [ + "success" + ] + }, + "example": { + "success": true + } + } + } + }, + "400": { + "description": "Invalid tag id or name" + }, + "403": { + "description": "Permission denied (admin only)" + }, + "409": { + "description": "A tag with that name already exists" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + }, + "icon": { + "type": "string" + } + } + }, + "example": { + "color": "blue", + "icon": "cloud" + } + } + } + } + }, + "delete": { + "operationId": "delete_api_tags_id", + "tags": [ + "tags" + ], + "summary": "Delete a catalog tag (removes it from every container and stack)", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Tag id" + } + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + } + }, + "required": [ + "success" + ] + }, + "example": { + "success": true + } + } + } + }, + "400": { + "description": "Invalid tag id" + }, + "403": { + "description": "Permission denied (admin only)" + } + }, + "security": [ + { + "cookieAuth": [] + }, + { + "bearerAuth": [] + } + ] + } + }, "/api/templates": { "get": { "operationId": "get_api_templates", diff --git a/tests/grid-grouping-core.test.ts b/tests/grid-grouping-core.test.ts new file mode 100644 index 000000000..a0dcbb132 --- /dev/null +++ b/tests/grid-grouping-core.test.ts @@ -0,0 +1,77 @@ +import { describe, it, expect } from 'bun:test'; +import { groupData, UNGROUPED_KEY, type GroupDescriptor } from '../src/lib/components/data-grid/grouping-core'; + +interface Row { id: number; combo: string | null; } + +// Group by the row's `combo` string; null -> ungrouped. +const by = (r: Row): GroupDescriptor | null => + r.combo ? { key: r.combo, label: r.combo, color: '#abc', order: r.combo.length } : null; + +describe('groupData', () => { + it('partitions rows by group key, preserving in-group order', () => { + const data: Row[] = [ + { id: 1, combo: 'prod' }, + { id: 2, combo: 'infra' }, + { id: 3, combo: 'prod' } + ]; + const groups = groupData(data, by); + const prod = groups.find((g) => g.key === 'prod')!; + expect(prod.items.map((r) => r.id)).toEqual([1, 3]); // order preserved + }); + + it('orders groups by `order` weight then first appearance', () => { + const data: Row[] = [ + { id: 1, combo: 'infra' }, // len 5 + { id: 2, combo: 'prod' }, // len 4 + { id: 3, combo: 'db' } // len 2 + ]; + const groups = groupData(data, by); + expect(groups.map((g) => g.key)).toEqual(['db', 'prod', 'infra']); + }); + + it('places the ungrouped bucket last with the given label', () => { + const data: Row[] = [ + { id: 1, combo: null }, + { id: 2, combo: 'prod' }, + { id: 3, combo: null } + ]; + const groups = groupData(data, by, 'No tags'); + expect(groups[groups.length - 1].key).toBe(UNGROUPED_KEY); + expect(groups[groups.length - 1].label).toBe('No tags'); + expect(groups[groups.length - 1].items.map((r) => r.id)).toEqual([1, 3]); + }); + + it('is stable when two groups share the same order weight', () => { + // same length -> same order -> first appearance decides + const data: Row[] = [ + { id: 1, combo: 'aaa' }, + { id: 2, combo: 'bbb' }, + { id: 3, combo: 'aaa' } + ]; + const groups = groupData(data, by).filter((g) => g.key !== UNGROUPED_KEY); + expect(groups.map((g) => g.key)).toEqual(['aaa', 'bbb']); + }); + + it('carries color and icons from the descriptor', () => { + const data: Row[] = [{ id: 1, combo: 'prod' }]; + const withIcons = (r: Row): GroupDescriptor | null => + r.combo ? { key: r.combo, label: r.combo, color: '#f00', icons: ['shield', null] } : null; + const [g] = groupData(data, withIcons); + expect(g.color).toBe('#f00'); + expect(g.icons).toEqual(['shield', null]); + }); + + it('returns an empty array for empty data', () => { + expect(groupData([], by)).toEqual([]); + }); + + it('every input row lands in exactly one group', () => { + const data: Row[] = Array.from({ length: 50 }, (_, i) => ({ + id: i, + combo: i % 3 === 0 ? null : `g${i % 4}` + })); + const groups = groupData(data, by); + const total = groups.reduce((n, g) => n + g.items.length, 0); + expect(total).toBe(50); + }); +}); diff --git a/tests/tags-core.test.ts b/tests/tags-core.test.ts new file mode 100644 index 000000000..edf789c0c --- /dev/null +++ b/tests/tags-core.test.ts @@ -0,0 +1,91 @@ +import { describe, test, expect } from 'bun:test'; +import { normalizeTag, matchesTagFilter, normalizeColor, tagGroupDescriptor, tagHex, TAG_COLORS, MAX_TAG_LENGTH, type Tag } from '../src/lib/utils/tags-core'; + +describe('normalizeTag', () => { + test('trims and collapses whitespace', () => { + expect(normalizeTag(' home cloud ')).toBe('home cloud'); + }); + test('allows letters, digits and _ - . /', () => { + expect(normalizeTag('web/proxy')).toBe('web/proxy'); + expect(normalizeTag('v2.0_beta-1')).toBe('v2.0_beta-1'); + }); + test('rejects empty / non-string', () => { + expect(normalizeTag('')).toBeNull(); + expect(normalizeTag(' ')).toBeNull(); + expect(normalizeTag(null)).toBeNull(); + expect(normalizeTag(42)).toBeNull(); + }); + test('rejects illegal characters', () => { + for (const bad of ['a,b', 'a;b', 'a:b', 'a=b', 'a`b', 'a$b', 'a\tb'.replace('\t', '')]) { + expect(normalizeTag(bad)).toBeNull(); + } + }); + test('rejects an over-long tag', () => { + expect(normalizeTag('a'.repeat(MAX_TAG_LENGTH + 1))).toBeNull(); + expect(normalizeTag('a'.repeat(MAX_TAG_LENGTH))).toBe('a'.repeat(MAX_TAG_LENGTH)); + }); +}); + +describe('tagGroupDescriptor', () => { + const mk = (id: number, name: string, color = 'blue', icon: string | null = null): Tag => ({ id, name, color, icon }); + + test('untagged -> null (falls into the Untagged bucket)', () => { + expect(tagGroupDescriptor([])).toBeNull(); + }); + test('single tag: key=id, label=name, colour from that tag', () => { + const d = tagGroupDescriptor([mk(5, 'prod', 'red')]); + expect(d).toMatchObject({ key: '5', label: 'prod', color: tagHex('red') }); + }); + test('combination: sorted-id key and " + " joined label', () => { + // deliberately unsorted input + const d = tagGroupDescriptor([mk(9, 'infra'), mk(3, 'prod')]); + expect(d?.key).toBe('3+9'); + expect(d?.label).toBe('prod + infra'); + }); + test('colour + icons come from the first tag by id, icons in id order', () => { + const d = tagGroupDescriptor([mk(9, 'infra', 'green', 'wrench'), mk(3, 'prod', 'red', 'lock')]); + expect(d?.color).toBe(tagHex('red')); // tag id 3 wins + expect(d?.icons).toEqual(['lock', 'wrench']); // id order 3,9 + }); + test('order weight: fewer tags first, tie-broken by first id', () => { + const one = tagGroupDescriptor([mk(2, 'a')])!; + const oneHigher = tagGroupDescriptor([mk(7, 'b')])!; + const two = tagGroupDescriptor([mk(1, 'a'), mk(2, 'b')])!; + expect(one.order).toBeLessThan(oneHigher.order); // same size -> lower id first + expect(oneHigher.order).toBeLessThan(two.order); // 1-tag groups before 2-tag groups + }); +}); + +describe('matchesTagFilter', () => { + test('empty filter matches everything', () => { + expect(matchesTagFilter([], [])).toBe(true); + expect(matchesTagFilter(undefined, [])).toBe(true); + expect(matchesTagFilter([1], [])).toBe(true); + }); + test('ALL mode (default): item must carry every selected tag id', () => { + expect(matchesTagFilter([1, 2], [1])).toBe(true); + expect(matchesTagFilter([1, 2], [1, 2])).toBe(true); + expect(matchesTagFilter([1], [1, 2])).toBe(false); + expect(matchesTagFilter([1], [1, 2], 'all')).toBe(false); + }); + test('ANY mode: item must carry at least one selected tag id', () => { + expect(matchesTagFilter([1], [1, 2], 'any')).toBe(true); + expect(matchesTagFilter([3], [1, 2], 'any')).toBe(false); + expect(matchesTagFilter([2, 3], [1, 2], 'any')).toBe(true); + }); + test('untagged item with a non-empty filter never matches', () => { + expect(matchesTagFilter([], [1])).toBe(false); + expect(matchesTagFilter(undefined, [1])).toBe(false); + }); +}); + +describe('normalizeColor', () => { + test('accepts palette colours', () => { + for (const c of TAG_COLORS) expect(normalizeColor(c)).toBe(c); + }); + test('defaults unknown/invalid to slate', () => { + expect(normalizeColor('mauve')).toBe('slate'); + expect(normalizeColor(null)).toBe('slate'); + expect(normalizeColor(42)).toBe('slate'); + }); +}); From ef9e405a6f80a60220ed1798fa6c5cb82d4aac4e Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:46 +0200 Subject: [PATCH 03/32] add a toggle for the coloured group bands on the tag-grouped grids --- src/lib/components/TagFilter.svelte | 103 ++++++++ src/lib/components/data-grid/DataGrid.svelte | 98 ++++++- src/routes/containers/+page.svelte | 260 +++++++++++++------ src/routes/stacks/+page.svelte | 168 +++++++++++- 4 files changed, 540 insertions(+), 89 deletions(-) create mode 100644 src/lib/components/TagFilter.svelte diff --git a/src/lib/components/TagFilter.svelte b/src/lib/components/TagFilter.svelte new file mode 100644 index 000000000..1b6ac68ec --- /dev/null +++ b/src/lib/components/TagFilter.svelte @@ -0,0 +1,103 @@ + + + + + {#snippet child({ props })} + + {/snippet} + + + {#if groupBy !== undefined} +
+ + Group by tag + +
+ {#if showBands !== undefined && groupBy} + +
+ + Group colors + +
+ {/if} + {/if} + {#if showTags !== undefined} +
+ + Show tags + +
+ {/if} + {#if groupBy !== undefined || showTags !== undefined} +
+ {/if} + {#if tags.length === 0} +
No tags yet
+ {:else} + +
+ Match + (mode = m as TagFilterMode)} /> +
+
+ {#each tags as tag (tag.id)} + {@const isSel = selected.includes(tag.id)} + + {/each} +
+ {#if selected.length > 0} + + {/if} + {/if} +
+
diff --git a/src/lib/components/data-grid/DataGrid.svelte b/src/lib/components/data-grid/DataGrid.svelte index 93468dbbd..67891ee83 100644 --- a/src/lib/components/data-grid/DataGrid.svelte +++ b/src/lib/components/data-grid/DataGrid.svelte @@ -11,6 +11,7 @@ import type { GridId, ColumnConfig, ColumnPreference } from '$lib/types'; import type { DataGridSortState, DataGridRowState } from './types'; import { setDataGridContext } from './context'; + import { groupData, type GroupDescriptor, type DataGridGroup } from './grouping-core'; // Props interface Props { @@ -59,6 +60,18 @@ // Selection filter - return false to make an item non-selectable selectableFilter?: (item: T) => boolean; + // Visual grouping (standard, non-virtual mode only; OFF by default). + // When `groupBy` is set, rows are partitioned into collapsible sections with + // a coloured header. When it is undefined the render path is byte-for-byte + // the ungrouped grid. + groupBy?: (item: T) => GroupDescriptor | null; + collapsedGroups?: Set; + ungroupedLabel?: string; + /** Draw the coloured left accent band spanning each group (default true). */ + showGroupBands?: boolean; + /** Optional custom header content (e.g. tag chips/icons) rendered inside the group pill. */ + groupHeaderLabel?: Snippet<[DataGridGroup]>; + // Expandable rows expandable?: boolean; expandedKeys?: Set; @@ -101,6 +114,11 @@ windowTotal, onWindowShift, onVisibleRangeChange, + groupBy, + collapsedGroups = $bindable(new Set()), + ungroupedLabel = 'Untagged', + showGroupBands = true, + groupHeaderLabel, onRowClick, highlightedKey, rowClass, @@ -456,6 +474,28 @@ return cachedVisibleData; }); + // Grouping (standard mode only). Empty when `groupBy` is not supplied, so the + // ungrouped body is chosen and nothing here runs. + const groups = $derived.by[]>(() => + groupBy ? groupData(data, groupBy, ungroupedLabel) : [] + ); + function toggleGroup(key: string) { + const collapsed = collapsedGroups.has(key); + const next = new Set(collapsedGroups); + if (collapsed) next.delete(key); else next.add(key); + collapsedGroups = next; + } + // Global, stable row index across all groups (for getRowState cache validity). + const groupIndexMap = $derived.by(() => { + const m = new Map(); + let i = 0; + for (const g of groups) for (const item of g.items) m.set(item, i++); + return m; + }); + function groupRowIndex(item: T): number { + return groupIndexMap.get(item) ?? 0; + } + // Windowed rows for the absolute range [startIndex, endIndex): each position is // the loaded row or undefined (→ a loading placeholder row). const windowedVisible = $derived.by<(T | undefined)[]>(() => { @@ -974,10 +1014,57 @@ {/snippet} + +{#snippet groupedBody()} + {@const totalCols = fixedStartCols.length + orderedColumns.length + fixedEndCols.length} + + {#each groups as group (group.key)} + {@const collapsed = collapsedGroups.has(group.key)} + {@const hex = group.color} + {@const band = !showGroupBands ? 'transparent' : (hex ?? 'var(--color-muted-foreground)')} + + + + + + + {#if !collapsed} + {#each group.items as item (item[keyField])} + {@render dataRow(item, getRowState(item, groupRowIndex(item)))} + {/each} + {/if} + + {/each} +{/snippet} + {#snippet tableContent()} {@render tableHeader()} - {@render tableBody()} + {#if groupBy} + {@render groupedBody()} + {:else} + {@render tableBody()} + {/if}
{/snippet} @@ -1027,3 +1114,12 @@ {@render tableContent()} {/if}
+ + diff --git a/src/routes/containers/+page.svelte b/src/routes/containers/+page.svelte index 1910e32a1..e565eeaa5 100644 --- a/src/routes/containers/+page.svelte +++ b/src/routes/containers/+page.svelte @@ -7,6 +7,7 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; import { toast } from 'svelte-sonner'; + import { containerMatchesSearch } from '$lib/utils/container-search-core'; import * as Dialog from '$lib/components/ui/dialog'; import * as Popover from '$lib/components/ui/popover'; import * as Select from '$lib/components/ui/select'; @@ -22,6 +23,7 @@ import { Switch } from '$lib/components/ui/switch'; import { Label } from '$lib/components/ui/label'; import { Input } from '$lib/components/ui/input'; + import { SearchInput } from '$lib/components/ui/search-input'; import { Play, Square, @@ -38,7 +40,6 @@ ArrowUpDown, ArrowUp, ArrowDown, - Search, ExternalLink, Globe, LayoutPanelLeft, @@ -62,8 +63,6 @@ Shield, ShieldCheck, Box, - Ship, - Cable, Copy, Loader2, AlertCircle, @@ -85,12 +84,17 @@ import VersionUpdateBadge from '$lib/components/VersionUpdateBadge.svelte'; import VersionUpdateModal from '$lib/components/VersionUpdateModal.svelte'; import type { ContainerInfo, TerminalMode } from '$lib/types'; + import { matchesTagFilter, tagGroupDescriptor, type Tag as UserTag, type TagColor } from '$lib/utils/tags-core'; + import TagChips from '$lib/components/TagChips.svelte'; + import TagEditPopover from '$lib/components/TagEditPopover.svelte'; + import TagFilter from '$lib/components/TagFilter.svelte'; + import TagLucideIcon from '$lib/components/TagLucideIcon.svelte'; import { EmptyState, NoEnvironment } from '$lib/components/ui/empty-state'; import { currentEnvironment, environments, appendEnvParam, clearStaleEnvironment } from '$lib/stores/environment'; import { containerStore } from '$lib/stores/containers'; import { onDockerEvent, isContainerListChange } from '$lib/stores/events'; import { appSettings } from '$lib/stores/settings'; - import { canAccess } from '$lib/stores/auth'; + import { canAccess, isAdmin } from '$lib/stores/auth'; import { vulnerabilityCriteriaIcons } from '$lib/utils/update-steps'; import { compareIps } from '$lib/utils/ip'; import { parseTimeStringToSeconds } from '$lib/utils/parse-uptime'; @@ -124,6 +128,111 @@ iconOverrides = {}; } } + + // User-defined tags: assignments (name -> tagId[]) + the catalog. + let tagsMap = $state>({}); + let tagCatalog = $state([]); + const tagById = $derived(new Map(tagCatalog.map((t) => [t.id, t]))); + async function loadTags(forEnvId: number | null) { + try { + const res = await fetch(appendEnvParam('/api/container-tags', forEnvId)); + tagsMap = res.ok ? await res.json() : {}; + } catch { + tagsMap = {}; + } + } + async function loadTagCatalog() { + // The tag catalog is global (not env-scoped); assignments load per env. + try { + const res = await fetch('/api/tags'); + tagCatalog = res.ok ? (await res.json()).tags : []; + } catch { + tagCatalog = []; + } + // Drop any persisted filter id that no longer exists in the catalog (a + // deleted tag, or a wiped DB) - otherwise a stale id filters the whole + // list to empty with no visible cause. + const valid = new Set(tagCatalog.map((t) => t.id)); + if (tagFilter.some((id) => !valid.has(id))) tagFilter = tagFilter.filter((id) => valid.has(id)); + } + // Tag filter, persisted per browser so it survives a refresh. + const TAG_FILTER_KEY = 'dockhand-containers-tag-filter'; + const TAG_FILTER_MODE_KEY = 'dockhand-containers-tag-filter-mode'; + let tagFilter = $state(loadTagFilter()); + let tagFilterMode = $state<'all' | 'any'>(loadTagFilterMode()); + function loadTagFilter(): number[] { + if (typeof window === 'undefined') return []; + try { const s = localStorage.getItem(TAG_FILTER_KEY); return s ? JSON.parse(s) : []; } catch { return []; } + } + function loadTagFilterMode(): 'all' | 'any' { + if (typeof window === 'undefined') return 'any'; + const s = localStorage.getItem(TAG_FILTER_MODE_KEY); + return s === 'all' || s === 'any' ? s : 'any'; + } + $effect(() => { + const f = tagFilter, m = tagFilterMode; + if (typeof window === 'undefined') return; + localStorage.setItem(TAG_FILTER_KEY, JSON.stringify(f)); + localStorage.setItem(TAG_FILTER_MODE_KEY, m); + }); + function tagsFor(name: string): UserTag[] { + return (tagsMap[name] ?? []).map((id) => tagById.get(id)).filter((t): t is UserTag => !!t); + } + + // Group-by-tag: partition rows by their unique tag COMBINATION (a container with + // prod+infra forms its own group, distinct from just prod). Persisted per browser. + const GROUP_BY_TAG_KEY = 'dockhand-containers-group-by-tag'; + const COLLAPSED_GROUPS_KEY = 'dockhand-containers-collapsed-groups'; + const SHOW_TAGS_KEY = 'dockhand-containers-show-tags'; + const SHOW_BANDS_KEY = 'dockhand-containers-group-bands'; + // Show tag chips on rows (default true - only '0' hides them). + let showTags = $state(typeof window === 'undefined' || localStorage.getItem(SHOW_TAGS_KEY) !== '0'); + // Coloured group bands (default true - only '0' hides them). + let showBands = $state(typeof window === 'undefined' || localStorage.getItem(SHOW_BANDS_KEY) !== '0'); + $effect(() => { + if (typeof window === 'undefined') return; + localStorage.setItem(SHOW_TAGS_KEY, showTags ? '1' : '0'); + }); + $effect(() => { + if (typeof window === 'undefined') return; + localStorage.setItem(SHOW_BANDS_KEY, showBands ? '1' : '0'); + }); + let groupByTag = $state(typeof window !== 'undefined' && localStorage.getItem(GROUP_BY_TAG_KEY) === '1'); + let collapsedGroups = $state>(loadCollapsedGroups()); + function loadCollapsedGroups(): Set { + if (typeof window === 'undefined') return new Set(); + try { const s = localStorage.getItem(COLLAPSED_GROUPS_KEY); return new Set(s ? JSON.parse(s) : []); } catch { return new Set(); } + } + $effect(() => { + if (typeof window === 'undefined') return; + localStorage.setItem(GROUP_BY_TAG_KEY, groupByTag ? '1' : '0'); + }); + $effect(() => { + if (typeof window === 'undefined') return; + localStorage.setItem(COLLAPSED_GROUPS_KEY, JSON.stringify([...collapsedGroups])); + }); + const containerGroupBy = $derived(groupByTag ? (c: any) => tagGroupDescriptor(tagsFor(c.name)) : undefined); + async function createTag(name: string, color: TagColor, icon: string | null): Promise { + try { + const res = await fetch('/api/tags', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name, color, icon }) + }); + if (!res.ok) return null; + const tag = await res.json(); + await loadTagCatalog(); + return tag; + } catch { return null; } + } + async function applyContainerTags(name: string, tagIds: number[]) { + tagsMap = { ...tagsMap, [name]: tagIds }; + try { + await fetch(appendEnvParam(`/api/container-tags/${encodeURIComponent(name)}`, envId), { + method: 'PUT', headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ tagIds }) + }); + } catch { /* optimistic; reload on next env switch */ } + } const containerStats = $derived($containerStore.stats); const autoUpdateSettings = $derived($containerStore.autoUpdateSettings); const envHasScanning = $derived($containerStore.envHasScanning); @@ -230,12 +339,16 @@ // Refresh data (store handles loading state internally) containerStore.refresh(newEnvId); loadIconOverrides(newEnvId); + loadTags(newEnvId); + loadTagCatalog(); // global catalog; assignments come from loadTags } else if (!env) { // No environment - clear data and stop loading envId = null; shellDetectionCache = {}; containerStore.clear(); iconOverrides = {}; + tagsMap = {}; + tagCatalog = []; } }); let showCreateModal = $state(false); @@ -803,14 +916,15 @@ result = result.filter((c) => newerVersionsMap.has(c.id)); } - // Filter by search query + // Filter by search query (name, image, any label key/value, or a + // `label:key`/`label:key=value` filter - see containerMatchesSearch). if (searchQuery.trim()) { - const query = searchQuery.toLowerCase(); - result = result.filter(c => - c.name.toLowerCase().includes(query) || - c.image.toLowerCase().includes(query) || - (c.labels?.['com.docker.compose.project'] || '').toLowerCase().includes(query) - ); + result = result.filter(c => containerMatchesSearch(c, searchQuery)); + } + + // Filter by user-defined tags. + if (tagFilter.length > 0) { + result = result.filter((c) => matchesTagFilter(tagsMap[c.name], tagFilter, tagFilterMode)); } // Sort @@ -916,8 +1030,12 @@ return containerStore.refreshContainers(envId); } - // Check if highlightChanges is enabled for current environment - const highlightChangesEnabled = $derived($currentEnvironment?.highlightChanges ?? true); + // Check if highlightChanges is enabled for current environment. Read from the full + // environments list first (authoritative); the thin currentEnvironment store omits + // the flag on some switch paths, which otherwise reverts it to the default. + const highlightChangesEnabled = $derived( + currentEnvDetails?.highlightChanges ?? $currentEnvironment?.highlightChanges ?? true + ); // Helper to check if a stat field changed significantly function hasFieldChanged(containerId: string, field: string, oldVal: number | undefined, newVal: number | undefined): boolean { @@ -1430,16 +1548,7 @@
-
- - e.key === 'Escape' && (searchQuery = '')} - class="pl-8 h-8 w-48 text-sm" - /> -
+ @@ -1451,6 +1560,7 @@ width="w-44" defaultIcon={Box} /> +
{#if $canAccess('containers', 'create')} - {#if container.systemContainer} - {@const hasUpdate = containersWithUpdatesSet.has(container.id)} + + {#if container.systemContainer && containersWithUpdatesSet.has(container.id)} - - {#if container.systemContainer === 'dockhand'} - - {:else} - - {/if} - {container.systemContainer === 'dockhand' ? 'Dockhand' : 'Hawser'} - {#if hasUpdate} - - {/if} + + - {#if container.systemContainer === 'dockhand'} - {#if hasUpdate} - - {:else} -

Dockhand management container

- {/if} - {:else} - {#if hasUpdate} -
-

- - Update available -

-

Update on the remote host where Hawser runs.

- e.stopPropagation()} - > - - Update instructions on GitHub - -
+
+

+ + Update available +

+ {#if container.systemContainer === 'dockhand'} + e.stopPropagation()} + > + Settings > About + {:else} -

Hawser remote agent

+

Update on the remote host where Hawser runs.

+ e.stopPropagation()} + > + + Update instructions on GitHub + {/if} - {/if} +
{/if} + {#if showTags}{/if} + {#if $appSettings.inlineTagEditing && $canAccess('containers', 'edit')} + e.stopPropagation()} role="presentation"> + applyContainerTags(container.name, ids)} + allowCreate={$isAdmin} + /> + + {/if}
{:else if column.id === 'image'}
diff --git a/src/routes/stacks/+page.svelte b/src/routes/stacks/+page.svelte index 940e17988..3f036b2c5 100644 --- a/src/routes/stacks/+page.svelte +++ b/src/routes/stacks/+page.svelte @@ -4,17 +4,17 @@
@@ -367,28 +357,5 @@
- -
-
- - -
- - - {#each monospaceFonts as font} - {#if font.id === selectedEditorFont} - {font.name} - {/if} - {/each} - - - {#each monospaceFonts as font} - - {font.name} - - {/each} - - -
{/if}
From aba356e5bb8747460670af6a43e436047be6f5f7 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:46 +0200 Subject: [PATCH 05/32] keep populated git stack env vars visible in the editor after saving --- src/lib/env-merge.ts | 58 ++++++++++++++++ tests/env-merge.test.ts | 149 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 src/lib/env-merge.ts create mode 100644 tests/env-merge.test.ts diff --git a/src/lib/env-merge.ts b/src/lib/env-merge.ts new file mode 100644 index 000000000..222e59ed0 --- /dev/null +++ b/src/lib/env-merge.ts @@ -0,0 +1,58 @@ +// Merge a git stack's repo .env vars with its DB override vars for display in the +// editor. The save path stores only overrides (vars that differ from the repo .env, +// plus secrets), so a reopened editor would otherwise show only the changed vars - the +// untouched repo vars vanish even though the deploy still applies them. +// +// Precedence mirrors deploy (stacks.ts: repo .env first, .env.dockhand + secrets on +// top): file value is the base, a DB non-secret var overrides its key, a DB secret +// (masked '***') always wins over any same-named file key. + +import type { EnvVar } from '$lib/components/StackEnvVarsEditor.svelte'; + +export type { EnvVar }; + +// The load-bearing git-sync predicate: an editor var is stored to the DB only when it +// differs from the repo .env value, is new (no file entry), or is a secret. Everything +// file-equal and non-secret is dropped so the DB stays override-only. Shared by the +// modal's save filter, the re-populate preserve step, and the merge round-trip test so +// the invariant has one definition. +export function isGitStackOverride(v: EnvVar, fileVars: Record): boolean { + if (!v.key.trim()) return false; + const fileValue = fileVars[v.key]; + return fileValue === undefined || v.value !== fileValue || v.isSecret; +} + +export function mergeGitStackEnvVars( + fileVars: Record, + dbVars: EnvVar[] +): EnvVar[] { + const dbByKey = new Map(); + for (const v of dbVars) { + const key = v.key.trim(); + if (key) dbByKey.set(key, v); + } + + const merged: EnvVar[] = []; + const seen = new Set(); + + // File vars form the base, in file order. A DB var with the same key overrides it. + for (const [key, value] of Object.entries(fileVars)) { + const override = dbByKey.get(key); + if (override) { + merged.push({ key, value: override.value, isSecret: override.isSecret }); + } else { + merged.push({ key, value, isSecret: false }); + } + seen.add(key); + } + + // DB-only vars (user overrides / secrets with no file counterpart) keep their order. + for (const v of dbVars) { + const key = v.key.trim(); + if (!key || seen.has(key)) continue; + merged.push({ key, value: v.value, isSecret: v.isSecret }); + seen.add(key); + } + + return merged; +} diff --git a/tests/env-merge.test.ts b/tests/env-merge.test.ts new file mode 100644 index 000000000..0b9ad38e5 --- /dev/null +++ b/tests/env-merge.test.ts @@ -0,0 +1,149 @@ +/** + * Unit tests for mergeGitStackEnvVars + isGitStackOverride. + * + * A git stack's editor must show the full effective env set on reopen: the repo + * .env vars (base) plus the DB overrides/secrets on top. The save path stores only + * overrides (isGitStackOverride), so the merged output fed back through that predicate + * must still drop untouched file vars - otherwise a save would persist the whole .env + * into the DB and break git-sync pickup. + */ + +import { describe, test, expect } from 'bun:test'; +import { mergeGitStackEnvVars, isGitStackOverride, type EnvVar } from '../src/lib/env-merge'; + +describe('mergeGitStackEnvVars', () => { + test('(a) untouched file var is shown non-secret, straight from the file', () => { + const merged = mergeGitStackEnvVars({ TZ: 'Europe/Berlin' }, []); + expect(merged).toEqual([{ key: 'TZ', value: 'Europe/Berlin', isSecret: false }]); + }); + + test('(b) a DB non-secret override wins over the file value', () => { + const merged = mergeGitStackEnvVars( + { TZ: 'UTC', PORT: '8080' }, + [{ key: 'TZ', value: 'Europe/Berlin', isSecret: false }] + ); + expect(merged).toEqual([ + { key: 'TZ', value: 'Europe/Berlin', isSecret: false }, + { key: 'PORT', value: '8080', isSecret: false } + ]); + }); + + test('(c) a DB-only user var (no file entry) is preserved', () => { + const merged = mergeGitStackEnvVars( + { TZ: 'UTC' }, + [{ key: 'EXTRA', value: 'x', isSecret: false }] + ); + expect(merged).toEqual([ + { key: 'TZ', value: 'UTC', isSecret: false }, + { key: 'EXTRA', value: 'x', isSecret: false } + ]); + }); + + test('(d) a DB secret (masked) wins over a same-named file key and stays secret', () => { + const merged = mergeGitStackEnvVars( + { API_KEY: 'plain-from-file', TZ: 'UTC' }, + [{ key: 'API_KEY', value: '***', isSecret: true }] + ); + expect(merged).toEqual([ + { key: 'API_KEY', value: '***', isSecret: true }, + { key: 'TZ', value: 'UTC', isSecret: false } + ]); + }); + + test('(e) empty fileVars (default .env missing) yields just the DB set', () => { + const merged = mergeGitStackEnvVars({}, [ + { key: 'OVERRIDE', value: 'v', isSecret: false }, + { key: 'SECRET', value: '***', isSecret: true } + ]); + expect(merged).toEqual([ + { key: 'OVERRIDE', value: 'v', isSecret: false }, + { key: 'SECRET', value: '***', isSecret: true } + ]); + }); + + test('(g) DB keys are trimmed and blank DB keys are dropped', () => { + // A padded key must override the same file key (not append a duplicate row); + // a whitespace-only key must be dropped entirely. + const merged = mergeGitStackEnvVars({ TZ: 'UTC' }, [ + { key: ' TZ ', value: 'X', isSecret: false }, + { key: ' ', value: 'phantom', isSecret: false } + ]); + expect(merged).toEqual([{ key: 'TZ', value: 'X', isSecret: false }]); + }); +}); + +describe('isGitStackOverride (the save/preserve predicate)', () => { + const fileVars = { TZ: 'UTC', PORT: '8080' }; + + test('drops a blank key', () => { + expect(isGitStackOverride({ key: ' ', value: 'x', isSecret: false }, fileVars)).toBe(false); + }); + test('drops a non-secret var equal to the file value', () => { + expect(isGitStackOverride({ key: 'TZ', value: 'UTC', isSecret: false }, fileVars)).toBe(false); + }); + test('keeps a non-secret var that differs from the file value', () => { + expect(isGitStackOverride({ key: 'PORT', value: '9090', isSecret: false }, fileVars)).toBe(true); + }); + test('keeps a var with no file counterpart', () => { + expect(isGitStackOverride({ key: 'NEW', value: 'y', isSecret: false }, fileVars)).toBe(true); + }); + test('keeps a secret even when equal to the file value', () => { + expect(isGitStackOverride({ key: 'TZ', value: 'UTC', isSecret: true }, fileVars)).toBe(true); + }); +}); + +describe('round-trip: merge output through the save predicate persists nothing new', () => { + test('(f) merged output drops untouched file vars, keeps override + secret', () => { + const fileVars = { TZ: 'UTC', PORT: '8080', HOST: 'localhost' }; + const dbVars: EnvVar[] = [ + { key: 'PORT', value: '9090', isSecret: false }, // real override + { key: 'API_KEY', value: '***', isSecret: true } // secret, no file entry + ]; + + const merged = mergeGitStackEnvVars(fileVars, dbVars); + // The editor shows everything: TZ, PORT(override), HOST, API_KEY. + expect(merged.map((v) => v.key)).toEqual(['TZ', 'PORT', 'HOST', 'API_KEY']); + + // Saving persists ONLY the override + the secret - the untouched TZ/HOST + // (equal to file) are dropped, so the DB stays override-only (git-sync intact). + const persisted = merged.filter((v) => isGitStackOverride(v, fileVars)); + expect(persisted).toEqual([ + { key: 'PORT', value: '9090', isSecret: false }, + { key: 'API_KEY', value: '***', isSecret: true } + ]); + }); + + test('(f2) round-trip with NO overrides persists nothing (pure untouched .env)', () => { + const fileVars = { A: '1', B: '2' }; + const merged = mergeGitStackEnvVars(fileVars, []); + expect(merged.filter((v) => isGitStackOverride(v, fileVars))).toEqual([]); + }); +}); + +describe('re-populate never clobbers the current editor (the populateEnvVars path)', () => { + // populateEnvVars refreshes the file base from the repo, then merges the current + // editor (trimmed) on top. Merge lets the editor (DB side) win, so any value the + // user is looking at survives a re-populate; only NEW repo keys are added. This is + // the "don't clobber my edits" contract - a non-secret editor value that differs + // from the fresh repo cannot be distinguished from a real edit, so it is kept. + // The round-trip stays consistent: a kept value that differs from the fresh repo is + // then persisted as a real override and the deploy reflects exactly what was shown. + test('editor values win; new repo keys are added', () => { + const currentEditor: EnvVar[] = [ + { key: 'TZ', value: 'UTC', isSecret: false }, // kept (differs from fresh repo) + { key: 'PORT', value: '9090', isSecret: false }, // user override, kept + { key: 'API_KEY', value: '***', isSecret: true }, // secret, kept + { key: ' ', value: 'blank', isSecret: false } // blank key, dropped + ]; + const freshRepo = { TZ: 'Europe/Berlin', PORT: '80', HOST: 'example' }; + + const merged = mergeGitStackEnvVars(freshRepo, currentEditor.filter((v) => v.key.trim())); + + expect(merged).toEqual([ + { key: 'TZ', value: 'UTC', isSecret: false }, // editor value wins (not clobbered) + { key: 'PORT', value: '9090', isSecret: false }, // override preserved + { key: 'HOST', value: 'example', isSecret: false }, // new repo var appears + { key: 'API_KEY', value: '***', isSecret: true } // secret preserved + ]); + }); +}); From c1084f71ce4b98db50d3f36ba64de53ee6087763 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:46 +0200 Subject: [PATCH 06/32] don't send container died/killed notifications for a container being updated --- src/lib/server/expected-events-core.ts | 75 +++++++++++++++++++++ src/lib/server/subprocess-manager.ts | 7 +- tests/expected-events-core.test.ts | 91 ++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/expected-events-core.ts create mode 100644 tests/expected-events-core.test.ts diff --git a/src/lib/server/expected-events-core.ts b/src/lib/server/expected-events-core.ts new file mode 100644 index 000000000..3ebec3f67 --- /dev/null +++ b/src/lib/server/expected-events-core.ts @@ -0,0 +1,75 @@ +/** + * Suppresses the die/kill/stop notifications that an auto-update deliberately + * causes. When Dockhand recreates a container to update its image, it stops the + * old container - Docker then emits kill/die/stop events that are EXPECTED, not a + * crash, but they used to notify the user as "Container died" (#68). + * + * A container id is marked "expected" for a short window before the update stops + * it; the event handler checks this and skips the notification for the noisy + * lifecycle actions only. A genuine crash AFTER the window still alarms. Pure, + * in-memory, unit-tested - no timers, expiry is checked lazily against `now`. + */ + +/** Actions an auto-update legitimately triggers, whose notification is noise. */ +const SUPPRESSED_ACTIONS = new Set(['die', 'kill', 'stop']); + +export class ExpectedEventsTracker { + // containerId -> expiry epoch-ms. Kept small: entries are dropped on check. + private readonly expiry = new Map(); + + /** Mark a container's imminent stop/kill as expected for `ttlMs` from `now`. */ + markExpected(containerId: string, now: number, ttlMs: number): void { + if (!containerId) return; + this.expiry.set(containerId, now + ttlMs); + } + + /** + * True when this action for this container should NOT notify: it is a + * die/kill/stop for a container marked expected and still within its window. + * A non-suppressed action (start, oom, health) always returns false, so those + * still notify even mid-update. Expired/unknown ids return false. + */ + shouldSuppress(containerId: string, action: string, now: number): boolean { + // Opportunistically drop everything already past its window so happy-path + // entries (whose id never emits another event to lazily expire them) can't + // accumulate for the process lifetime. Cheap: the map holds at most a handful + // of in-flight updates at once. + this.prune(now); + if (!SUPPRESSED_ACTIONS.has(action)) return false; + const exp = this.expiry.get(containerId); + if (exp === undefined) return false; + // A single update legitimately emits die AND kill AND stop for the same id, so + // do NOT delete on a suppressed hit (that would let the 2nd/3rd through); the + // prune above reclaims the entry once its window passes. + return now <= exp; + } + + /** Clear a container's mark, e.g. when an update rolls back and restarts it so a + * later genuine crash of that restored container is NOT wrongly suppressed. */ + clear(containerId: string): void { + this.expiry.delete(containerId); + } + + /** Drop all entries whose window has passed (called opportunistically). */ + prune(now: number): void { + for (const [id, exp] of this.expiry) { + if (now > exp) this.expiry.delete(id); + } + } + + /** Test/introspection helper. */ + size(): number { + return this.expiry.size; + } +} + +/** How long after marking a container its expected stop/kill stays suppressed. */ +export const EXPECTED_EVENT_TTL_MS = 30_000; + +/** + * Process-wide shared tracker. docker.ts marks a container before an auto-update + * stops it; subprocess-manager.ts checks it before notifying. Kept in this + * import-light module so neither of those (which don't import each other) creates + * a cycle - same pattern as token-cache.ts. + */ +export const expectedEvents = new ExpectedEventsTracker(); diff --git a/src/lib/server/subprocess-manager.ts b/src/lib/server/subprocess-manager.ts index dfe44c656..3ba34a233 100644 --- a/src/lib/server/subprocess-manager.ts +++ b/src/lib/server/subprocess-manager.ts @@ -25,6 +25,7 @@ import { } from './db'; import { sendEnvironmentNotification, sendEventNotification } from './notifications'; import { isNotifyDisabledByLabel } from './container-labels'; +import { expectedEvents } from './expected-events-core'; import { rssBeforeOp, rssAfterOp } from './rss-tracker'; import { pushMetric } from './metrics-store'; @@ -322,8 +323,10 @@ async function handleContainerEvent(msg: GoMessage): Promise { // Sub-category: notification const notifBefore = rssBeforeOp(); - // Check dockhand.notify label — Docker includes container labels in event Actor.Attributes - if (!isNotifyDisabledByLabel(event.Actor?.Attributes)) { + // Check dockhand.notify label — Docker includes container labels in event Actor.Attributes. + // Also skip die/kill/stop that an in-progress update deliberately caused (#68). + const suppressExpected = expectedEvents.shouldSuppress(containerId, action, Date.now()); + if (!suppressExpected && !isNotifyDisabledByLabel(event.Actor?.Attributes)) { const actionLabel = action.startsWith('health_status') ? action.includes('unhealthy') ? 'Unhealthy' : 'Healthy' : action.charAt(0).toUpperCase() + action.slice(1); diff --git a/tests/expected-events-core.test.ts b/tests/expected-events-core.test.ts new file mode 100644 index 000000000..d4cd1603b --- /dev/null +++ b/tests/expected-events-core.test.ts @@ -0,0 +1,91 @@ +import { describe, test, expect } from 'bun:test'; +import { ExpectedEventsTracker } from '../src/lib/server/expected-events-core'; + +const T0 = 1_000_000; +const TTL = 30_000; + +describe('ExpectedEventsTracker', () => { + test('suppresses die/kill/stop for a marked container within the window', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + for (const a of ['die', 'kill', 'stop']) { + expect(t.shouldSuppress('abc', a, T0 + 1000)).toBe(true); + } + }); + + test('does NOT suppress start/oom/health even mid-update (only the noisy actions)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + for (const a of ['start', 'oom', 'health_status: unhealthy', 'create', 'restart']) { + expect(t.shouldSuppress('abc', a, T0 + 1000)).toBe(false); + } + }); + + test('does NOT suppress an unmarked container (a genuine crash of something else)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + expect(t.shouldSuppress('other', 'die', T0 + 1000)).toBe(false); + }); + + test('does NOT suppress after the window expires (a later real crash still alarms)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + expect(t.shouldSuppress('abc', 'die', T0 + TTL + 1)).toBe(false); + }); + + test('at exactly the expiry boundary is still within (now > exp is the cutoff)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + expect(t.shouldSuppress('abc', 'die', T0 + TTL)).toBe(true); // now == exp -> not > exp + expect(t.shouldSuppress('abc', 'die', T0 + TTL + 1)).toBe(false); + }); + + test('checking an expired entry drops it (lazy cleanup)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + expect(t.size()).toBe(1); + t.shouldSuppress('abc', 'die', T0 + TTL + 1); // expired -> deleted + expect(t.size()).toBe(0); + }); + + test('empty containerId is ignored', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('', T0, TTL); + expect(t.size()).toBe(0); + }); + + test('clear drops a mark so a later genuine crash is NOT suppressed (rollback case)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + t.clear('abc'); + expect(t.shouldSuppress('abc', 'die', T0 + 1000)).toBe(false); + expect(t.size()).toBe(0); + }); + + test('does not leak: a check prunes OTHER expired entries (happy-path cleanup)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('done', T0, TTL); // expires at T0+30000 + t.markExpected('live', T0 + 50_000, TTL); // expires at T0+80000 + // A check AFTER 'done' expired but BEFORE 'live' expires reclaims 'done' even + // though 'done' never got another event of its own. + t.shouldSuppress('live', 'die', T0 + 60_000); + expect(t.size()).toBe(1); // only 'live' remains + }); + + test('suppressed hit does NOT drop the entry (die+kill+stop of one update all suppressed)', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('abc', T0, TTL); + expect(t.shouldSuppress('abc', 'die', T0 + 100)).toBe(true); + expect(t.shouldSuppress('abc', 'kill', T0 + 200)).toBe(true); + expect(t.shouldSuppress('abc', 'stop', T0 + 300)).toBe(true); // still suppressed within window + }); + + test('prune removes only expired entries', () => { + const t = new ExpectedEventsTracker(); + t.markExpected('a', T0, TTL); + t.markExpected('b', T0 + 20_000, TTL); + t.prune(T0 + TTL + 1); // 'a' expired, 'b' still valid + expect(t.size()).toBe(1); + expect(t.shouldSuppress('b', 'die', T0 + 25_000)).toBe(true); + }); +}); From 0cc8c1a8c87f2ebadd609675e60c6ca7276367c0 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 07/32] skip hidden folders when scanning for stacks to adopt --- src/lib/server/stack-scanner.ts | 7 +++---- src/lib/utils/scan-skip.ts | 12 ++++++++++++ tests/scan-skip.test.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/lib/utils/scan-skip.ts create mode 100644 tests/scan-skip.test.ts diff --git a/src/lib/server/stack-scanner.ts b/src/lib/server/stack-scanner.ts index 4e78e882b..cd9272f90 100644 --- a/src/lib/server/stack-scanner.ts +++ b/src/lib/server/stack-scanner.ts @@ -11,12 +11,11 @@ import yaml from 'js-yaml'; import { getExternalStackPaths, getStackSources, upsertStackSource, type StackSourceType } from './db'; import { DockerConnectionError } from './docker'; import { normalizeStackName } from '$lib/utils/stack-name'; +import { shouldSkipScanDir } from '$lib/utils/scan-skip'; // Compose file patterns to detect (in order of priority - prefer new style first) const COMPOSE_PATTERNS = ['compose.yaml', 'compose.yml', 'docker-compose.yml', 'docker-compose.yaml']; -// Directories to skip during scanning -const SKIP_DIRECTORIES = ['.git', 'node_modules', '.docker', '__pycache__', '.venv', 'venv']; // Maximum recursion depth to prevent runaway scanning const MAX_DEPTH = 5; @@ -149,8 +148,8 @@ async function scanPath(basePath: string): Promise<{ stacks: DiscoveredStack[]; const entryPath = join(currentPath, entry.name); if (entry.isDirectory()) { - // Skip excluded directories - if (SKIP_DIRECTORIES.includes(entry.name)) continue; + // Skip excluded and hidden (dot) directories (#1251). + if (shouldSkipScanDir(entry.name)) continue; // Skip if we already found a compose file here if (foundStackDirs.has(entryPath)) continue; diff --git a/src/lib/utils/scan-skip.ts b/src/lib/utils/scan-skip.ts new file mode 100644 index 000000000..466685890 --- /dev/null +++ b/src/lib/utils/scan-skip.ts @@ -0,0 +1,12 @@ +// Whether the stack-adoption scan should skip a directory (#1251). Pure + import-light so +// it's unit-testable without pulling in the scanner's db/docker deps. + +// Known noise directories that never hold an adoptable stack. +export const SKIP_DIRECTORIES = ['.git', 'node_modules', '.docker', '__pycache__', '.venv', 'venv']; + +// Skip a known noise dir, or any hidden (dot-prefixed) dir. Dotfolders like btrfs +// `.snapshots` otherwise surface one duplicate stack per snapshot; a stack directory is +// never legitimately dot-prefixed. +export function shouldSkipScanDir(name: string): boolean { + return SKIP_DIRECTORIES.includes(name) || name.startsWith('.'); +} diff --git a/tests/scan-skip.test.ts b/tests/scan-skip.test.ts new file mode 100644 index 000000000..17f79d966 --- /dev/null +++ b/tests/scan-skip.test.ts @@ -0,0 +1,31 @@ +import { describe, test, expect } from 'bun:test'; +import { shouldSkipScanDir, SKIP_DIRECTORIES } from '../src/lib/utils/scan-skip'; + +describe('shouldSkipScanDir', () => { + test('skips hidden (dot-prefixed) directories, e.g. btrfs .snapshots (#1251)', () => { + expect(shouldSkipScanDir('.snapshots')).toBe(true); + expect(shouldSkipScanDir('.git')).toBe(true); + expect(shouldSkipScanDir('.cache')).toBe(true); + expect(shouldSkipScanDir('.anything')).toBe(true); + }); + + test('skips the known noise directories', () => { + for (const d of SKIP_DIRECTORIES) { + expect(shouldSkipScanDir(d)).toBe(true); + } + expect(shouldSkipScanDir('node_modules')).toBe(true); + expect(shouldSkipScanDir('venv')).toBe(true); + }); + + test('does NOT skip normal stack directories', () => { + expect(shouldSkipScanDir('my-stack')).toBe(false); + expect(shouldSkipScanDir('nginx')).toBe(false); + expect(shouldSkipScanDir('docker')).toBe(false); // only .docker is skipped, not docker + expect(shouldSkipScanDir('snapshots')).toBe(false); // only .snapshots is hidden + }); + + test('a name with a dot inside (not prefix) is not treated as hidden', () => { + expect(shouldSkipScanDir('my.stack')).toBe(false); + expect(shouldSkipScanDir('v1.2.3')).toBe(false); + }); +}); From 1f8c4a340588cd71fee35d9de92918b0ea6d8854 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 08/32] resolve secret-provider values for all stack lifecycle operations --- src/lib/server/stacks.ts | 114 ++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 26 deletions(-) diff --git a/src/lib/server/stacks.ts b/src/lib/server/stacks.ts index 3906965a7..24800f157 100644 --- a/src/lib/server/stacks.ts +++ b/src/lib/server/stacks.ts @@ -2521,9 +2521,11 @@ export async function startStack( const containers = await getStackContainers(stackName, envId); const operation = containers.length > 0 ? 'start' : 'up'; - if (operation === 'up') { - await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); - } + // Resolve secret-provider values for BOTH operations: `docker compose start` + // parses and interpolates the compose file too, so a stack with required + // provider secrets (${VAR:?required}) fails to start without them - e.g. the + // post-backup restart of a stopped stack (#1579). + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); const startResult = await executeComposeCommand( operation, @@ -2561,6 +2563,11 @@ export async function stopStack( // sourceType is plumbed through from requireComposeFile to avoid a redundant DB lookup. const isGitStack = result.sourceType === 'git'; + // `docker compose stop` interpolates the compose file too, so a stack with required + // provider secrets (${VAR:?required}) fails to stop without them - e.g. the + // stop-during-backup path (#1579). + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); + const composeResult = await executeComposeCommand( 'stop', { stackName, envId, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack, stackFiles: await lifecycleStackFiles(result.stackDir) }, @@ -2613,10 +2620,14 @@ export async function restartStack( let composeResult: StackOperationResult; + // Resolve secret-provider values up front: every restart mode ends in a compose + // command (up/start/restart) that interpolates the compose file, so a stack with + // required provider secrets (${VAR:?required}) fails without them (#1579). + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); + if (mode === 'recreate') { // Stop first, then bring up with --force-recreate to ensure new container IDs await executeComposeCommand('stop', opts, result.content!, result.nonSecretVars, result.secretVars, onLine); - await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); composeResult = await executeComposeCommand('up', { ...opts, forceRecreate: true }, result.content!, result.nonSecretVars, result.secretVars, onLine); } else if (mode === 'ordered') { // Stop everything, then start in depends_on order (compose start honors the @@ -2654,6 +2665,11 @@ export async function downStack( // sourceType is plumbed through from requireComposeFile to avoid a redundant DB lookup. const isGitStack = result.sourceType === 'git'; + // `docker compose down` interpolates the compose file too, so a stack with required + // provider secrets (${VAR:?required}) fails to come down without them (#1579). + // bestEffort: an unreachable provider must not block tearing a stack down. + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`, true); + const composeResult = await executeComposeCommand( 'down', { stackName, envId, removeVolumes, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack, stackFiles: await lifecycleStackFiles(result.stackDir) }, @@ -2754,8 +2770,22 @@ export async function removeStack( // If compose file exists, run docker compose down first if (composeResult.success) { - const envVars = await getNonSecretEnvVarsAsRecord(stackName, envId); - const secretVars = await getSecretEnvVarsAsRecord(stackName, envId); + // `docker compose down` interpolates the compose file, so a stack with + // required provider secrets (${VAR:?required}) needs them resolved to come + // down (#1579). bestEffort: an unreachable provider must not block removal. + // suggestedEnvPath covers custom-path stacks whose stored envPath is null but + // have a real sibling .env (the selector/refs may live only there). + const resolved = await resolveProviderVarsBestEffort( + stackName, + envId, + await getNonSecretEnvVarsAsRecord(stackName, envId), + await getSecretEnvVarsAsRecord(stackName, envId), + composeResult.envPath ?? composeResult.suggestedEnvPath, + `[Stack:${stackName}]`, + true + ); + const envVars = resolved.nonSecretVars; + const secretVars = resolved.secretVars; // Stack removal cleanup (#1162): the agent deletes ONLY what Dockhand // explicitly lists. The list is the local staging dir contents — exactly @@ -3733,6 +3763,49 @@ async function resolveProviderEnvVars( return { dbNonSecretVars, secretVars, injectedProviderKeys: injectedProviderKeys() }; } +/** + * Resolve the bound provider's secrets over a raw (nonSecretVars, secretVars) pair. + * Returns the merged vars. bestEffort=true (tear-down paths) logs and returns the + * inputs unchanged if the provider is unreachable, so a down/remove is never blocked + * by a dead provider. The single source of truth both the compose-result helper and + * removeStack use, so envPath derivation cannot drift between them. + */ +async function resolveProviderVarsBestEffort( + stackName: string, + envId: number | null | undefined, + nonSecretVars: Record, + secretVars: Record, + envPath: string | null | undefined, + logPrefix: string, + bestEffort = false +): Promise<{ nonSecretVars: Record; secretVars: Record }> { + let envFileContent: string | undefined; + if (envPath && existsSync(envPath)) { + try { + envFileContent = readFileSync(envPath, 'utf-8'); + } catch (err) { + console.warn(`${logPrefix} Failed to read .env at ${envPath}:`, err); + } + } + + try { + const source = await getStackSource(stackName, envId ?? undefined); + const resolved = await resolveProviderEnvVars( + { ...nonSecretVars }, + { ...secretVars }, + logPrefix, + source?.secretProviderId, + envFileContent, + { stackName, envId: envId ?? undefined } + ); + return { nonSecretVars: resolved.dbNonSecretVars, secretVars: resolved.secretVars }; + } catch (err) { + if (!bestEffort) throw err; + console.warn(`${logPrefix} Provider secret resolution failed, proceeding without provider secrets:`, err); + return { nonSecretVars, secretVars }; + } +} + /** * Resolve the bound provider's secrets for a compose result produced by * requireComposeFile(). Mutates result.secretVars / result.nonSecretVars in @@ -3743,30 +3816,19 @@ async function applyProviderSecretsToComposeResult( result: RequireComposeResult, stackName: string, envId: number | null | undefined, - logPrefix: string + logPrefix: string, + // Tear-down paths (down/remove) pass bestEffort: a provider that is unreachable + // must not block bringing a stack down, so a resolve error is logged and the + // compose command proceeds with whatever vars are on disk/DB. + bestEffort = false ): Promise { if (!result.success || !result.secretVars || !result.nonSecretVars) return; - let envFileContent: string | undefined; - if (result.envPath && existsSync(result.envPath)) { - try { - envFileContent = readFileSync(result.envPath, 'utf-8'); - } catch (err) { - console.warn(`${logPrefix} Failed to read .env at ${result.envPath}:`, err); - } - } - - const source = await getStackSource(stackName, envId ?? undefined); - const { dbNonSecretVars, secretVars } = await resolveProviderEnvVars( - { ...result.nonSecretVars }, - { ...result.secretVars }, - logPrefix, - source?.secretProviderId, - envFileContent, - { stackName, envId: envId ?? undefined } + const resolved = await resolveProviderVarsBestEffort( + stackName, envId, result.nonSecretVars, result.secretVars, result.envPath, logPrefix, bestEffort ); - result.nonSecretVars = dbNonSecretVars; - result.secretVars = secretVars; + result.nonSecretVars = resolved.nonSecretVars; + result.secretVars = resolved.secretVars; } // ============================================================================= From 03b335d6466967356c4942a6649fa9c880cdc455 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 09/32] update Podman Quadlet containers by handing the recreate to systemd --- src/lib/server/systemd-recreate-core.ts | 58 +++++++++++++++ tests/systemd-recreate-core.test.ts | 94 +++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/lib/server/systemd-recreate-core.ts create mode 100644 tests/systemd-recreate-core.test.ts diff --git a/src/lib/server/systemd-recreate-core.ts b/src/lib/server/systemd-recreate-core.ts new file mode 100644 index 000000000..c9591792c --- /dev/null +++ b/src/lib/server/systemd-recreate-core.ts @@ -0,0 +1,58 @@ +// Pure decision helpers for recreating a Podman Quadlet / systemd-managed container. +// Import-light (no docker/db) so the respawn-detection logic is unit-testable without a +// live Podman socket. + +export interface FoundContainer { + Id: string; + State: string; +} + +/** + * Classify what a name-lookup found while polling for the unit to respawn the container + * after a stop. `oldId` is the container we stopped. + * - 'respawned-running': a NEW id, running -> the recreate succeeded (fresh container + * from the unit's `podman run --replace` on the new image). + * - 'respawned-not-running': a NEW id, not yet/no longer running (created/exited/ + * restarting) -> respawned but not healthy; keep polling, and on timeout this is a + * FAILURE (a crash-loop on the new image must not be reported as success). + * - 'old-still-there': the id we stopped is still the one under this name -> keep polling. + * - 'gone': nothing under this name yet -> keep polling. + */ +export function classifyRespawn( + found: FoundContainer | null, + oldId: string +): 'respawned-running' | 'respawned-not-running' | 'old-still-there' | 'gone' { + if (!found) return 'gone'; + if (found.Id === oldId) return 'old-still-there'; + return found.State === 'running' ? 'respawned-running' : 'respawned-not-running'; +} + +/** Exact-name match filter for a container-list `name` filter (Podman/Docker treat it as regex-contains). */ +export function isExactNameMatch(names: string[] | undefined, name: string): boolean { + return (names || []).some((n) => n.replace(/^\//, '') === name); +} + +export type RespawnOutcome = + | { done: true; ok: true; id: string } // a new container is running -> success + | { done: false } // keep polling + | { done: true; ok: false }; // deadline reached without a running new container + +/** + * Decide, from one poll observation, whether to finish or keep polling. Pure so the + * timeout/success/failure branches are unit-testable without a live socket. + * + * A running new-id container is an immediate success. Otherwise we keep polling until the + * deadline; once reached, we only succeed if the CURRENT observation is a running new-id + * container - a container that merely appeared but never reached running (crash-loop on a + * broken new image) is a FAILURE, never a false success. + */ +export function decideRespawnOutcome( + found: FoundContainer | null, + oldId: string, + deadlineReached: boolean +): RespawnOutcome { + const state = classifyRespawn(found, oldId); + if (state === 'respawned-running') return { done: true, ok: true, id: found!.Id }; + if (!deadlineReached) return { done: false }; + return { done: true, ok: false }; +} diff --git a/tests/systemd-recreate-core.test.ts b/tests/systemd-recreate-core.test.ts new file mode 100644 index 000000000..0920f7ba5 --- /dev/null +++ b/tests/systemd-recreate-core.test.ts @@ -0,0 +1,94 @@ +// @ts-expect-error -- bun:test is a runtime built-in with no types installed +import { describe, test, expect } from 'bun:test'; +import { + classifyRespawn, + isExactNameMatch, + decideRespawnOutcome +} from '../src/lib/server/systemd-recreate-core'; + +describe('classifyRespawn (Quadlet/systemd recreate detection)', () => { + const OLD = 'old111'; + + test('a new id that is running is a successful respawn', () => { + expect(classifyRespawn({ Id: 'new222', State: 'running' }, OLD)).toBe('respawned-running'); + }); + + test('a new id that is not running is respawned-not-running (crash-loop / settling)', () => { + expect(classifyRespawn({ Id: 'new222', State: 'created' }, OLD)).toBe('respawned-not-running'); + expect(classifyRespawn({ Id: 'new222', State: 'restarting' }, OLD)).toBe('respawned-not-running'); + expect(classifyRespawn({ Id: 'new222', State: 'exited' }, OLD)).toBe('respawned-not-running'); + }); + + test('the same id as the stopped container means keep waiting', () => { + expect(classifyRespawn({ Id: OLD, State: 'running' }, OLD)).toBe('old-still-there'); + expect(classifyRespawn({ Id: OLD, State: 'exited' }, OLD)).toBe('old-still-there'); + }); + + test('nothing found means keep waiting (systemd removed it, not yet respawned)', () => { + expect(classifyRespawn(null, OLD)).toBe('gone'); + }); +}); + +describe('decideRespawnOutcome (poll loop: continue / succeed / fail)', () => { + const OLD = 'old111'; + + test('a running new-id container succeeds immediately, even before the deadline', () => { + expect(decideRespawnOutcome({ Id: 'new222', State: 'running' }, OLD, false)).toEqual({ + done: true, + ok: true, + id: 'new222' + }); + }); + + test('before the deadline, a non-running / absent / old container keeps polling', () => { + expect(decideRespawnOutcome({ Id: 'new222', State: 'created' }, OLD, false)).toEqual({ done: false }); + expect(decideRespawnOutcome({ Id: OLD, State: 'running' }, OLD, false)).toEqual({ done: false }); + expect(decideRespawnOutcome(null, OLD, false)).toEqual({ done: false }); + }); + + test('at the deadline, a crash-looping new container is a FAILURE, not a false success', () => { + // a broken new image (crash-loop) must never be reported as a successful update + expect(decideRespawnOutcome({ Id: 'new222', State: 'restarting' }, OLD, true)).toEqual({ + done: true, + ok: false + }); + expect(decideRespawnOutcome({ Id: 'new222', State: 'exited' }, OLD, true)).toEqual({ + done: true, + ok: false + }); + }); + + test('at the deadline, nothing respawned is a failure', () => { + expect(decideRespawnOutcome(null, OLD, true)).toEqual({ done: true, ok: false }); + }); + + test('at the deadline, a genuinely running new container still succeeds', () => { + expect(decideRespawnOutcome({ Id: 'new222', State: 'running' }, OLD, true)).toEqual({ + done: true, + ok: true, + id: 'new222' + }); + }); +}); + +describe('isExactNameMatch', () => { + test('matches the exact name, tolerating a leading slash', () => { + expect(isExactNameMatch(['/immich-server'], 'immich-server')).toBe(true); + expect(isExactNameMatch(['immich-server'], 'immich-server')).toBe(true); + }); + + test('matches when the exact name is not the first of several names', () => { + expect(isExactNameMatch(['/other', '/immich-server'], 'immich-server')).toBe(true); + }); + + test('does not match a name that merely contains the target (regex-contains guard)', () => { + expect(isExactNameMatch(['/immich-server-old'], 'immich-server')).toBe(false); + expect(isExactNameMatch(['/my-immich-server'], 'immich-server')).toBe(false); + expect(isExactNameMatch(['/immich-server-old', '/immich-server-old2'], 'immich-server')).toBe(false); + }); + + test('handles missing/empty names', () => { + expect(isExactNameMatch(undefined, 'x')).toBe(false); + expect(isExactNameMatch([], 'x')).toBe(false); + }); +}); From aa242bcc6c834e28bada63f0df88c36af7334588 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 10/32] search and filter containers by label --- src/lib/utils/container-search-core.ts | 67 ++++++++++++++++++++++++ tests/container-search-core.test.ts | 71 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 src/lib/utils/container-search-core.ts create mode 100644 tests/container-search-core.test.ts diff --git a/src/lib/utils/container-search-core.ts b/src/lib/utils/container-search-core.ts new file mode 100644 index 000000000..b5daab333 --- /dev/null +++ b/src/lib/utils/container-search-core.ts @@ -0,0 +1,67 @@ +/** + * Pure container search matching, so the containers-page filter is unit-testable. + * + * A plain query matches the name, image, any label key OR value, and (kept for + * back-compat) the compose project. A `label:` prefix does a Docker-style label + * filter: `label:heal` matches a container that HAS a `heal` label (any value); + * `label:heal=true` matches only when the value is `true` too. Mirrors + * `docker ps --filter "label=heal"` / `label=heal=true` (#1372). + */ + +export interface SearchableContainer { + name: string; + image: string; + labels?: Record; +} + +/** A `label:key` / `label:key=value` token, parsed once per query. */ +function parseLabelToken(query: string): { key: string; value: string | null } | null { + const m = /^label:(.+)$/i.exec(query.trim()); + if (!m) return null; + const rest = m[1]; + const eq = rest.indexOf('='); + if (eq === -1) return { key: rest.trim().toLowerCase(), value: null }; + return { + key: rest.slice(0, eq).trim().toLowerCase(), + value: rest.slice(eq + 1).trim().toLowerCase(), + }; +} + +/** True if the container has a label whose key matches `key` (and value matches + * `value` when given). Keys and values are compared case-insensitively. */ +function matchesLabelFilter( + labels: Record | undefined, + key: string, + value: string | null, +): boolean { + if (!labels) return false; + for (const [k, v] of Object.entries(labels)) { + if (k.toLowerCase() !== key) continue; + if (value === null) return true; + if ((v ?? '').toLowerCase() === value) return true; + } + return false; +} + +/** + * Does a container match the search query? Empty query matches everything. + * A `label:` query is a targeted label filter; any other query is a free-text + * substring match over name, image, every label key/value, and the compose project. + */ +export function containerMatchesSearch(c: SearchableContainer, rawQuery: string): boolean { + const q = rawQuery.trim(); + if (!q) return true; + + const labelToken = parseLabelToken(q); + if (labelToken) return matchesLabelFilter(c.labels, labelToken.key, labelToken.value); + + const query = q.toLowerCase(); + if (c.name.toLowerCase().includes(query)) return true; + if (c.image.toLowerCase().includes(query)) return true; + if (c.labels) { + for (const [k, v] of Object.entries(c.labels)) { + if (k.toLowerCase().includes(query) || (v ?? '').toLowerCase().includes(query)) return true; + } + } + return false; +} diff --git a/tests/container-search-core.test.ts b/tests/container-search-core.test.ts new file mode 100644 index 000000000..01fc71676 --- /dev/null +++ b/tests/container-search-core.test.ts @@ -0,0 +1,71 @@ +import { describe, test, expect } from 'bun:test'; +import { containerMatchesSearch } from '../src/lib/utils/container-search-core'; + +const c = { + name: 'my-nginx', + image: 'nginx:1.27', + labels: { + 'com.docker.compose.project': 'web', + 'heal': 'true', + 'traefik.enable': 'true', + 'maintainer': 'Alice', + }, +}; + +describe('containerMatchesSearch - free text', () => { + test('empty query matches everything', () => { + expect(containerMatchesSearch(c, '')).toBe(true); + expect(containerMatchesSearch(c, ' ')).toBe(true); + }); + test('matches name and image (existing behavior preserved)', () => { + expect(containerMatchesSearch(c, 'nginx')).toBe(true); + expect(containerMatchesSearch(c, '1.27')).toBe(true); + }); + test('matches the compose project (existing behavior preserved)', () => { + expect(containerMatchesSearch(c, 'web')).toBe(true); + }); + test('NOW matches a label KEY as free text (the #1372 ask)', () => { + expect(containerMatchesSearch(c, 'heal')).toBe(true); + expect(containerMatchesSearch(c, 'traefik')).toBe(true); + }); + test('matches a label VALUE as free text', () => { + expect(containerMatchesSearch(c, 'alice')).toBe(true); // maintainer=Alice, case-insensitive + }); + test('does not match an unrelated query', () => { + expect(containerMatchesSearch(c, 'postgres')).toBe(false); + }); +}); + +describe('containerMatchesSearch - label: filter (docker ps --filter style)', () => { + test('label:key matches a container that HAS the label (any value)', () => { + expect(containerMatchesSearch(c, 'label:heal')).toBe(true); + expect(containerMatchesSearch(c, 'label:maintainer')).toBe(true); + }); + test('label:key is case-insensitive on the key', () => { + expect(containerMatchesSearch(c, 'label:HEAL')).toBe(true); + }); + test('label:key does NOT match when the label is absent', () => { + expect(containerMatchesSearch(c, 'label:nope')).toBe(false); + }); + test('label:key=value matches only when the value matches too', () => { + expect(containerMatchesSearch(c, 'label:heal=true')).toBe(true); + expect(containerMatchesSearch(c, 'label:heal=false')).toBe(false); + }); + test('label:key=value is case-insensitive on the value', () => { + expect(containerMatchesSearch(c, 'label:maintainer=alice')).toBe(true); + }); + test('label: with a key that only partially matches does NOT match (exact key)', () => { + // free-text "heal" matches; but label:hea should NOT (exact key semantics) + expect(containerMatchesSearch(c, 'label:hea')).toBe(false); + }); +}); + +describe('containerMatchesSearch - no labels', () => { + const bare = { name: 'x', image: 'busybox', labels: undefined }; + test('free text still works on name/image', () => { + expect(containerMatchesSearch(bare, 'busybox')).toBe(true); + }); + test('label: filter returns false when there are no labels', () => { + expect(containerMatchesSearch(bare, 'label:heal')).toBe(false); + }); +}); From b3e2b267e7a6cbfb197fa0506367ff229923152d Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 11/32] make the command palette fast and search stacks and containers --- src/lib/utils/palette-filter.ts | 94 +++++++++++++++++++++++++ src/lib/utils/palette-virtual.ts | 46 +++++++++++++ tests/palette-filter.test.ts | 114 +++++++++++++++++++++++++++++++ tests/palette-virtual.test.ts | 57 ++++++++++++++++ 4 files changed, 311 insertions(+) create mode 100644 src/lib/utils/palette-filter.ts create mode 100644 src/lib/utils/palette-virtual.ts create mode 100644 tests/palette-filter.test.ts create mode 100644 tests/palette-virtual.test.ts diff --git a/src/lib/utils/palette-filter.ts b/src/lib/utils/palette-filter.ts new file mode 100644 index 000000000..245e4a99d --- /dev/null +++ b/src/lib/utils/palette-filter.ts @@ -0,0 +1,94 @@ +// Pure filter + rank for the command palette. Import-light (no Svelte) so it is +// unit-testable. The palette holds hundreds of items (nav, themes, fonts, editor themes, +// environments, containers, stacks); this ranks matches cheaply (substring, no fuzzy lib) +// and keeps results grouped so the list stays readable. + +export interface PaletteItem { + /** Stable key (also the aria row id). */ + id: string; + /** Group heading, e.g. 'Navigation' | 'Light theme' | 'Containers' | 'Stacks'. */ + group: string; + /** Display text, matched with highest priority. */ + label: string; + /** Pre-lowercased extra haystack (keywords + image + envName + aliases). */ + keywords: string; + /** Drives a current-selection checkmark (theme/font/env). */ + active?: boolean; +} + +/** Per-group cap applied when the query is empty, so the default view stays small. */ +export type DefaultCaps = Record; + +function escapeRegExp(s: string): string { + return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + +/** The word-boundary matcher for a query: `q` starts a word (^, space, -, _, /). */ +export function wordBoundaryRegex(q: string): RegExp { + return new RegExp(`(^|[\\s\\-_/])${escapeRegExp(q)}`); +} + +/** + * Match/rank tier for one item against a query. Lower number = better match; -1 = no + * match. Ordering: label-prefix < label-word-boundary < label-substring < keyword-substring. + * `wb` is the pre-compiled word-boundary regex for `q` (compiled ONCE per query by the + * caller, not per item - a fresh RegExp per item would be a perf killer at hundreds of + * items). When omitted (test convenience) it is compiled here. + */ +export function rankItem(item: PaletteItem, q: string, wb: RegExp = wordBoundaryRegex(q)): number { + if (!q) return 0; + const label = item.label.toLowerCase(); + if (label.startsWith(q)) return 0; + if (wb.test(label)) return 1; + if (label.includes(q)) return 2; + if (item.keywords.includes(q)) return 3; + return -1; +} + +/** + * Filter + rank the palette. Results stay grouped (a group's items never interleave with + * another group's), ordered by (group order, match tier, original index) so the sort is + * stable within a tier. An empty/whitespace query returns a CAPPED default set per group + * (via `defaultCaps`, default cap = Infinity for groups not listed) so the initial view + * doesn't mount every item. + */ +export function filterPalette( + items: PaletteItem[], + rawQuery: string, + opts: { defaultCaps?: DefaultCaps } = {} +): PaletteItem[] { + const q = rawQuery.trim().toLowerCase(); + + // group order = first appearance in the source list, so groups render in a stable order. + const groupOrder = new Map(); + for (const it of items) if (!groupOrder.has(it.group)) groupOrder.set(it.group, groupOrder.size); + + if (!q) { + const caps = opts.defaultCaps ?? {}; + const perGroup = new Map(); + const out: Array<{ item: PaletteItem; tier: number; i: number; g: number }> = []; + items.forEach((item, i) => { + const used = perGroup.get(item.group) ?? 0; + const cap = caps[item.group] ?? Infinity; + if (used >= cap) return; + perGroup.set(item.group, used + 1); + out.push({ item, tier: 0, i, g: groupOrder.get(item.group)! }); + }); + return sortGrouped(out); + } + + const wb = wordBoundaryRegex(q); // compile ONCE per query, not per item + const scored: Array<{ item: PaletteItem; tier: number; i: number; g: number }> = []; + items.forEach((item, i) => { + const tier = rankItem(item, q, wb); + if (tier >= 0) scored.push({ item, tier, i, g: groupOrder.get(item.group)! }); + }); + return sortGrouped(scored); +} + +function sortGrouped( + scored: Array<{ item: PaletteItem; tier: number; i: number; g: number }> +): PaletteItem[] { + scored.sort((a, b) => a.g - b.g || a.tier - b.tier || a.i - b.i); + return scored.map((s) => s.item); +} diff --git a/src/lib/utils/palette-virtual.ts b/src/lib/utils/palette-virtual.ts new file mode 100644 index 000000000..b9ee17a2d --- /dev/null +++ b/src/lib/utils/palette-virtual.ts @@ -0,0 +1,46 @@ +// Pure fixed-height virtualization math for the command palette list. Rows have one of two +// heights (item vs group header); a prefix-sum offsets array + binary search gives the +// visible window in O(log n). Import-light so it's unit-testable without the DOM. + +/** Cumulative top offset of each row plus a final total. `heights[i]` is row i's height. */ +export function buildOffsets(heights: number[]): number[] { + const o = new Array(heights.length + 1); + o[0] = 0; + for (let i = 0; i < heights.length; i++) o[i + 1] = o[i] + heights[i]; + return o; +} + +/** + * Index of the last row whose top offset is <= y. Binary search into `offsets` (length + * rows+1). Clamps: y below 0 -> 0; y past the end -> the last row. Returns 0 for an empty + * list. + */ +export function rowAtOffset(offsets: number[], y: number): number { + const rows = offsets.length - 1; + if (rows <= 0) return 0; + let lo = 0, hi = rows - 1, ans = 0; + while (lo <= hi) { + const mid = (lo + hi) >> 1; + if (offsets[mid] <= y) { + ans = mid; + lo = mid + 1; + } else { + hi = mid - 1; + } + } + return ans; +} + +/** The [start, end) row window to render for a viewport, padded by `buffer` rows. */ +export function visibleRange( + offsets: number[], + scrollTop: number, + viewportH: number, + buffer: number +): { start: number; end: number } { + const rows = offsets.length - 1; + if (rows <= 0) return { start: 0, end: 0 }; + const start = Math.max(0, rowAtOffset(offsets, scrollTop) - buffer); + const end = Math.min(rows, rowAtOffset(offsets, scrollTop + viewportH) + buffer + 1); + return { start, end }; +} diff --git a/tests/palette-filter.test.ts b/tests/palette-filter.test.ts new file mode 100644 index 000000000..5263094fa --- /dev/null +++ b/tests/palette-filter.test.ts @@ -0,0 +1,114 @@ +import { describe, test, expect } from 'bun:test'; +import { filterPalette, rankItem, type PaletteItem } from '../src/lib/utils/palette-filter'; + +const item = (over: Partial & { id: string; group: string; label: string }): PaletteItem => ({ + keywords: '', + ...over +}); + +describe('rankItem (match tiers)', () => { + const it = item({ id: '1', group: 'g', label: 'Editor theme', keywords: 'dark colors' }); + + test('empty query matches everything at tier 0', () => { + expect(rankItem(it, '')).toBe(0); + }); + test('label prefix is tier 0', () => { + expect(rankItem(it, 'editor')).toBe(0); + }); + test('word-boundary in label is tier 1', () => { + expect(rankItem(it, 'theme')).toBe(1); // starts the second word + }); + test('mid-word substring in label is tier 2', () => { + expect(rankItem(it, 'dito')).toBe(2); + }); + test('keyword-only match is tier 3', () => { + expect(rankItem(it, 'colors')).toBe(3); + }); + test('no match is -1', () => { + expect(rankItem(it, 'zzz')).toBe(-1); + }); + test('case-insensitive (query is pre-lowercased by filterPalette; rankItem assumes lowercase q)', () => { + expect(rankItem(item({ id: '2', group: 'g', label: 'Dracula', keywords: '' }), 'drac')).toBe(0); + }); + + test('regex special chars in the query are matched literally (escapeRegExp), never as wildcards', () => { + // a query with regex metachars must not throw and must not act as a pattern + const gpp = item({ id: 'x', group: 'g', label: 'g++ tool', keywords: '' }); + expect(rankItem(gpp, 'g++')).toBe(0); // prefix, literal '++' + // a dot must be literal: '1.6' must NOT match 'host 156' (dot != any-char) + const host = item({ id: 'y', group: 'g', label: 'host 156', keywords: '' }); + expect(rankItem(host, '1.6')).toBe(-1); + // but a literal dotted string matches + expect(rankItem(item({ id: 'z', group: 'g', label: 'v1.6.0', keywords: '' }), '1.6')).toBe(2); + }); +}); + +describe('filterPalette', () => { + const items: PaletteItem[] = [ + item({ id: 'nav-dash', group: 'Navigation', label: 'Dashboard', keywords: 'home' }), + item({ id: 'nav-cont', group: 'Navigation', label: 'Containers', keywords: 'docker' }), + item({ id: 'th-drac', group: 'Theme', label: 'Dracula', keywords: '' }), + item({ id: 'th-mono', group: 'Theme', label: 'Monokai', keywords: '' }), + item({ id: 'th-nord', group: 'Theme', label: 'Nord', keywords: '' }), + item({ id: 'ct-nginx', group: 'Containers', label: 'nginx-proxy', keywords: 'nginx:latest prod' }), + item({ id: 'ct-db', group: 'Containers', label: 'postgres', keywords: 'postgres:16 prod' }) + ]; + + test('whitespace-only query behaves as empty', () => { + expect(filterPalette(items, ' ').length).toBe(items.length); + }); + + test('empty query applies per-group caps', () => { + const out = filterPalette(items, '', { defaultCaps: { Theme: 2 } }); + const themes = out.filter((i) => i.group === 'Theme'); + expect(themes.length).toBe(2); // capped from 3 + expect(out.filter((i) => i.group === 'Navigation').length).toBe(2); // uncapped + // cap keeps source order (first two themes) + expect(themes.map((t) => t.id)).toEqual(['th-drac', 'th-mono']); + }); + + test('results stay grouped in source group order, not globally reshuffled', () => { + const out = filterPalette(items, 'o'); // matches across groups + const groups = out.map((i) => i.group); + // once a group ends it does not reappear + const seen = new Set(); + let prev = ''; + for (const g of groups) { + if (g !== prev && seen.has(g)) throw new Error(`group ${g} interleaved`); + seen.add(g); + prev = g; + } + expect(groups[0]).toBe('Navigation'); // Navigation appears before Theme/Containers + }); + + test('prefix ranks above word-boundary above substring above keyword-only', () => { + const ranked: PaletteItem[] = [ + item({ id: 'kw', group: 'g', label: 'zzz', keywords: 'alpha' }), // keyword-only + item({ id: 'sub', group: 'g', label: 'xalphax', keywords: '' }), // substring + item({ id: 'wb', group: 'g', label: 'x alpha', keywords: '' }), // word-boundary + item({ id: 'pre', group: 'g', label: 'alpha thing', keywords: '' }) // prefix + ]; + const out = filterPalette(ranked, 'alpha'); + expect(out.map((i) => i.id)).toEqual(['pre', 'wb', 'sub', 'kw']); + }); + + test('keyword/image haystack finds a container by its image tag', () => { + const out = filterPalette(items, 'nginx:latest'); + expect(out.map((i) => i.id)).toContain('ct-nginx'); + }); + + test('case-insensitive matching', () => { + expect(filterPalette(items, 'DRACULA').map((i) => i.id)).toContain('th-drac'); + expect(filterPalette(items, 'NGINX').map((i) => i.id)).toContain('ct-nginx'); + }); + + test('no matches returns empty', () => { + expect(filterPalette(items, 'zzzznope')).toEqual([]); + }); + + test('stable order within a tier (source order preserved)', () => { + // all three themes are keyword-less; querying a common substring keeps source order + const out = filterPalette(items, 'o').filter((i) => i.group === 'Theme'); + expect(out.map((i) => i.id)).toEqual(['th-mono', 'th-nord']); // Monokai, Nord (Dracula has no 'o') + }); +}); diff --git a/tests/palette-virtual.test.ts b/tests/palette-virtual.test.ts new file mode 100644 index 000000000..b895abf4c --- /dev/null +++ b/tests/palette-virtual.test.ts @@ -0,0 +1,57 @@ +import { describe, test, expect } from 'bun:test'; +import { buildOffsets, rowAtOffset, visibleRange } from '../src/lib/utils/palette-virtual'; + +describe('buildOffsets', () => { + test('prefix-sum with a final total', () => { + expect(buildOffsets([28, 44, 44, 28, 44])).toEqual([0, 28, 72, 116, 144, 188]); + }); + test('empty -> [0]', () => { + expect(buildOffsets([])).toEqual([0]); + }); +}); + +describe('rowAtOffset', () => { + const offsets = buildOffsets([28, 44, 44, 28, 44]); // 5 rows -> [0,28,72,116,144,188] + + test('exact row tops map to that row', () => { + expect(rowAtOffset(offsets, 0)).toBe(0); + expect(rowAtOffset(offsets, 28)).toBe(1); + expect(rowAtOffset(offsets, 72)).toBe(2); + expect(rowAtOffset(offsets, 144)).toBe(4); + }); + test('a y inside a row maps to that row', () => { + expect(rowAtOffset(offsets, 50)).toBe(1); // within row 1 [28,72) + expect(rowAtOffset(offsets, 143)).toBe(3); // within row 3 [116,144) + }); + test('y below 0 clamps to first row', () => { + expect(rowAtOffset(offsets, -100)).toBe(0); + }); + test('y past the end clamps to the last row', () => { + expect(rowAtOffset(offsets, 9999)).toBe(4); + }); + test('empty list -> 0', () => { + expect(rowAtOffset([0], 42)).toBe(0); + }); +}); + +describe('visibleRange', () => { + const offsets = buildOffsets(new Array(100).fill(44)); // 100 uniform rows + + test('window covers the viewport plus buffer on both sides', () => { + // scrollTop 440 (row 10), viewport 220 (5 rows), buffer 2 + const { start, end } = visibleRange(offsets, 440, 220, 2); + expect(start).toBe(8); // row 10 - 2 + // bottom offset 660 -> row 15; +2 buffer +1 exclusive end + expect(end).toBe(18); + expect(end - start).toBeLessThanOrEqual(220 / 44 + 2 * 2 + 2); // bounded, not O(total) + }); + test('at the top, start clamps to 0', () => { + expect(visibleRange(offsets, 0, 220, 6).start).toBe(0); + }); + test('at the bottom, end clamps to row count', () => { + expect(visibleRange(offsets, 4400, 220, 6).end).toBe(100); + }); + test('empty list -> {0,0}', () => { + expect(visibleRange([0], 0, 220, 6)).toEqual({ start: 0, end: 0 }); + }); +}); From 246e637087f1e07f5203ceab72619039a1d18a13 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 12/32] correct the environment query param docs on container endpoints --- src/routes/api/containers/[id]/+server.ts | 4 ++-- src/routes/api/containers/[id]/compose/+server.ts | 2 +- src/routes/api/containers/[id]/exec/+server.ts | 2 +- src/routes/api/containers/[id]/files/+server.ts | 2 +- src/routes/api/containers/[id]/files/chmod/+server.ts | 2 +- src/routes/api/containers/[id]/files/content/+server.ts | 4 ++-- src/routes/api/containers/[id]/files/delete/+server.ts | 2 +- src/routes/api/containers/[id]/files/download/+server.ts | 2 +- src/routes/api/containers/[id]/files/rename/+server.ts | 2 +- src/routes/api/containers/[id]/inspect/+server.ts | 2 +- src/routes/api/containers/[id]/logs/+server.ts | 2 +- src/routes/api/containers/[id]/logs/stream/+server.ts | 2 +- src/routes/api/containers/[id]/pause/+server.ts | 2 +- src/routes/api/containers/[id]/rename/+server.ts | 2 +- src/routes/api/containers/[id]/restart/+server.ts | 2 +- src/routes/api/containers/[id]/shells/+server.ts | 2 +- src/routes/api/containers/[id]/start/+server.ts | 2 +- src/routes/api/containers/[id]/stop/+server.ts | 2 +- src/routes/api/containers/[id]/top/+server.ts | 2 +- src/routes/api/containers/[id]/unpause/+server.ts | 2 +- src/routes/api/containers/[id]/update/+server.ts | 2 +- src/routes/api/containers/[id]/version-notes/+server.ts | 2 +- src/routes/api/containers/batch-update-stream/+server.ts | 2 +- src/routes/api/containers/batch-update/+server.ts | 2 +- src/routes/api/containers/check-updates/+server.ts | 6 +++--- src/routes/api/containers/sizes/+server.ts | 2 +- 26 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/routes/api/containers/[id]/+server.ts b/src/routes/api/containers/[id]/+server.ts index d981c33cf..19c5bc943 100644 --- a/src/routes/api/containers/[id]/+server.ts +++ b/src/routes/api/containers/[id]/+server.ts @@ -18,7 +18,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Return the full Docker inspect payload for a single container * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: The raw Docker inspect object for the container * resp-403: Permission denied, or (enterprise) no access to the requested environment * resp-404: Container not found @@ -82,7 +82,7 @@ export const GET: RequestHandler = async ({ params, url, cookies }) => { * @openapi * summary: Remove a container and clean up its auto-update schedule and pending-update record * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: force:boolean Force removal of a running container (Docker force flag) * resp-200: {success:boolean!} * resp-200-example: {"success":true} diff --git a/src/routes/api/containers/[id]/compose/+server.ts b/src/routes/api/containers/[id]/compose/+server.ts index be753860e..00bcac003 100644 --- a/src/routes/api/containers/[id]/compose/+server.ts +++ b/src/routes/api/containers/[id]/compose/+server.ts @@ -13,7 +13,7 @@ import { inspectToCompose, type DockerInspect } from '$lib/utils/inspect-to-comp * @openapi * summary: Generate a docker-compose service definition from a running container's inspect (requires the 'view' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {compose:string, composeFullEnv:string, serviceName:string, stackProject:string} * resp-200-desc: compose keeps only user-set env; composeFullEnv keeps every env var (incl. image-inherited); stackProject is the compose project the container already belongs to, or null * resp-403: Permission denied diff --git a/src/routes/api/containers/[id]/exec/+server.ts b/src/routes/api/containers/[id]/exec/+server.ts index 555fb3212..192342c31 100644 --- a/src/routes/api/containers/[id]/exec/+server.ts +++ b/src/routes/api/containers/[id]/exec/+server.ts @@ -17,7 +17,7 @@ import { validateDockerIdParam } from '$lib/server/docker-validation'; * @openapi * summary: Create a Docker exec instance in a container and return its ID plus the Docker connection info for a terminal WebSocket * path: id:string! Container ID or name (from GET /api/containers) - * query: envId:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: envId:integer! The target environment ID the container lives in (from GET /api/environments) * body: {shell:string, user:string} * body-example: {"shell":"/bin/sh","user":"root"} * resp-200: {execId:string!, connectionInfo:{type:string!, host:string, port:integer}} diff --git a/src/routes/api/containers/[id]/files/+server.ts b/src/routes/api/containers/[id]/files/+server.ts index 3393bdc77..953a37b10 100644 --- a/src/routes/api/containers/[id]/files/+server.ts +++ b/src/routes/api/containers/[id]/files/+server.ts @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: List the contents of a directory inside a container's filesystem * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: path:string Absolute directory path inside the container (default "/") * query: simpleLs:boolean Use a lightweight `ls` listing instead of a full stat of each entry * resp-200: Directory listing (entries with name, type, size and permission metadata) diff --git a/src/routes/api/containers/[id]/files/chmod/+server.ts b/src/routes/api/containers/[id]/files/chmod/+server.ts index 15140d3b1..a66702c84 100644 --- a/src/routes/api/containers/[id]/files/chmod/+server.ts +++ b/src/routes/api/containers/[id]/files/chmod/+server.ts @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Change the mode (permissions) of a file or directory inside a container (requires the 'exec' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {path:string!, mode:string!, recursive:boolean} * body-example: {"path":"/app/entrypoint.sh","mode":"755","recursive":false} * resp-200: {success:boolean!, path:string!, mode:string!, recursive:boolean!} diff --git a/src/routes/api/containers/[id]/files/content/+server.ts b/src/routes/api/containers/[id]/files/content/+server.ts index 798a9131f..44f84bb15 100644 --- a/src/routes/api/containers/[id]/files/content/+server.ts +++ b/src/routes/api/containers/[id]/files/content/+server.ts @@ -13,7 +13,7 @@ const MAX_FILE_SIZE = 1024 * 1024; * @openapi * summary: Read the content of a single file inside a container (max 1 MB) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: path:string! Absolute file path inside the container * resp-200: {content:string!, path:string!} * resp-400: Path is missing, the target is a directory, or the container is not running @@ -86,7 +86,7 @@ export const GET: RequestHandler = async ({ params, url, cookies }) => { * @openapi * summary: Overwrite the content of a file inside a container (max 1 MB, requires the 'exec' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: path:string! Absolute file path inside the container * body: {content:string!} * body-example: {"content":"server {\n listen 80;\n}\n"} diff --git a/src/routes/api/containers/[id]/files/delete/+server.ts b/src/routes/api/containers/[id]/files/delete/+server.ts index 8899e2004..ef2d1cb1f 100644 --- a/src/routes/api/containers/[id]/files/delete/+server.ts +++ b/src/routes/api/containers/[id]/files/delete/+server.ts @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Delete a file or directory inside a container (requires the 'exec' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: path:string! Absolute path inside the container to delete * resp-200: {success:boolean!, path:string!} * resp-200-example: {"success":true,"path":"/app/tmp/old.log"} diff --git a/src/routes/api/containers/[id]/files/download/+server.ts b/src/routes/api/containers/[id]/files/download/+server.ts index 4a38b2c87..3e3bec945 100644 --- a/src/routes/api/containers/[id]/files/download/+server.ts +++ b/src/routes/api/containers/[id]/files/download/+server.ts @@ -12,7 +12,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Download a file or directory from a container as a tar (optionally gzip-compressed) archive attachment * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: path:string! Absolute path inside the container to archive and download * query: format:string Archive format, "tar" (default) or "tar.gz" * resp-200: Archive stream (application/x-tar or application/gzip) as a file attachment diff --git a/src/routes/api/containers/[id]/files/rename/+server.ts b/src/routes/api/containers/[id]/files/rename/+server.ts index bda7e7e96..a1c1cc248 100644 --- a/src/routes/api/containers/[id]/files/rename/+server.ts +++ b/src/routes/api/containers/[id]/files/rename/+server.ts @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Rename or move a file or directory inside a container (requires the 'exec' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {oldPath:string!, newPath:string!} * body-example: {"oldPath":"/app/config.yaml","newPath":"/app/config.old.yaml"} * resp-200: {success:boolean!, oldPath:string!, newPath:string!} diff --git a/src/routes/api/containers/[id]/inspect/+server.ts b/src/routes/api/containers/[id]/inspect/+server.ts index 3b6e5f27f..87ec4375a 100644 --- a/src/routes/api/containers/[id]/inspect/+server.ts +++ b/src/routes/api/containers/[id]/inspect/+server.ts @@ -16,7 +16,7 @@ import { * @openapi * summary: Return the full Docker inspect payload for a container (requires the 'inspect' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: The raw Docker inspect object for the container * resp-403: Permission denied * resp-500: Failed to inspect the container diff --git a/src/routes/api/containers/[id]/logs/+server.ts b/src/routes/api/containers/[id]/logs/+server.ts index 376d55a8c..5e036d306 100644 --- a/src/routes/api/containers/[id]/logs/+server.ts +++ b/src/routes/api/containers/[id]/logs/+server.ts @@ -10,7 +10,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Return the last N lines of a container's combined stdout/stderr logs as a single string * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: tail:integer Number of trailing log lines to return (default 100) * query: since:string Only return logs since this time (Unix timestamp or Docker duration, e.g. 10m) * query: until:string Only return logs before this time (Unix timestamp or Docker duration) diff --git a/src/routes/api/containers/[id]/logs/stream/+server.ts b/src/routes/api/containers/[id]/logs/stream/+server.ts index a67030563..6747728c1 100644 --- a/src/routes/api/containers/[id]/logs/stream/+server.ts +++ b/src/routes/api/containers/[id]/logs/stream/+server.ts @@ -261,7 +261,7 @@ async function handleEdgeLogsStream(containerId: string, tail: string, environme * summary: Stream a container's logs live as Server-Sent Events (connected/log/end/error events, with keepalive heartbeats) * description: Returns a `text/event-stream`. For Hawser Edge environments whose agent is not connected the stream body carries an error event. Docker stdout/stderr frames are demultiplexed server-side; TTY containers stream raw text. * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: tail:string Number of trailing log lines to prime the stream with (default "100") * query: since:string Only stream logs since this time (Unix timestamp or Docker duration, e.g. 10m) * query: until:string Only stream logs before this time (Unix timestamp or Docker duration) diff --git a/src/routes/api/containers/[id]/pause/+server.ts b/src/routes/api/containers/[id]/pause/+server.ts index b77f25e82..36a235911 100644 --- a/src/routes/api/containers/[id]/pause/+server.ts +++ b/src/routes/api/containers/[id]/pause/+server.ts @@ -11,7 +11,7 @@ import { validateDockerIdParam } from '$lib/server/docker-validation'; * @openapi * summary: Pause all processes in a running container (requires the container 'stop' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {success:boolean!} * resp-200-example: {"success":true} * resp-403: Permission denied diff --git a/src/routes/api/containers/[id]/rename/+server.ts b/src/routes/api/containers/[id]/rename/+server.ts index e974fd229..eed673c07 100644 --- a/src/routes/api/containers/[id]/rename/+server.ts +++ b/src/routes/api/containers/[id]/rename/+server.ts @@ -12,7 +12,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Rename a container and update any associated auto-update schedule (requires the 'create' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {name:string!} * body-example: {"name":"my-renamed-container"} * resp-200: {success:boolean!} diff --git a/src/routes/api/containers/[id]/restart/+server.ts b/src/routes/api/containers/[id]/restart/+server.ts index 0ec0d2a6d..21a91eda9 100644 --- a/src/routes/api/containers/[id]/restart/+server.ts +++ b/src/routes/api/containers/[id]/restart/+server.ts @@ -11,7 +11,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Restart a container * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {success:boolean!} * resp-200-example: {"success":true} * resp-403: Permission denied, or (enterprise) no access to the requested environment diff --git a/src/routes/api/containers/[id]/shells/+server.ts b/src/routes/api/containers/[id]/shells/+server.ts index fd13fe21b..edbdfc55b 100644 --- a/src/routes/api/containers/[id]/shells/+server.ts +++ b/src/routes/api/containers/[id]/shells/+server.ts @@ -19,7 +19,7 @@ const SHELLS_TO_CHECK = [ * summary: Probe a container for available shells (bash/sh/zsh/ash) and report the preferred default (requires the 'exec' permission) * description: On probe failure the endpoint still returns 200 with empty results rather than an error, so callers always get a usable shell list. * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {shells:array!, defaultShell:string, allShells:array<{path:string!, label:string!, available:boolean!}>!} * resp-200-example: {"shells":["/bin/sh"],"defaultShell":"/bin/sh","allShells":[{"path":"/bin/bash","label":"Bash","available":false},{"path":"/bin/sh","label":"Shell (sh)","available":true}]} * resp-403: Permission denied, or (enterprise) no access to the requested environment diff --git a/src/routes/api/containers/[id]/start/+server.ts b/src/routes/api/containers/[id]/start/+server.ts index 6bdf50a95..69a9bdbe3 100644 --- a/src/routes/api/containers/[id]/start/+server.ts +++ b/src/routes/api/containers/[id]/start/+server.ts @@ -11,7 +11,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Start a stopped container * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {success:boolean!} * resp-200-example: {"success":true} * resp-403: Permission denied, or (enterprise) no access to the requested environment diff --git a/src/routes/api/containers/[id]/stop/+server.ts b/src/routes/api/containers/[id]/stop/+server.ts index 97535b172..ffc635c6c 100644 --- a/src/routes/api/containers/[id]/stop/+server.ts +++ b/src/routes/api/containers/[id]/stop/+server.ts @@ -11,7 +11,7 @@ import type { RequestHandler } from './$types'; * @openapi * summary: Stop a running container * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {success:boolean!} * resp-200-example: {"success":true} * resp-403: Permission denied, or (enterprise) no access to the requested environment diff --git a/src/routes/api/containers/[id]/top/+server.ts b/src/routes/api/containers/[id]/top/+server.ts index 875e67880..abfdd8014 100644 --- a/src/routes/api/containers/[id]/top/+server.ts +++ b/src/routes/api/containers/[id]/top/+server.ts @@ -35,7 +35,7 @@ function parsePsOutput(output: string): { Titles: string[]; Processes: string[][ * summary: List the processes running inside a container (via `ps` in the container, falling back to the Docker top API) * description: Uses the container 'inspect' permission. The `source` field indicates whether the result came from an in-container `ps` (`"ps"`) or the Docker top API fallback (`"top"`). * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {Titles:array!, Processes:array>!, source:string!} * resp-403: Permission denied * resp-500: Failed to read the container process list diff --git a/src/routes/api/containers/[id]/unpause/+server.ts b/src/routes/api/containers/[id]/unpause/+server.ts index 76f834857..e3c89786a 100644 --- a/src/routes/api/containers/[id]/unpause/+server.ts +++ b/src/routes/api/containers/[id]/unpause/+server.ts @@ -11,7 +11,7 @@ import { validateDockerIdParam } from '$lib/server/docker-validation'; * @openapi * summary: Resume all processes in a paused container (requires the container 'start' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {success:boolean!} * resp-200-example: {"success":true} * resp-403: Permission denied diff --git a/src/routes/api/containers/[id]/update/+server.ts b/src/routes/api/containers/[id]/update/+server.ts index 3a3223888..5b94abea7 100644 --- a/src/routes/api/containers/[id]/update/+server.ts +++ b/src/routes/api/containers/[id]/update/+server.ts @@ -13,7 +13,7 @@ import type { RequestHandler } from './$types'; * summary: Recreate a container with updated create-options (optionally re-pulling the image first), preserving its configuration (requires the 'create' permission) * description: The body carries the container create-options (image, name, env, ports, volumes, …) alongside the two control flags below; `repullImage` pulls the image before recreation and `startAfterUpdate` starts the new container once created. * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {image:string, name:string, repullImage:boolean, startAfterUpdate:boolean} * body-example: {"image":"nginx:latest","name":"web","repullImage":true,"startAfterUpdate":true} * resp-200: {success:boolean!, id:string!} diff --git a/src/routes/api/containers/[id]/version-notes/+server.ts b/src/routes/api/containers/[id]/version-notes/+server.ts index 062801998..a1c1461bf 100644 --- a/src/routes/api/containers/[id]/version-notes/+server.ts +++ b/src/routes/api/containers/[id]/version-notes/+server.ts @@ -12,7 +12,7 @@ import { resolveAndFetchReleaseNotes } from '$lib/server/semver/release-notes'; * @openapi * summary: Resolve GitHub release notes for the versions a semver update-check surfaced (requires the 'view' permission) * path: id:string! Container ID or name (from GET /api/containers) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * query: versions:string! Comma-separated version tags to fetch notes for (target + skipped), e.g. "16.3-alpine,16.4-alpine" * resp-200: {changelogUrl:string, source:string, rateLimited:boolean, notes:array<{version:string!, name:string, githubTag:string, body:string, publishedAt:string, url:string!}>!} * resp-200-example: {"changelogUrl":"https://github.com/go-gitea/gitea/releases","source":"go-gitea/gitea","notes":[{"version":"1.22.0","name":"v1.22.0","githubTag":"v1.22.0","body":"## Changes...","publishedAt":"2024-05-01T00:00:00Z","url":"https://github.com/go-gitea/gitea/releases/tag/v1.22.0"}]} diff --git a/src/routes/api/containers/batch-update-stream/+server.ts b/src/routes/api/containers/batch-update-stream/+server.ts index 9f937dec0..5b6ebb407 100644 --- a/src/routes/api/containers/batch-update-stream/+server.ts +++ b/src/routes/api/containers/batch-update-stream/+server.ts @@ -77,7 +77,7 @@ export interface UpdateProgress { * @openapi * summary: Recreate a set of containers with live streaming progress (Server-Sent Events), optionally blocking on vulnerability criteria (requires the 'create' permission) * description: Returns a `text/event-stream` reporting per-container progress. `vulnerabilityCriteria` (default "never") can block an update when a container's image scan exceeds the configured severity threshold. containerIds from GET /api/containers. - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {containerIds:array!, vulnerabilityCriteria:string} * body-example: {"containerIds":["3f4a1c2b9d8e"],"vulnerabilityCriteria":"never"} * resp-200: Server-Sent Events stream (text/event-stream) of per-container update progress diff --git a/src/routes/api/containers/batch-update/+server.ts b/src/routes/api/containers/batch-update/+server.ts index 128b2258c..851649402 100644 --- a/src/routes/api/containers/batch-update/+server.ts +++ b/src/routes/api/containers/batch-update/+server.ts @@ -22,7 +22,7 @@ export interface BatchUpdateResult { * @openapi * summary: Recreate a set of containers with their latest images, preserving all settings (requires the 'create' permission) * description: Containers are processed sequentially; the response reports per-container success/failure plus a summary. Use the streaming variant for live progress. containerIds from GET /api/containers. - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * body: {containerIds:array!} * body-example: {"containerIds":["3f4a1c2b9d8e","a1b2c3d4e5f6"]} * resp-200: {success:boolean!, results:array<{containerId:string!, containerName:string!, success:boolean!, error:string}>!, summary:{total:integer!, success:integer!, failed:integer!}!} diff --git a/src/routes/api/containers/check-updates/+server.ts b/src/routes/api/containers/check-updates/+server.ts index 31208b177..7186a8f9f 100644 --- a/src/routes/api/containers/check-updates/+server.ts +++ b/src/routes/api/containers/check-updates/+server.ts @@ -32,7 +32,7 @@ export interface UpdateCheckResult { * @openapi * summary: Read the cached pending image-update records for an environment (no fresh check; requires the 'view' permission) * description: Returns the containers currently flagged as having a pending image update from the last check. Does not trigger a new check — use POST to run a fresh check. - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: {environmentId:integer!, pendingUpdates:array<{containerId:string!, containerName:string!, currentImage:string!, checkedAt:string}>!} * resp-400: Environment ID required * resp-403: Permission denied @@ -75,7 +75,7 @@ export const GET: RequestHandler = async ({ url, cookies }) => { * * @openapi * summary: Trigger a fresh image-update check across all (non-hidden, non-podman-infra) containers in an environment - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: text/event-stream job stream ("progress" events with {checked,total}, final "result" event with {total,updatesFound,results}) — or, with "Accept: application/json", the final result as plain JSON * resp-403: Permission denied */ @@ -162,7 +162,7 @@ export const POST: RequestHandler = async ({ url, cookies, request }) => { ? await checkNewerVersion(imageName, { ...semverOptions, versionPattern: getVersionPatternOverride(inspectData.Config?.Labels) - }, getTagArtifactKind).catch(() => null) + }, getTagArtifactKind, result.localDigests ?? []).catch(() => null) : null; return { diff --git a/src/routes/api/containers/sizes/+server.ts b/src/routes/api/containers/sizes/+server.ts index ca13480be..448c6deb1 100644 --- a/src/routes/api/containers/sizes/+server.ts +++ b/src/routes/api/containers/sizes/+server.ts @@ -8,7 +8,7 @@ import { authorize } from '$lib/server/authorize'; * * @openapi * summary: List all containers in an environment together with their writable-layer and root-filesystem sizes (requires the 'view' permission) - * query: env:integer The target environment ID (omit for the local/default Docker host) (from GET /api/environments) + * query: env:integer! The target environment ID the container lives in (from GET /api/environments) * resp-200: Array of containers with size metadata (SizeRw / SizeRootFs) * resp-403: Permission denied * resp-500: Failed to get container sizes (returns an empty object) From ac1aa1e6904cfb155557412455ed6fe7280284e0 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:47 +0200 Subject: [PATCH 13/32] add an optional entrypoint field to the container create and edit modals --- src/routes/containers/ContainerSettingsTab.svelte | 7 +++++++ src/routes/containers/CreateContainerModal.svelte | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/routes/containers/ContainerSettingsTab.svelte b/src/routes/containers/ContainerSettingsTab.svelte index 9ed105c9d..318d584e8 100644 --- a/src/routes/containers/ContainerSettingsTab.svelte +++ b/src/routes/containers/ContainerSettingsTab.svelte @@ -87,6 +87,7 @@ name: string; image: string; command: string; + entrypoint: string; restartPolicy: string; restartMaxRetries: number | ''; networkMode: string; @@ -173,6 +174,7 @@ name = $bindable(), image = $bindable(), command = $bindable(), + entrypoint = $bindable(''), restartPolicy = $bindable(), restartMaxRetries = $bindable(), networkMode = $bindable(), @@ -886,6 +888,11 @@
+
+ + +
+
diff --git a/src/routes/containers/CreateContainerModal.svelte b/src/routes/containers/CreateContainerModal.svelte index 329112fc1..d09538364 100644 --- a/src/routes/containers/CreateContainerModal.svelte +++ b/src/routes/containers/CreateContainerModal.svelte @@ -54,6 +54,7 @@ let name = $state(''); let image = $state(''); let command = $state(''); + let entrypoint = $state(''); let restartPolicy = $state('no'); let restartMaxRetries = $state(''); let networkMode = $state('bridge'); @@ -341,6 +342,7 @@ }); const cmd = command.trim() ? parseShellCommand(command.trim()) : undefined; + const entrypointArr = entrypoint.trim() ? parseShellCommand(entrypoint.trim()) : undefined; let healthcheck: any = undefined; if (healthcheckEnabled && healthcheckCommand.trim()) { @@ -405,6 +407,7 @@ env: env.length > 0 ? env : undefined, labels: Object.keys(labelsObj).length > 0 ? labelsObj : undefined, cmd, + entrypoint: entrypointArr, restartPolicy, restartMaxRetries: restartPolicy === 'on-failure' && restartMaxRetries !== '' ? Number(restartMaxRetries) : undefined, networkMode, @@ -493,6 +496,7 @@ name = ''; image = ''; command = ''; + entrypoint = ''; restartPolicy = 'no'; restartMaxRetries = ''; networkMode = 'bridge'; @@ -692,6 +696,7 @@ bind:name bind:image bind:command + bind:entrypoint bind:restartPolicy bind:restartMaxRetries bind:networkMode From 1ecc38f22d2a0717856ea11ba230b4cae392320f Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:48 +0200 Subject: [PATCH 14/32] release housekeeping --- package.json | 1 + src/lib/data/changelog.json | 27 ++++ src/lib/data/dependencies.json | 222 +++++++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+) diff --git a/package.json b/package.json index a779d30b6..eb5d62b13 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@lezer/highlight": "1.2.3", "@lucide/lab": "0.1.2", "@replit/codemirror-indentation-markers": "6.5.3", + "@uiw/codemirror-themes-all": "4.25.11", "ansi_up": "6.0.6", "argon2": "0.41.1", "better-sqlite3": "11.7.0", diff --git a/src/lib/data/changelog.json b/src/lib/data/changelog.json index 31359abe1..c54175b3a 100644 --- a/src/lib/data/changelog.json +++ b/src/lib/data/changelog.json @@ -1,4 +1,31 @@ [ + { + "version": "1.0.49", + "date": "", + "comingSoon": true, + "changes": [ + { "type": "feature", "text": "tag containers and stacks, then filter and group the grid by tag (#781, #870)" }, + { "type": "fix", "text": "don't report a newer version tag that resolves to the image you already run (#1572)" }, + { "type": "fix", "text": "fix vulnerability scans failing on the containerd image store (#1569, #1350)" }, + { "type": "fix", "text": "show CPU and memory for containers on Windows Docker hosts (#1574)" }, + { "type": "fix", "text": "don't send container died/killed notifications for a container being updated (#68)" }, + { "type": "fix", "text": "stop, start, restart and remove stacks that use secret providers, e.g. stop-during-backup (#1579)" }, + { "type": "fix", "text": "check for image updates on a plain-HTTP registry (#1580)" }, + { "type": "fix", "text": "send you to the login page when your session expires (#1577)" }, + { "type": "fix", "text": "skip hidden folders like .snapshots when scanning for stacks to adopt (#1251)" }, + { "type": "fix", "text": "updating a Podman container managed by a systemd Quadlet unit now works (#1529, #1559)" }, + { "type": "fix", "text": "option to skip bind mounts when scheduling backups for a whole environment (#1570)" }, + { "type": "fix", "text": "git stack env vars stay visible in the editor after saving (#1112)" }, + { "type": "feature", "text": "search and filter containers by label (#1372)" }, + { "type": "feature", "text": "editor themes: select from 40 themes with live preview (#1309)" }, + { "type": "feature", "text": "command palette searches stacks and containers across all hosts (#670)" }, + { "type": "feature", "text": "clear a search field with the X button in it (#1321)" }, + { "type": "fix", "text": "clearing a container's command now reverts it to the image default (#1489)" }, + { "type": "feature", "text": "one-shot container exec API returning stdout, stderr and exit code (#1380)" }, + { "type": "feature", "text": "set and change file ownership in the container file browser (#224)" } + ], + "imageTag": "fnsys/dockhand:v1.0.49" + }, { "version": "1.0.48", "date": "2026-09-14", diff --git a/src/lib/data/dependencies.json b/src/lib/data/dependencies.json index 1dbbce906..d0dd0296c 100644 --- a/src/lib/data/dependencies.json +++ b/src/lib/data/dependencies.json @@ -383,6 +383,228 @@ "license": "MIT", "repository": "https://github.com/typescript-eslint/typescript-eslint" }, + { + "name": "@uiw/codemirror-theme-abcdef", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-abyss", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-androidstudio", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-andromeda", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-atomone", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-aura", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-basic", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-bbedit", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-bespin", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-console", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-copilot", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-darcula", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-dracula", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-duotone", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-eclipse", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-github", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-gruvbox-dark", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-kimbie", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-material", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-monokai", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-monokai-dimmed", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-noctis-lilac", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-nord", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-okaidia", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-quietlight", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-red", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-solarized", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-sublime", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-tokyo-night", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-tokyo-night-day", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-tokyo-night-storm", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-tomorrow-night-blue", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-vscode", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-white", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-theme-xcode", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-themes", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, + { + "name": "@uiw/codemirror-themes-all", + "version": "4.25.11", + "license": "MIT", + "repository": "https://github.com/uiwjs/react-codemirror" + }, { "name": "abort-controller", "version": "3.0.0", From c6bbce802ac81906324574e5b198348d4d23bc2d Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:48 +0200 Subject: [PATCH 15/32] derive the editor gutter background from the theme so it stands out on all themes --- src/lib/components/CodeEditor.svelte | 75 ++++++++++++++++++++++++---- src/lib/utils/gutter-contrast.ts | 41 +++++++++++++++ tests/gutter-contrast.test.ts | 55 ++++++++++++++++++++ 3 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 src/lib/utils/gutter-contrast.ts create mode 100644 tests/gutter-contrast.test.ts diff --git a/src/lib/components/CodeEditor.svelte b/src/lib/components/CodeEditor.svelte index e7c2ee487..f4a68da44 100644 --- a/src/lib/components/CodeEditor.svelte +++ b/src/lib/components/CodeEditor.svelte @@ -11,6 +11,8 @@ import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark'; import { indentationMarkers } from '@replit/codemirror-indentation-markers'; import { themeStore } from '$lib/stores/theme'; + import { getEditorThemeExtension } from '$lib/utils/editor-theme-extensions'; + import { gutterBackgroundFor } from '$lib/utils/gutter-contrast'; import { get } from 'svelte/store'; import { shell } from '@codemirror/legacy-modes/mode/shell'; import { dockerFile } from '@codemirror/legacy-modes/mode/dockerfile'; @@ -233,9 +235,11 @@ onLintClick?: (line: number) => void; /** 1-based inclusive line ranges highlighted as freshly-added (green), e.g. a merged-in service. */ addedLineMarkers?: { line: number; endLine: number }[]; + /** Force a specific editor color theme id, ignoring the user's stored preference (live preview). */ + editorThemeOverride?: string; } - let { value = '', language = 'yaml', readonly = false, theme = 'dark', onchange, class: className = '', variableMarkers: variableMarkersProp = [], lintMarkers: lintMarkersProp = [], onLintClick, addedLineMarkers: addedLineMarkersProp = [] }: Props = $props(); + let { value = '', language = 'yaml', readonly = false, theme = 'dark', onchange, class: className = '', variableMarkers: variableMarkersProp = [], lintMarkers: lintMarkersProp = [], onLintClick, addedLineMarkers: addedLineMarkersProp = [], editorThemeOverride }: Props = $props(); // Keep markers reactive - destructured props with defaults lose reactivity const variableMarkers = $derived(variableMarkersProp); @@ -759,9 +763,9 @@ padding: '8px 0' }, '.cm-gutters': { - backgroundColor: '#1a1a1a', + backgroundColor: '#212121', color: '#858585', - border: 'none', + borderRight: '1px solid #333333', fontFamily: 'var(--font-editor, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)', fontSize: '13px' }, @@ -801,14 +805,14 @@ padding: '8px 0' }, '.cm-gutters': { - backgroundColor: '#fafafa', + backgroundColor: '#f1f1f1', color: '#a1a1aa', - border: 'none', + borderRight: '1px solid #e0e0e0', fontFamily: 'var(--font-editor, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)', fontSize: '13px' }, '.cm-activeLineGutter': { - backgroundColor: '#f4f4f5' + backgroundColor: '#e8e8e8' }, '.cm-activeLine': { backgroundColor: '#f4f4f5' @@ -837,13 +841,51 @@ // Track last applied markers to avoid redundant updates let lastAppliedMarkersJson = ''; + // Give the gutter a background derived from the (rendered) code background so line + // numbers stay visibly separated on any @uiw theme (#1309). Reads the real applied + // colour, so it works without knowing the theme's palette. + function applyGutterContrast() { + if (!view) return; + const gutters = view.dom.querySelector('.cm-gutters') as HTMLElement | null; + if (!gutters) return; + // The theme background can sit on .cm-content, the editor root, or the scroller; + // take the first that resolves to a real rgb() (skip transparent). + let gutterBg: string | null = null; + for (const sel of ['.cm-content', '.cm-scroller', '.cm-editor']) { + const el = (sel === '.cm-editor' ? view.dom : view.dom.querySelector(sel)) as HTMLElement | null; + if (!el) continue; + gutterBg = gutterBackgroundFor(getComputedStyle(el).backgroundColor); + if (gutterBg) break; + } + if (gutterBg) gutters.style.backgroundColor = gutterBg; + } + function createEditor() { if (!container || view || initialized) return; initialized = true; - const themeExtensions = theme === 'dark' - ? [dockhandDark, syntaxHighlighting(oneDarkHighlightStyle)] - : [dockhandLight, syntaxHighlighting(defaultHighlightStyle)]; + // Editor color theme (#1309): 'default' keeps the built-in theme that follows + // the app's dark/light toggle; any other id applies a @uiw theme extension + // (self-contained - it brings its own background/gutter/syntax colors). + const editorThemeId = editorThemeOverride ?? get(themeStore).editorTheme; + const pickedExtension = getEditorThemeExtension(editorThemeId); + // @uiw themes don't set a font, and most give the gutter the same background as the + // code so line numbers blend in (#1309). Force the user's editor font and a firmer + // border here; the distinct gutter BACKGROUND is derived from the rendered code + // background after mount (applyGutterContrast) so it stays visible on any theme. + const editorThemeTweaks = EditorView.theme({ + '.cm-content, .cm-gutters': { + fontFamily: 'var(--font-editor, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)' + }, + '.cm-gutters': { + borderRight: '1px solid rgba(128, 128, 128, 0.5)' + } + }); + const themeExtensions = pickedExtension + ? [pickedExtension, editorThemeTweaks] + : theme === 'dark' + ? [dockhandDark, syntaxHighlighting(oneDarkHighlightStyle)] + : [dockhandLight, syntaxHighlighting(defaultHighlightStyle)]; // Build autocompletion config - add Docker Compose completions for YAML // Note: activateOnTyping can interfere with key repeat, so we disable it @@ -942,6 +984,11 @@ dispatchTransactions }); + // Derive a visibly distinct gutter background from the theme's rendered code + // background (#1309). Only for @uiw themes; the built-in dockhand themes set their + // own gutter colour. Runs after mount so getComputedStyle sees the applied theme. + if (pickedExtension) applyGutterContrast(); + // Push initial variable markers if provided. Lint markers need no initial // dispatch: currentLintField/gutter are created from lintMarkers, and the reactive // $effect below fires once on mount - dispatching here too would double it. @@ -1074,17 +1121,23 @@ let prevLanguage = $state(language); let prevTheme = $state(theme); let prevIndentGuides = $state($themeStore.editorIndentGuides); + let prevEditorTheme = $state(editorThemeOverride ?? $themeStore.editorTheme); + let prevEditorFont = $state($themeStore.editorFont); - // Recreate editor if language, theme, or the indent-guides preference changes + // Recreate editor if language, theme, indent-guides, the color theme, or the editor font changes $effect(() => { const currentLanguage = language; const currentTheme = theme; const currentIndentGuides = $themeStore.editorIndentGuides; + const currentEditorTheme = editorThemeOverride ?? $themeStore.editorTheme; + const currentEditorFont = $themeStore.editorFont; - if (view && (currentLanguage !== prevLanguage || currentTheme !== prevTheme || currentIndentGuides !== prevIndentGuides)) { + if (view && (currentLanguage !== prevLanguage || currentTheme !== prevTheme || currentIndentGuides !== prevIndentGuides || currentEditorTheme !== prevEditorTheme || currentEditorFont !== prevEditorFont)) { prevLanguage = currentLanguage; prevTheme = currentTheme; prevIndentGuides = currentIndentGuides; + prevEditorTheme = currentEditorTheme; + prevEditorFont = currentEditorFont; const currentContent = view.state.doc.toString(); destroyEditor(); value = currentContent; // Preserve content diff --git a/src/lib/utils/gutter-contrast.ts b/src/lib/utils/gutter-contrast.ts new file mode 100644 index 000000000..763369928 --- /dev/null +++ b/src/lib/utils/gutter-contrast.ts @@ -0,0 +1,41 @@ +// Compute a gutter background that stays visibly distinct from the editor's own +// background on ANY theme (#1309). @uiw themes give the gutter the same colour as the +// code, so line numbers blend in. Rather than guess per theme, the caller reads the +// rendered background and this derives a contrasting tint from it. + +export interface Rgb { + r: number; + g: number; + b: number; +} + +// Parse "rgb(r, g, b)" / "rgba(r, g, b, a)" (the form getComputedStyle returns). +// Returns null for anything else (e.g. "transparent", named colours, empty). +export function parseRgb(color: string | null | undefined): Rgb | null { + if (!color) return null; + const m = color.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i); + if (!m) return null; + return { r: Number(m[1]), g: Number(m[2]), b: Number(m[3]) }; +} + +// Perceived luminance 0..255 (Rec. 601 weights). +export function luminance({ r, g, b }: Rgb): number { + return 0.299 * r + 0.587 * g + 0.114 * b; +} + +function clamp(n: number): number { + return Math.max(0, Math.min(255, Math.round(n))); +} + +// A gutter background derived from the code background: lighten a dark background, +// darken a light one, by a fixed step so the shift is always visible. Returns an +// rgb() string, or null if the input can't be parsed (caller keeps its fallback). +export function gutterBackgroundFor(codeBg: string | null | undefined, step = 24): string | null { + const rgb = parseRgb(codeBg); + if (!rgb) return null; + const dir = luminance(rgb) < 128 ? 1 : -1; // dark bg -> lighten, light bg -> darken + const r = clamp(rgb.r + dir * step); + const g = clamp(rgb.g + dir * step); + const b = clamp(rgb.b + dir * step); + return `rgb(${r}, ${g}, ${b})`; +} diff --git a/tests/gutter-contrast.test.ts b/tests/gutter-contrast.test.ts new file mode 100644 index 000000000..09b685c9b --- /dev/null +++ b/tests/gutter-contrast.test.ts @@ -0,0 +1,55 @@ +import { describe, test, expect } from 'bun:test'; +import { parseRgb, luminance, gutterBackgroundFor } from '../src/lib/utils/gutter-contrast'; + +describe('gutter-contrast', () => { + test('parseRgb reads rgb() and rgba()', () => { + expect(parseRgb('rgb(46, 52, 64)')).toEqual({ r: 46, g: 52, b: 64 }); + expect(parseRgb('rgba(255, 255, 255, 0.5)')).toEqual({ r: 255, g: 255, b: 255 }); + expect(parseRgb('RGB( 1 , 2 , 3 )')).toEqual({ r: 1, g: 2, b: 3 }); + }); + + test('parseRgb returns null for non-rgb inputs', () => { + expect(parseRgb('transparent')).toBeNull(); + expect(parseRgb('#2e3440')).toBeNull(); + expect(parseRgb('')).toBeNull(); + expect(parseRgb(null)).toBeNull(); + expect(parseRgb(undefined)).toBeNull(); + }); + + test('luminance orders dark below light', () => { + expect(luminance({ r: 0, g: 0, b: 0 })).toBe(0); + expect(luminance({ r: 255, g: 255, b: 255 })).toBeCloseTo(255, 0); + expect(luminance({ r: 46, g: 52, b: 64 })).toBeLessThan(128); // Nord bg is dark + }); + + test('a dark background yields a LIGHTER gutter', () => { + // Nord background rgb(46,52,64) -> each channel +24 + expect(gutterBackgroundFor('rgb(46, 52, 64)')).toBe('rgb(70, 76, 88)'); + }); + + test('a light background yields a DARKER gutter', () => { + // GitHub Light background rgb(255,255,255) -> each channel -24 + expect(gutterBackgroundFor('rgb(255, 255, 255)')).toBe('rgb(231, 231, 231)'); + }); + + test('channels clamp at 0 and 255', () => { + expect(gutterBackgroundFor('rgb(0, 0, 0)')).toBe('rgb(24, 24, 24)'); // black lightens + expect(gutterBackgroundFor('rgb(250, 250, 250)', 24)).toBe('rgb(226, 226, 226)'); + // near-black with a big step never goes negative + expect(gutterBackgroundFor('rgb(5, 5, 5)', 100)).toBe('rgb(105, 105, 105)'); + }); + + test('unparseable background returns null so the caller keeps its fallback', () => { + expect(gutterBackgroundFor('transparent')).toBeNull(); + expect(gutterBackgroundFor(null)).toBeNull(); + }); + + test('the shift is always visible (>= 24 per channel by default)', () => { + for (const bg of ['rgb(40, 42, 54)', 'rgb(30, 30, 30)', 'rgb(253, 246, 227)']) { + const out = gutterBackgroundFor(bg)!; + const before = parseRgb(bg)!; + const after = parseRgb(out)!; + expect(Math.abs(after.r - before.r)).toBeGreaterThanOrEqual(24); + } + }); +}); From 4128efa17973ca72223fa17bc68f9e915492f20f Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:48 +0200 Subject: [PATCH 16/32] add selectable code editor color themes and fix gutter readability --- src/lib/stores/theme.ts | 7 +- src/lib/utils/editor-theme-extensions.ts | 61 +++++++++++++++ src/lib/utils/editor-themes.ts | 76 +++++++++++++++++++ src/routes/api/profile/preferences/+server.ts | 14 +++- src/routes/api/settings/theme/+server.ts | 12 ++- tests/editor-themes.test.ts | 69 +++++++++++++++++ 6 files changed, 230 insertions(+), 9 deletions(-) create mode 100644 src/lib/utils/editor-theme-extensions.ts create mode 100644 src/lib/utils/editor-themes.ts create mode 100644 tests/editor-themes.test.ts diff --git a/src/lib/stores/theme.ts b/src/lib/stores/theme.ts index 84fec0daa..70db49089 100644 --- a/src/lib/stores/theme.ts +++ b/src/lib/stores/theme.ts @@ -36,6 +36,7 @@ export interface ThemePreferences { coloredActionButtons: boolean; actionIconSize: ActionIconSize; editorIndentGuides: boolean; + editorTheme: string; } const STORAGE_KEY = 'dockhand-theme'; @@ -51,7 +52,8 @@ const defaultPrefs: ThemePreferences = { animateIcons: true, coloredActionButtons: false, actionIconSize: 'normal', - editorIndentGuides: false + editorIndentGuides: false, + editorTheme: 'default' }; // Font size scale mapping @@ -130,7 +132,8 @@ function createThemeStore() { coloredActionButtons: !!(data.coloredActionButtons ?? data.colored_action_buttons ?? false), actionIconSize: (data.actionIconSize || data.action_icon_size || 'normal') as ActionIconSize, // Default OFF (#1410) - editorIndentGuides: !!(data.editorIndentGuides ?? data.editor_indent_guides ?? false) + editorIndentGuides: !!(data.editorIndentGuides ?? data.editor_indent_guides ?? false), + editorTheme: data.editorTheme || data.editor_theme || 'default' }; set(prefs); saveToStorage(prefs); diff --git a/src/lib/utils/editor-theme-extensions.ts b/src/lib/utils/editor-theme-extensions.ts new file mode 100644 index 000000000..01a6c91b4 --- /dev/null +++ b/src/lib/utils/editor-theme-extensions.ts @@ -0,0 +1,61 @@ +import type { Extension } from '@codemirror/state'; +import * as uiw from '@uiw/codemirror-themes-all'; + +// id -> CM6 theme Extension (#1309). Heavy (pulls the whole @uiw theme package), so this +// module is imported ONLY client-side (CodeEditor / EditorThemeSelector). 'default' maps +// to null - CodeEditor then uses its built-in dark/light theme that follows the app toggle. +// Keys must match the ids in editor-themes.ts. +const EXTENSIONS: Record = { + dracula: uiw.dracula, + 'vscode-dark': uiw.vscodeDark, + 'github-dark': uiw.githubDark, + monokai: uiw.monokai, + 'monokai-dimmed': uiw.monokaiDimmed, + nord: uiw.nord, + 'tokyo-night': uiw.tokyoNight, + 'tokyo-night-storm': uiw.tokyoNightStorm, + 'solarized-dark': uiw.solarizedDark, + 'gruvbox-dark': uiw.gruvboxDark, + 'material-dark': uiw.materialDark, + 'atom-one': uiw.atomone, + androidstudio: uiw.androidstudio, + andromeda: uiw.andromeda, + aura: uiw.aura, + abcdef: uiw.abcdef, + abyss: uiw.abyss, + bespin: uiw.bespin, + copilot: uiw.copilot, + darcula: uiw.darcula, + 'duotone-dark': uiw.duotoneDark, + kimbie: uiw.kimbie, + okaidia: uiw.okaidia, + red: uiw.red, + sublime: uiw.sublime, + 'console-dark': uiw.consoleDark, + 'tomorrow-night-blue': uiw.tomorrowNightBlue, + 'white-dark': uiw.whiteDark, + 'xcode-dark': uiw.xcodeDark, + material: uiw.material, + 'basic-dark': uiw.basicDark, + + 'github-light': uiw.githubLight, + 'vscode-light': uiw.vscodeLight, + 'solarized-light': uiw.solarizedLight, + 'gruvbox-light': uiw.gruvboxLight, + 'material-light': uiw.materialLight, + 'duotone-light': uiw.duotoneLight, + eclipse: uiw.eclipse, + bbedit: uiw.bbedit, + 'noctis-lilac': uiw.noctisLilac, + quietlight: uiw.quietlight, + 'tokyo-night-day': uiw.tokyoNightDay, + 'xcode-light': uiw.xcodeLight, + 'console-light': uiw.consoleLight, + 'white-light': uiw.whiteLight +}; + +// Returns the CM6 theme extension for an id, or null for 'default'/unknown (built-in theme). +export function getEditorThemeExtension(id: string | undefined | null): Extension | null { + if (!id || id === 'default') return null; + return EXTENSIONS[id] ?? null; +} diff --git a/src/lib/utils/editor-themes.ts b/src/lib/utils/editor-themes.ts new file mode 100644 index 000000000..31b1f9c32 --- /dev/null +++ b/src/lib/utils/editor-themes.ts @@ -0,0 +1,76 @@ +// CodeMirror editor color themes (#1309) - LIGHT metadata only (no @uiw import). +// The heavy id->Extension mapping lives in editor-theme-extensions.ts and is imported +// only client-side (CodeEditor / EditorThemeSelector). Server routes import this module +// to validate an id string, so it must stay free of any CodeMirror weight. + +export interface EditorThemeMeta { + id: string; + label: string; + dark: boolean; +} + +// Built-in first, then dark, then light. Ids are persisted (per-user/global) - keep stable. +export const EDITOR_THEMES: EditorThemeMeta[] = [ + { id: 'default', label: 'Default (follows app theme)', dark: true }, + + // Dark + { id: 'dracula', label: 'Dracula', dark: true }, + { id: 'vscode-dark', label: 'VS Code Dark', dark: true }, + { id: 'github-dark', label: 'GitHub Dark', dark: true }, + { id: 'monokai', label: 'Monokai', dark: true }, + { id: 'monokai-dimmed', label: 'Monokai Dimmed', dark: true }, + { id: 'nord', label: 'Nord', dark: true }, + { id: 'tokyo-night', label: 'Tokyo Night', dark: true }, + { id: 'tokyo-night-storm', label: 'Tokyo Night Storm', dark: true }, + { id: 'solarized-dark', label: 'Solarized Dark', dark: true }, + { id: 'gruvbox-dark', label: 'Gruvbox Dark', dark: true }, + { id: 'material-dark', label: 'Material Dark', dark: true }, + { id: 'atom-one', label: 'Atom One', dark: true }, + { id: 'androidstudio', label: 'Android Studio', dark: true }, + { id: 'andromeda', label: 'Andromeda', dark: true }, + { id: 'aura', label: 'Aura', dark: true }, + { id: 'abcdef', label: 'abcdef', dark: true }, + { id: 'abyss', label: 'Abyss', dark: true }, + { id: 'bespin', label: 'Bespin', dark: true }, + { id: 'copilot', label: 'Copilot', dark: true }, + { id: 'darcula', label: 'Darcula', dark: true }, + { id: 'duotone-dark', label: 'Duotone Dark', dark: true }, + { id: 'kimbie', label: 'Kimbie', dark: true }, + { id: 'okaidia', label: 'Okaidia', dark: true }, + { id: 'red', label: 'Red', dark: true }, + { id: 'sublime', label: 'Sublime', dark: true }, + { id: 'console-dark', label: 'Console Dark', dark: true }, + { id: 'tomorrow-night-blue', label: 'Tomorrow Night Blue', dark: true }, + { id: 'white-dark', label: 'White Dark', dark: true }, + { id: 'xcode-dark', label: 'Xcode Dark', dark: true }, + { id: 'material', label: 'Material', dark: true }, + { id: 'basic-dark', label: 'Basic Dark', dark: true }, + + // Light + { id: 'github-light', label: 'GitHub Light', dark: false }, + { id: 'vscode-light', label: 'VS Code Light', dark: false }, + { id: 'solarized-light', label: 'Solarized Light', dark: false }, + { id: 'gruvbox-light', label: 'Gruvbox Light', dark: false }, + { id: 'material-light', label: 'Material Light', dark: false }, + { id: 'duotone-light', label: 'Duotone Light', dark: false }, + { id: 'eclipse', label: 'Eclipse', dark: false }, + { id: 'bbedit', label: 'BBEdit', dark: false }, + { id: 'noctis-lilac', label: 'Noctis Lilac', dark: false }, + { id: 'quietlight', label: 'Quiet Light', dark: false }, + { id: 'tokyo-night-day', label: 'Tokyo Night Day', dark: false }, + { id: 'xcode-light', label: 'Xcode Light', dark: false }, + { id: 'console-light', label: 'Console Light', dark: false }, + { id: 'white-light', label: 'White Light', dark: false } +]; + +export const EDITOR_THEME_IDS: string[] = EDITOR_THEMES.map((t) => t.id); +const ID_SET = new Set(EDITOR_THEME_IDS); +const META_BY_ID = new Map(EDITOR_THEMES.map((t) => [t.id, t])); + +export function getEditorThemeMeta(id: string | undefined | null): EditorThemeMeta { + return META_BY_ID.get(id ?? 'default') ?? EDITOR_THEMES[0]; +} + +export function isValidEditorThemeId(id: unknown): id is string { + return typeof id === 'string' && ID_SET.has(id); +} diff --git a/src/routes/api/profile/preferences/+server.ts b/src/routes/api/profile/preferences/+server.ts index c62c2a8c3..db83011de 100644 --- a/src/routes/api/profile/preferences/+server.ts +++ b/src/routes/api/profile/preferences/+server.ts @@ -3,6 +3,7 @@ import type { RequestHandler } from '@sveltejs/kit'; import { getUserThemePreferences, setUserThemePreferences } from '$lib/server/db'; import { validateSession, isAuthEnabled } from '$lib/server/auth'; import { lightThemes, darkThemes, fonts, monospaceFonts } from '$lib/themes'; +import { isValidEditorThemeId } from '$lib/utils/editor-themes'; // GET /api/profile/preferences - Get current user's theme preferences /** @@ -35,8 +36,8 @@ export const GET: RequestHandler = async ({ cookies }) => { /** * @openapi * summary: Update the current user's UI preferences (each field is optional) - * body: {lightTheme:string, darkTheme:string, font:string, fontSize:string, gridFontSize:string, terminalFont:string, editorFont:string, animateIcons:boolean, coloredActionButtons:boolean, actionIconSize:string, editorIndentGuides:boolean} - * resp-400: A supplied field has the wrong type (e.g. editorIndentGuides not a boolean) + * body: {lightTheme:string, darkTheme:string, font:string, fontSize:string, gridFontSize:string, terminalFont:string, editorFont:string, animateIcons:boolean, coloredActionButtons:boolean, actionIconSize:string, editorIndentGuides:boolean, editorTheme:string} + * resp-400: A supplied field has the wrong type or an invalid value (e.g. editorIndentGuides not a boolean, or an unknown editorTheme) * resp-401: Not authenticated * resp-500: Failed to save preferences */ @@ -62,7 +63,7 @@ export const PUT: RequestHandler = async ({ request, cookies }) => { const validActionIconSizes = ['small', 'normal', 'large', 'xlarge']; - const updates: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string; editorIndentGuides?: boolean } = {}; + const updates: { lightTheme?: string; darkTheme?: string; font?: string; fontSize?: string; gridFontSize?: string; terminalFont?: string; editorFont?: string; animateIcons?: boolean; coloredActionButtons?: boolean; actionIconSize?: string; editorIndentGuides?: boolean; editorTheme?: string } = {}; if (data.lightTheme !== undefined) { if (!validLightThemeIds.includes(data.lightTheme)) { @@ -127,6 +128,13 @@ export const PUT: RequestHandler = async ({ request, cookies }) => { updates.editorIndentGuides = data.editorIndentGuides; } + if (data.editorTheme !== undefined) { + if (!isValidEditorThemeId(data.editorTheme)) { + return json({ error: 'Invalid editor theme' }, { status: 400 }); + } + updates.editorTheme = data.editorTheme; + } + if (data.coloredActionButtons !== undefined) { if (typeof data.coloredActionButtons !== 'boolean') { return json({ error: 'Invalid coloredActionButtons' }, { status: 400 }); diff --git a/src/routes/api/settings/theme/+server.ts b/src/routes/api/settings/theme/+server.ts index 75cf21b54..41b5d9102 100644 --- a/src/routes/api/settings/theme/+server.ts +++ b/src/routes/api/settings/theme/+server.ts @@ -17,7 +17,8 @@ const DEFAULT_THEME_SETTINGS = { animateIcons: true, coloredActionButtons: false, actionIconSize: 'normal', - editorIndentGuides: false + editorIndentGuides: false, + editorTheme: 'default' }; /** @@ -39,7 +40,8 @@ export const GET: RequestHandler = async () => { animateIcons, coloredActionButtons, actionIconSize, - editorIndentGuides + editorIndentGuides, + editorTheme ] = await Promise.all([ getSetting('theme_light'), getSetting('theme_dark'), @@ -51,7 +53,8 @@ export const GET: RequestHandler = async () => { getSetting('animate_icons'), getSetting('colored_action_buttons'), getSetting('action_icon_size'), - getSetting('editor_indent_guides') + getSetting('editor_indent_guides'), + getSetting('theme_editor_theme') ]); return json({ @@ -65,7 +68,8 @@ export const GET: RequestHandler = async () => { animateIcons: animateIcons ?? DEFAULT_THEME_SETTINGS.animateIcons, coloredActionButtons: coloredActionButtons ?? DEFAULT_THEME_SETTINGS.coloredActionButtons, actionIconSize: actionIconSize ?? DEFAULT_THEME_SETTINGS.actionIconSize, - editorIndentGuides: editorIndentGuides ?? DEFAULT_THEME_SETTINGS.editorIndentGuides + editorIndentGuides: editorIndentGuides ?? DEFAULT_THEME_SETTINGS.editorIndentGuides, + editorTheme: editorTheme ?? DEFAULT_THEME_SETTINGS.editorTheme }); } catch (error) { console.error('Failed to get theme settings:', error); diff --git a/tests/editor-themes.test.ts b/tests/editor-themes.test.ts new file mode 100644 index 000000000..0d00a5c83 --- /dev/null +++ b/tests/editor-themes.test.ts @@ -0,0 +1,69 @@ +import { describe, test, expect } from 'bun:test'; +import { + EDITOR_THEMES, + EDITOR_THEME_IDS, + getEditorThemeMeta, + isValidEditorThemeId +} from '../src/lib/utils/editor-themes'; +import { getEditorThemeExtension } from '../src/lib/utils/editor-theme-extensions'; + +describe('editor-themes (light metadata, no @uiw import)', () => { + test("'default' is first", () => { + expect(EDITOR_THEMES[0].id).toBe('default'); + }); + + test('theme ids are unique (ids are persisted, must not collide)', () => { + const seen = new Set(); + for (const id of EDITOR_THEME_IDS) { + expect(seen.has(id), `duplicate id ${id}`).toBe(false); + seen.add(id); + } + }); + + test('every theme has a non-empty label', () => { + for (const t of EDITOR_THEMES) { + expect(t.label.length, `${t.id} label`).toBeGreaterThan(0); + } + }); + + test('isValidEditorThemeId accepts known ids and rejects everything else', () => { + expect(isValidEditorThemeId('default')).toBe(true); + expect(isValidEditorThemeId('dracula')).toBe(true); + expect(isValidEditorThemeId('nord')).toBe(true); + expect(isValidEditorThemeId('not-a-theme')).toBe(false); + expect(isValidEditorThemeId('')).toBe(false); + expect(isValidEditorThemeId(undefined)).toBe(false); + expect(isValidEditorThemeId(null)).toBe(false); + expect(isValidEditorThemeId(42)).toBe(false); + }); + + test('getEditorThemeMeta falls back to default for unknown/empty ids', () => { + expect(getEditorThemeMeta('dracula').id).toBe('dracula'); + expect(getEditorThemeMeta('not-a-theme').id).toBe('default'); + expect(getEditorThemeMeta(undefined).id).toBe('default'); + expect(getEditorThemeMeta(null).id).toBe('default'); + }); + + test('both dark and light themes are offered', () => { + expect(EDITOR_THEMES.some((t) => t.dark && t.id !== 'default')).toBe(true); + expect(EDITOR_THEMES.some((t) => !t.dark)).toBe(true); + }); +}); + +describe('editor-theme-extensions (client-only, heavy)', () => { + test("'default' and unknown ids resolve to null (built-in theme in CodeEditor)", () => { + expect(getEditorThemeExtension('default')).toBeNull(); + expect(getEditorThemeExtension(undefined)).toBeNull(); + expect(getEditorThemeExtension(null)).toBeNull(); + expect(getEditorThemeExtension('not-a-theme')).toBeNull(); + }); + + test('every non-default theme id maps to a real CM6 extension', () => { + for (const t of EDITOR_THEMES) { + if (t.id === 'default') continue; + const ext = getEditorThemeExtension(t.id); + expect(ext, `${t.id} must have an extension`).not.toBeNull(); + expect(ext, `${t.id} extension must be defined`).toBeDefined(); + } + }); +}); From be98304b0657b5a618c4ab21c34d549f4341f54f Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:48 +0200 Subject: [PATCH 17/32] give the editor theme preview full width and honor the editor font --- src/routes/profile/+page.svelte | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/routes/profile/+page.svelte b/src/routes/profile/+page.svelte index e6f55726b..d315bfa4b 100644 --- a/src/routes/profile/+page.svelte +++ b/src/routes/profile/+page.svelte @@ -43,6 +43,7 @@ import AnimateIconsToggle from '$lib/components/AnimateIconsToggle.svelte'; import IndentGuidesToggle from '$lib/components/IndentGuidesToggle.svelte'; import ColoredActionsToggle from '$lib/components/ColoredActionsToggle.svelte'; + import EditorThemeSelector from '$lib/components/EditorThemeSelector.svelte'; import { themeStore } from '$lib/stores/theme'; import PageHeader from '$lib/components/PageHeader.svelte'; @@ -751,6 +752,20 @@
+ + + + + + + Editor theme + + Color theme for the code editor, with a live preview. + + + + +
{/if}
From eb9b5a766d0c809fe9c3fa18cc7517ff6c67d5f0 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:48 +0200 Subject: [PATCH 18/32] show a shared container once per environment in the command palette --- src/lib/components/CommandPalette.svelte | 635 +++++++++++++++-------- src/lib/utils/palette-data.ts | 73 +++ tests/palette-data.test.ts | 95 ++++ 3 files changed, 586 insertions(+), 217 deletions(-) create mode 100644 src/lib/utils/palette-data.ts create mode 100644 tests/palette-data.test.ts diff --git a/src/lib/components/CommandPalette.svelte b/src/lib/components/CommandPalette.svelte index 58a51f941..4e422af77 100644 --- a/src/lib/components/CommandPalette.svelte +++ b/src/lib/components/CommandPalette.svelte @@ -1,7 +1,7 @@ - - - - No results found. - - {#each filteredItems as item (item.href)} - handleSelect(item.href)} - > - - {item.name} - - {/each} - - {#if $licenseStore.isEnterprise && $authStore.authEnabled} - - - handleSelect('/audit')} - > - - Audit log - - - {/if} - - - {#each lightThemes as theme (theme.id)} - handleLightThemeSelect(theme.id)} - > - -
-
- {theme.name} -
- {#if $themeStore.lightTheme === theme.id} - - {/if} -
- {/each} -
- - - {#each darkThemes as theme (theme.id)} - handleDarkThemeSelect(theme.id)} - > - -
-
- {theme.name} -
- {#if $themeStore.darkTheme === theme.id} - - {/if} -
- {/each} -
- - - {#each fonts as font (font.id)} - handleFontSelect(font.id)} - > - - {font.name} - {#if $themeStore.font === font.id} - - {/if} - - {/each} - - {#if environments.length > 0} - - - {#each environments as env (env.id)} - handleEnvSelect(env)} - > - - {env.name} - {#if $currentEnvironment?.id === env.id} - + + + Command palette + Search for pages, themes, environments, stacks and containers + +
+ + = 0 ? `palette-row-${activeRow}` : undefined} + class="h-11 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground" + /> +
+ + {#if rows.length === 0} +
No results found.
+ {:else} +
(scrollTop = e.currentTarget.scrollTop)} + class="max-h-[min(60vh,400px)] overflow-y-auto" + > +
+ {#each visible as { row, index } (index)} + {#if row.type === 'header'} +
+ {row.group} +
+ {:else} + {@const item = row.item} + {@const meta = built.meta.get(item.id)} + {@const isActive = index === activeRow} + + +
{ activeRow = index; meta?.run(); }} + onmousemove={() => (activeRow = index)} + class="absolute left-0 right-0 flex cursor-pointer items-center gap-2 px-3 text-sm {isActive ? 'bg-accent text-accent-foreground' : ''}" + style="top: {offsets[index]}px; height: {ITEM_H}px;" + > + {#if meta?.container} + {@const c = meta.container} + +
+ {item.label} + + + {c.envName} - {c.image} + +
+ {#if isActive} +
+ {#if c.state === 'running'} + + + + + {:else} + + {/if} +
+ {/if} + {:else if meta?.stack} + {@const s = meta.stack} + +
+ {item.label} + + + {s.envName} + +
+ {:else if meta?.env} + + {item.label} + {#if item.active} + + {/if} + {:else} + {@const Icon = meta?.icon ?? Box} + + {#if meta?.preview} + + {/if} + {item.label} + {#if item.active} + + {/if} + {/if} +
{/if} - - {/each} - - {/if} - {#if containers.length > 0} - - - {#each containers as container (container.id)} - handleContainerAction(container.id, 'logs')} - > - -
- {container.name} - {container.envName} • {container.image} -
-
- {#if container.state === 'running'} - - - - - {:else} - - {/if} -
-
- {/each} -
+ {/each} +
+
{/if} -
-
+ + diff --git a/src/lib/utils/palette-data.ts b/src/lib/utils/palette-data.ts new file mode 100644 index 000000000..2725278a2 --- /dev/null +++ b/src/lib/utils/palette-data.ts @@ -0,0 +1,73 @@ +// Pure row mappers for the command palette. The /api/containers and /api/stacks +// endpoints are per-environment and return camelCase rows; the palette stamps the +// env identity (from the loop) onto each row. Extracted (like palette-filter) so the +// exact field mapping that once regressed to Docker PascalCase is unit-testable. + +export interface PaletteEnv { + id: number; + name: string; + icon?: string; +} + +export interface ContainerRow { + id: string; + name: string; + state: string; + image: string; + envId: number; + envName: string; + envIcon: string; +} + +export interface StackRow { + id: string; + name: string; + icon?: string | null; + envId: number; + envName: string; + envIcon: string; +} + +/** Map one env's /api/containers rows (camelCase {id,name,state,image}) to palette rows. */ +export function mapContainerRows(list: unknown, env: PaletteEnv): ContainerRow[] { + if (!Array.isArray(list)) return []; + return list.map((c: any) => ({ + id: c.id, + name: c.name, + state: c.state, + image: c.image, + envId: env.id, + envName: env.name, + envIcon: env.icon || 'globe' + })); +} + +/** Map one env's /api/stacks rows to palette rows (id namespaced by env). */ +export function mapStackRows(list: unknown, env: PaletteEnv): StackRow[] { + if (!Array.isArray(list)) return []; + return list.map((s: any) => ({ + id: `${env.id}:${s.name}`, + name: s.name, + icon: s.icon ?? null, + envId: env.id, + envName: env.name, + envIcon: env.icon || 'globe' + })); +} + +/** + * Flatten per-group arrays by taking one from each group in turn + * (g0[0], g1[0], ..., g0[1], g1[1], ...). The palette caps its empty view, so + * interleaving per environment surfaces variety instead of filling the cap with + * one environment's rows (and their copies when environments share a daemon). + */ +export function roundRobin(groups: T[][]): T[] { + const out: T[] = []; + const max = Math.max(0, ...groups.map((g) => g.length)); + for (let i = 0; i < max; i++) { + for (const g of groups) { + if (i < g.length) out.push(g[i]); + } + } + return out; +} diff --git a/tests/palette-data.test.ts b/tests/palette-data.test.ts new file mode 100644 index 000000000..4352c4e50 --- /dev/null +++ b/tests/palette-data.test.ts @@ -0,0 +1,95 @@ +import { describe, test, expect } from 'bun:test'; +import { mapContainerRows, mapStackRows, roundRobin } from '../src/lib/utils/palette-data'; + +const env = { id: 7, name: 'prod', icon: 'server' }; + +describe('mapContainerRows', () => { + test('maps camelCase container fields and stamps env identity', () => { + const rows = mapContainerRows( + [{ id: 'abc123', name: 'nginx', state: 'running', image: 'nginx:latest' }], + env + ); + expect(rows).toEqual([ + { + id: 'abc123', + name: 'nginx', + state: 'running', + image: 'nginx:latest', + envId: 7, + envName: 'prod', + envIcon: 'server' + } + ]); + }); + + test('falls back to globe when the env has no icon', () => { + const rows = mapContainerRows([{ id: 'x', name: 'c', state: 'exited', image: 'busybox' }], { + id: 3, + name: 'edge' + }); + expect(rows[0].envIcon).toBe('globe'); + }); + + test('non-array input yields an empty list (offline env / error body)', () => { + expect(mapContainerRows(null, env)).toEqual([]); + expect(mapContainerRows(undefined, env)).toEqual([]); + expect(mapContainerRows({ error: 'nope' }, env)).toEqual([]); + }); + + test('does not read Docker PascalCase fields', () => { + // A raw Docker payload (Id/Names/Image) must NOT map through - guards the regression. + const rows = mapContainerRows([{ Id: 'abc', Names: ['/nginx'], Image: 'nginx', State: 'running' }], env); + expect(rows[0].id).toBeUndefined(); + expect(rows[0].name).toBeUndefined(); + expect(rows[0].image).toBeUndefined(); + }); +}); + +describe('mapStackRows', () => { + test('namespaces the id by env and stamps env identity', () => { + const rows = mapStackRows([{ name: 'web', icon: 'custom:stack' }], env); + expect(rows).toEqual([ + { + id: '7:web', + name: 'web', + icon: 'custom:stack', + envId: 7, + envName: 'prod', + envIcon: 'server' + } + ]); + }); + + test('missing icon becomes null', () => { + const rows = mapStackRows([{ name: 'db' }], env); + expect(rows[0].icon).toBeNull(); + }); + + test('non-array input yields an empty list', () => { + expect(mapStackRows(null, env)).toEqual([]); + expect(mapStackRows('oops', env)).toEqual([]); + }); +}); + +describe('roundRobin', () => { + test('interleaves one from each group in turn', () => { + expect(roundRobin([['a1', 'a2', 'a3'], ['b1', 'b2']])).toEqual(['a1', 'b1', 'a2', 'b2', 'a3']); + }); + + test('uneven group lengths drain in order', () => { + expect(roundRobin([['a1'], ['b1', 'b2', 'b3'], ['c1', 'c2']])).toEqual(['a1', 'b1', 'c1', 'b2', 'c2', 'b3']); + }); + + test('empty groups are skipped', () => { + expect(roundRobin([[], ['b1', 'b2'], []])).toEqual(['b1', 'b2']); + }); + + test('no groups -> empty', () => { + expect(roundRobin([])).toEqual([]); + expect(roundRobin([[], []])).toEqual([]); + }); + + test('single group is returned in order', () => { + expect(roundRobin([['x', 'y', 'z']])).toEqual(['x', 'y', 'z']); + }); +}); From 6e89c6ae8acb2f215768578adbc80f9ba55b9cbb Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:49 +0200 Subject: [PATCH 19/32] follow a cross-host jump to logs or a terminal already open on another host --- src/routes/logs/+page.svelte | 29 ++++++++++++++++++++--------- src/routes/terminal/+page.svelte | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/routes/logs/+page.svelte b/src/routes/logs/+page.svelte index 79e21bcd7..e03903335 100644 --- a/src/routes/logs/+page.svelte +++ b/src/routes/logs/+page.svelte @@ -7,6 +7,7 @@ import { page } from '$app/stores'; import { Button } from '$lib/components/ui/button'; import { Input } from '$lib/components/ui/input'; + import { SearchInput } from '$lib/components/ui/search-input'; import * as Select from '$lib/components/ui/select'; import { Checkbox } from '$lib/components/ui/checkbox'; import { ToggleGroup } from '$lib/components/ui/toggle-pill'; @@ -571,6 +572,24 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server'; } }); + // React to the ?container= URL param CHANGING while the page is already mounted + // (e.g. a cross-host jump from the command palette): the env subscription above + // only runs the URL match once per page load, so a later navigation to a new + // container - possibly on another host, hence keyed on `containers` too - is + // handled here once its container list has loaded. + let lastHandledUrlContainer: string | null = null; + $effect(() => { + const urlContainerId = $page.url.searchParams.get('container'); + const list = containers; // depend on the fetched list so this re-runs after an env switch + if (!urlContainerId || urlContainerId === lastHandledUrlContainer) return; + const container = list.find(c => c.id === urlContainerId || c.id.startsWith(urlContainerId)); + if (!container) return; // list for the target host not loaded yet; re-runs when it is + lastHandledUrlContainer = urlContainerId; + if (selectedContainer?.id === container.id) return; + layoutMode = 'single'; + selectContainer(container); + }); + // Filtered containers based on search let filteredContainers = $derived(() => { if (!searchQuery.trim()) return containers; @@ -1672,15 +1691,7 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server'; {#if layoutMode === 'multi' || layoutMode === 'grouped'}
-
- - -
+
{#if layoutMode === 'grouped'} diff --git a/src/routes/terminal/+page.svelte b/src/routes/terminal/+page.svelte index 32e9e4693..6a020e385 100644 --- a/src/routes/terminal/+page.svelte +++ b/src/routes/terminal/+page.svelte @@ -73,6 +73,22 @@ } }); + // React to the ?container= URL param CHANGING while already mounted (e.g. a + // cross-host jump from the command palette). onMount only matches the URL once, + // so a later navigation to a container - possibly on another host, hence keyed on + // `containers` too - is handled here once its list has loaded. + let lastHandledUrlContainer: string | null = null; + $effect(() => { + const urlContainerId = $page.url.searchParams.get('container'); + const list = containers; + if (!urlContainerId || urlContainerId === lastHandledUrlContainer) return; + const container = list.find(c => c.id === urlContainerId || c.id.startsWith(urlContainerId)); + if (!container) return; + lastHandledUrlContainer = urlContainerId; + if (selectedContainer?.id === container.id) return; + selectContainer(container); + }); + // Filtered containers based on search let filteredContainers = $derived(() => { if (!searchQuery.trim()) return containers; From 00781e809234b8371314293ef303355236af97de Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:49 +0200 Subject: [PATCH 20/32] put time and date format on one row and widen the theme picker --- src/lib/components/EditorThemeSelector.svelte | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/lib/components/EditorThemeSelector.svelte diff --git a/src/lib/components/EditorThemeSelector.svelte b/src/lib/components/EditorThemeSelector.svelte new file mode 100644 index 000000000..9c64c43a2 --- /dev/null +++ b/src/lib/components/EditorThemeSelector.svelte @@ -0,0 +1,173 @@ + + +
+
+ + +
+ + +
+
+ + + {#if awaitingGlobal} +
+ {:else} + + + {currentFontName} + + + {#each monospaceFonts as font} + + {font.name} + + {/each} + + + {/if} +
+ +
+ + {#if awaitingGlobal} +
+ {:else} + + + {currentLabel} + + + Default (follows app theme) + + Dark + {#each darkThemes as t} + {t.label} + {/each} + + + Light + {#each lightThemes as t} + {t.label} + {/each} + + + + {/if} +
+
+ + +
+ +
+

Applies to all code editors (compose files, env, config). Follows this theme regardless of the light/dark app setting.

+
From 8de1fdade523f02f3168cc1051f0e5a1e3504de5 Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Sat, 19 Sep 2026 08:14:49 +0200 Subject: [PATCH 21/32] add a clear (X) button to search fields --- src/lib/components/ui/search-input/index.ts | 3 + .../ui/search-input/search-input.svelte | 55 +++++++++++++++++++ src/routes/+page.svelte | 15 +---- src/routes/activity/+page.svelte | 14 +---- src/routes/backups/+page.svelte | 9 +-- src/routes/backups/CreateBackupModal.svelte | 9 +-- src/routes/images/+page.svelte | 25 ++------- src/routes/networks/+page.svelte | 15 +---- src/routes/registry/+page.svelte | 11 +--- src/routes/settings/about/AboutTab.svelte | 14 +---- .../settings/auth/users/UsersSubTab.svelte | 12 +--- src/routes/settings/backups/BackupsTab.svelte | 12 +--- src/routes/stacks/IconPickerModal.svelte | 14 ++--- src/routes/volumes/+page.svelte | 15 +---- 14 files changed, 93 insertions(+), 130 deletions(-) create mode 100644 src/lib/components/ui/search-input/index.ts create mode 100644 src/lib/components/ui/search-input/search-input.svelte diff --git a/src/lib/components/ui/search-input/index.ts b/src/lib/components/ui/search-input/index.ts new file mode 100644 index 000000000..2cb00c927 --- /dev/null +++ b/src/lib/components/ui/search-input/index.ts @@ -0,0 +1,3 @@ +import SearchInput from './search-input.svelte'; + +export { SearchInput, SearchInput as Root }; diff --git a/src/lib/components/ui/search-input/search-input.svelte b/src/lib/components/ui/search-input/search-input.svelte new file mode 100644 index 000000000..b9457ab7c --- /dev/null +++ b/src/lib/components/ui/search-input/search-input.svelte @@ -0,0 +1,55 @@ + + +
+ + { + if (e.key === 'Escape' && value) { + e.preventDefault(); + value = ''; + } + onkeydown?.(e); + }} + class={cn('pl-8', value ? 'pr-8' : '', className)} + {...rest} + /> + {#if value} + + {/if} +
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 63e04aea4..7857458b4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -5,7 +5,7 @@