Dashboard: programs list deployments; Tools page; statics on Services; editable launcher
- Programs page: each card lists the program's deployments (name · kind) instead of a single kind badge; kind-filter chips removed (nav is the kind lens now). protonmail honestly shows tool + job. - New Tools nav page (Wrench) — programs with a tool deployment (/programs?kind=tool). - Services page now shows statics too: /services returns service + static, and a static renders as a caddy-served card (KindBadge, served URL, no start/stop). - Program detail: DeploymentsSection + deleteConfirm rebuilt over program.deployments; header drops the (now nonexistent) program kind. - ServiceFields / JobFields: launcher is now an editable select (python|command| container|compose|node), persisted into run.launcher via the normal save. clean pnpm build + tsc --noEmit.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { useState } from "react"
|
||||
import type { JobDetail } from "@/types"
|
||||
import { launcherLabel } from "@/lib/labels"
|
||||
import { Field, TextField, FormFooter, useEnvSecrets } from "./fields"
|
||||
|
||||
interface Props {
|
||||
@@ -12,6 +11,28 @@ interface Props {
|
||||
type Obj = Record<string, unknown>
|
||||
const obj = (v: unknown): Obj => (v as Obj) ?? {}
|
||||
|
||||
// A job is a systemd deployment; its launcher is editable like a service's.
|
||||
const LAUNCHERS = ["python", "command", "container", "compose", "node"]
|
||||
|
||||
function applyLauncher(run: Obj, launcher: string, target: string): Obj {
|
||||
const out: Obj = { ...run, launcher }
|
||||
const t = target.trim()
|
||||
if (launcher === "command") {
|
||||
out.argv = t.split(/\s+/).filter(Boolean)
|
||||
delete out.program
|
||||
} else if (launcher === "python") {
|
||||
out.program = t
|
||||
delete out.argv
|
||||
} else if (launcher === "container") {
|
||||
if (t) out.image = t
|
||||
} else if (launcher === "node") {
|
||||
if (t) out.script = t
|
||||
} else if (launcher === "compose") {
|
||||
if (t) out.file = t
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Edit a job's deployment config (schedule / run / env). */
|
||||
export function JobFields({ job, onSave, onDelete }: Props) {
|
||||
const m = job.manifest
|
||||
@@ -22,12 +43,17 @@ export function JobFields({ job, onSave, onDelete }: Props) {
|
||||
|
||||
const [description, setDescription] = useState((m.description as string) ?? "")
|
||||
const [schedule, setSchedule] = useState((m.schedule as string) ?? "")
|
||||
const [launcher, setLauncher] = useState((run.launcher as string) ?? "command")
|
||||
const [runTarget, setRunTarget] = useState(
|
||||
(run.program as string) ?? ((run.argv as string[]) ?? []).join(" "),
|
||||
(run.program as string) ||
|
||||
((run.argv as string[]) ?? []).join(" ") ||
|
||||
(run.image as string) ||
|
||||
(run.script as string) ||
|
||||
(run.file as string) ||
|
||||
"",
|
||||
)
|
||||
|
||||
const { element: envEditor, merged } = useEnvSecrets(obj(obj(m.defaults).env) as Record<string, string>)
|
||||
const launcher = (run.launcher as string) ?? "?"
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true)
|
||||
@@ -38,10 +64,7 @@ export function JobFields({ job, onSave, onDelete }: Props) {
|
||||
config.description = description || undefined
|
||||
config.schedule = schedule || undefined
|
||||
|
||||
const runOut = obj(config.run)
|
||||
if (launcher === "command") runOut.argv = runTarget.split(" ").filter(Boolean)
|
||||
else if (launcher === "python") runOut.program = runTarget
|
||||
config.run = runOut
|
||||
config.run = applyLauncher(obj(config.run), launcher, runTarget)
|
||||
|
||||
const env = merged()
|
||||
if (Object.keys(env).length > 0) config.defaults = { ...obj(config.defaults), env }
|
||||
@@ -67,13 +90,26 @@ export function JobFields({ job, onSave, onDelete }: Props) {
|
||||
placeholder="0 2 * * *"
|
||||
hint="Cron expression — castle generates a systemd timer that runs the job on this schedule."
|
||||
/>
|
||||
<Field label="Runs" hint="The console script or command the job runs on each tick, then exits.">
|
||||
<span className="text-sm font-mono text-[var(--muted)]">{launcherLabel(launcher)} · </span>
|
||||
<input
|
||||
value={runTarget}
|
||||
onChange={(e) => setRunTarget(e.target.value)}
|
||||
className="w-56 bg-black/30 border border-[var(--border)] rounded px-2 py-1 text-xs font-mono focus:outline-none focus:border-[var(--primary)]"
|
||||
/>
|
||||
<Field label="Runs" hint="How the job runs on each tick, then exits: the launcher and its target (a console script, command/argv, image, node script, or compose file).">
|
||||
<div className="flex items-center gap-2">
|
||||
<select
|
||||
value={launcher}
|
||||
onChange={(e) => setLauncher(e.target.value)}
|
||||
className="bg-black/30 border border-[var(--border)] rounded px-2 py-1 text-xs font-mono focus:outline-none focus:border-[var(--primary)]"
|
||||
>
|
||||
{LAUNCHERS.map((l) => (
|
||||
<option key={l} value={l}>
|
||||
{l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="text-[var(--muted)]">·</span>
|
||||
<input
|
||||
value={runTarget}
|
||||
onChange={(e) => setRunTarget(e.target.value)}
|
||||
className="w-56 bg-black/30 border border-[var(--border)] rounded px-2 py-1 text-xs font-mono focus:outline-none focus:border-[var(--primary)]"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
{envEditor}
|
||||
<FormFooter
|
||||
|
||||
Reference in New Issue
Block a user