Initial commit — SvelteKit fleet manager for T5 Plutonium servers
Ports push_scripts.sh (1497 lines of bash) to a SvelteKit + SQLite web app that manages a fleet of T5 Plutonium servers running on Komodo. Same push and beta workflow as the shell script, with a live SSE pipeline view, a !rt-token-gated auth modal that hard-pauses deployments on stale tokens, per-file audit diffs, and a Komodo-container deployment target. - Push/beta engines port the exact filter, held-by-beta, conflict, and stale-backup rules from the shell script - SQLite (better-sqlite3) replaces script_metadata.json; a one-shot importer moves legacy state over on first boot - 16 vitest tests cover push add/update/skip, beta open→rollback, open→promote, conflict guards, sweep frozen/manual branches, and IW4M login/status parsing - docker/ + komodo/stack.toml deploy as a managed container on the same host as the game servers, /root/zombies bind-mounted at the same path the shell script used
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { startAuthStream } from '$ui/stores/auth.js';
|
||||
import { startPipelineStream } from '$ui/stores/pipeline.js';
|
||||
import { startServerStream } from '$ui/stores/servers.js';
|
||||
import TokenModal from '$ui/components/TokenModal.svelte';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
interface Props { children: import('svelte').Snippet }
|
||||
let { children }: Props = $props();
|
||||
|
||||
onMount(() => {
|
||||
startAuthStream();
|
||||
startPipelineStream();
|
||||
startServerStream();
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="shell">
|
||||
<nav>
|
||||
<a href="/" class:on={$page.url.pathname === '/'}>Fleet</a>
|
||||
<a href="/deployments" class:on={$page.url.pathname.startsWith('/deployments')}>Deployments</a>
|
||||
<a href="/betas" class:on={$page.url.pathname.startsWith('/betas')}>Betas</a>
|
||||
<span class="brand">electric-cherry</span>
|
||||
</nav>
|
||||
<main>
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<TokenModal />
|
||||
|
||||
<style>
|
||||
:global(html, body) {
|
||||
margin: 0;
|
||||
background: #0a0a0a;
|
||||
color: #ddd;
|
||||
font-family: system-ui, -apple-system, sans-serif;
|
||||
min-height: 100vh;
|
||||
}
|
||||
:global(*) { box-sizing: border-box; }
|
||||
.shell { min-height: 100vh; }
|
||||
nav {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 10px 20px;
|
||||
border-bottom: 1px solid #222;
|
||||
background: #0f0f0f;
|
||||
align-items: center;
|
||||
}
|
||||
nav a {
|
||||
color: #999;
|
||||
text-decoration: none;
|
||||
padding: 6px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
nav a:hover { color: #ddd; background: #1a1a1a; }
|
||||
nav a.on { color: #ff6060; background: #1a1a1a; }
|
||||
.brand {
|
||||
margin-left: auto;
|
||||
font-family: ui-monospace, monospace;
|
||||
color: #444;
|
||||
font-size: 12px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
|
||||
</style>
|
||||
@@ -0,0 +1,123 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import ServerCard from '$ui/components/ServerCard.svelte';
|
||||
import PipelineTimeline from '$ui/components/PipelineTimeline.svelte';
|
||||
import { statusByServer } from '$ui/stores/servers.js';
|
||||
|
||||
interface HeldRow { target: string; slug: string; }
|
||||
interface ServerRow {
|
||||
name: string;
|
||||
komodo_type: string;
|
||||
komodo_name: string;
|
||||
iw4m_match: string | null;
|
||||
iw4m_value: string | null;
|
||||
last_players: number | null;
|
||||
held: HeldRow[];
|
||||
}
|
||||
|
||||
let servers = $state<ServerRow[]>([]);
|
||||
let pushing = $state(false);
|
||||
let flash = $state<string | null>(null);
|
||||
|
||||
onMount(async () => {
|
||||
const res = await fetch('/api/servers');
|
||||
const body = (await res.json()) as { servers: ServerRow[] };
|
||||
servers = body.servers;
|
||||
});
|
||||
|
||||
async function push(dryRun: boolean) {
|
||||
pushing = true;
|
||||
flash = null;
|
||||
const res = await fetch('/api/push', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patterns: ['*'], dryRun, create: false, delete: false })
|
||||
});
|
||||
pushing = false;
|
||||
const body = (await res.json()) as { totalChangedServers?: number; totalFiles?: number; deploymentId?: string | null };
|
||||
if (!res.ok) {
|
||||
flash = `push failed: HTTP ${res.status}`;
|
||||
return;
|
||||
}
|
||||
flash = dryRun
|
||||
? `dry run: ${body.totalChangedServers ?? 0} servers would change, ${body.totalFiles ?? 0} files`
|
||||
: `pushed to ${body.totalChangedServers ?? 0} servers · ${body.totalFiles ?? 0} files`;
|
||||
}
|
||||
|
||||
function playersFor(name: string): number | null {
|
||||
const s = $statusByServer.get(name);
|
||||
return s?.players ?? null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="grid">
|
||||
<section class="left">
|
||||
<header class="hdr">
|
||||
<h1>Fleet</h1>
|
||||
<div class="actions">
|
||||
<button onclick={() => push(true)} disabled={pushing}>dry run</button>
|
||||
<button class="primary" onclick={() => push(false)} disabled={pushing}>push all</button>
|
||||
</div>
|
||||
</header>
|
||||
{#if flash}<p class="flash">{flash}</p>{/if}
|
||||
{#if servers.length === 0}
|
||||
<p class="empty">no servers registered yet — check SERVERS_ROOT</p>
|
||||
{:else}
|
||||
<div class="cards">
|
||||
{#each servers as s (s.name)}
|
||||
<ServerCard
|
||||
name={s.name}
|
||||
players={playersFor(s.name) ?? s.last_players}
|
||||
held={s.held}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<aside class="right">
|
||||
<PipelineTimeline />
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 380px;
|
||||
gap: 20px;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
.hdr {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
color: #ff6060;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.actions { display: flex; gap: 8px; }
|
||||
button {
|
||||
background: #222;
|
||||
color: #ddd;
|
||||
border: 1px solid #444;
|
||||
border-radius: 4px;
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
button.primary { background: #ff3030; color: #fff; border-color: #ff3030; font-weight: 600; }
|
||||
button:disabled { opacity: 0.5; cursor: default; }
|
||||
.cards {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
}
|
||||
.empty { color: #666; }
|
||||
.flash { color: #aaa; margin: 0 0 12px; font-family: ui-monospace, monospace; font-size: 12px; }
|
||||
</style>
|
||||
@@ -0,0 +1,30 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { loginWithToken } from '$lib/server/integrations/iw4m.js';
|
||||
import { getAuthState, setAuthState } from '$lib/server/integrations/auth-state.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export async function GET() {
|
||||
return json(getAuthState());
|
||||
}
|
||||
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as { token?: string };
|
||||
const token = (body.token ?? '').trim();
|
||||
if (!/^[a-zA-Z0-9]{4}$/.test(token)) {
|
||||
return json({ ok: false, error: 'token must be exactly 4 alphanumeric characters' }, { status: 400 });
|
||||
}
|
||||
const res = await loginWithToken(token);
|
||||
if (!res.ok) {
|
||||
setAuthState({ kind: 'stale', reason: res.reason === 'rejected' ? 'rejected' : 'unreachable' });
|
||||
return json({ ok: false, error: res.message }, { status: res.reason === 'rejected' ? 401 : 502 });
|
||||
}
|
||||
setAuthState({ kind: 'ready', token, cookie: res.cookie, expiresAt: res.expiresAt });
|
||||
// Fresh cookie → immediately drain any queued restarts.
|
||||
void kick();
|
||||
return json({ ok: true, expiresAt: res.expiresAt });
|
||||
}
|
||||
|
||||
export async function DELETE() {
|
||||
setAuthState({ kind: 'missing' });
|
||||
return json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { openBeta, updateBeta, listBetas, listBetaScripts, listBetaServers, BetaError } from '$lib/server/fleet/beta.js';
|
||||
import { stagedFiles, findTargets } from '$lib/server/fleet/files.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export async function GET() {
|
||||
const staged = await stagedFiles();
|
||||
const withHints = await Promise.all(
|
||||
staged.map(async (base) => ({
|
||||
base,
|
||||
hits: await findTargets(base)
|
||||
}))
|
||||
);
|
||||
const betas = listBetas().map((b) => ({
|
||||
...b,
|
||||
servers: listBetaServers(b.slug),
|
||||
scripts: listBetaScripts(b.slug)
|
||||
}));
|
||||
return json({ staged: withHints, betas });
|
||||
}
|
||||
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as {
|
||||
name?: string;
|
||||
patterns?: string[];
|
||||
dryRun?: boolean;
|
||||
create?: boolean;
|
||||
};
|
||||
if (!body.name) return json({ ok: false, error: 'name is required' }, { status: 400 });
|
||||
try {
|
||||
const res = await openBeta({
|
||||
name: body.name,
|
||||
patterns: body.patterns ?? ['*'],
|
||||
dryRun: body.dryRun ?? false,
|
||||
create: body.create ?? false
|
||||
});
|
||||
if (!res.dryRun) void kick();
|
||||
return json({ ok: true, result: res });
|
||||
} catch (err) {
|
||||
if (err instanceof BetaError) {
|
||||
return json({ ok: false, error: err.message, kind: err.kind, details: err.details }, { status: 409 });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH({ request }: { request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as { name?: string; dryRun?: boolean };
|
||||
if (!body.name) return json({ ok: false, error: 'name is required' }, { status: 400 });
|
||||
try {
|
||||
const res = await updateBeta(body.name, body.dryRun ?? false);
|
||||
return json({ ok: true, result: res });
|
||||
} catch (err) {
|
||||
if (err instanceof BetaError) {
|
||||
return json({ ok: false, error: err.message, kind: err.kind, details: err.details }, { status: 409 });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { promoteBeta, BetaError } from '$lib/server/fleet/beta.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export async function POST({ params, request }: { params: { slug: string }; request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as { dryRun?: boolean };
|
||||
try {
|
||||
const res = await promoteBeta(params.slug, body.dryRun ?? false);
|
||||
if (!res.dryRun) void kick();
|
||||
return json({ ok: true, result: res });
|
||||
} catch (err) {
|
||||
if (err instanceof BetaError) {
|
||||
return json({ ok: false, error: err.message, kind: err.kind, details: err.details }, { status: 409 });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { rollbackBeta, BetaError } from '$lib/server/fleet/beta.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export async function POST({ params, request }: { params: { slug: string }; request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as { dryRun?: boolean };
|
||||
try {
|
||||
// callers pass name; slug in URL is the slugified name — either works
|
||||
const res = await rollbackBeta(params.slug, body.dryRun ?? false);
|
||||
if (!res.dryRun) void kick();
|
||||
return json({ ok: true, result: res });
|
||||
} catch (err) {
|
||||
if (err instanceof BetaError) {
|
||||
return json({ ok: false, error: err.message, kind: err.kind, details: err.details }, { status: 409 });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
export async function GET({ url }: { url: URL }) {
|
||||
const activeOnly = url.searchParams.get('active') === 'true';
|
||||
|
||||
const deployments = db()
|
||||
.prepare(
|
||||
`SELECT id, action, started_at, finished_at, triggered_by
|
||||
FROM deployments
|
||||
ORDER BY started_at DESC
|
||||
LIMIT 500`
|
||||
)
|
||||
.all() as Array<{
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
}>;
|
||||
|
||||
const serversByDep = db()
|
||||
.prepare(
|
||||
`SELECT deployment_id, server, files_changed, restart_state, players, checked_at, restarted_at, attempts, error
|
||||
FROM deployment_servers`
|
||||
)
|
||||
.all() as Array<{
|
||||
deployment_id: string;
|
||||
server: string;
|
||||
files_changed: number;
|
||||
restart_state: string;
|
||||
players: number | null;
|
||||
checked_at: string | null;
|
||||
restarted_at: string | null;
|
||||
attempts: number;
|
||||
error: string | null;
|
||||
}>;
|
||||
|
||||
const grouped = new Map<string, typeof serversByDep>();
|
||||
for (const s of serversByDep) {
|
||||
const arr = grouped.get(s.deployment_id) ?? [];
|
||||
arr.push(s);
|
||||
grouped.set(s.deployment_id, arr);
|
||||
}
|
||||
|
||||
const rows = deployments
|
||||
.map((d) => ({ ...d, servers: grouped.get(d.id) ?? [] }))
|
||||
.filter((d) => (activeOnly ? d.servers.some((s) => s.restart_state === 'pending' || s.restart_state === 'failed') : true));
|
||||
|
||||
return json({ deployments: rows });
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
export async function GET({ params }: { params: { id: string } }) {
|
||||
const dep = db()
|
||||
.prepare('SELECT * FROM deployments WHERE id = ?')
|
||||
.get(params.id) as Record<string, unknown> | undefined;
|
||||
if (!dep) throw error(404, 'deployment not found');
|
||||
|
||||
const servers = db()
|
||||
.prepare('SELECT * FROM deployment_servers WHERE deployment_id = ? ORDER BY server')
|
||||
.all(params.id);
|
||||
|
||||
// Don't ship blobs in the summary — the client asks for a single file when
|
||||
// it opens the diff viewer.
|
||||
const files = db()
|
||||
.prepare(
|
||||
`SELECT id, server, verb, rel_path, sha256_before, sha256_after,
|
||||
LENGTH(content_before) AS size_before,
|
||||
LENGTH(content_after) AS size_after
|
||||
FROM deployment_files
|
||||
WHERE deployment_id = ?
|
||||
ORDER BY server, rel_path`
|
||||
)
|
||||
.all(params.id);
|
||||
|
||||
return json({ deployment: dep, servers, files });
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
|
||||
// Streams a single deployment_files row's before/after blobs as UTF-8 text
|
||||
// so the DiffViewer can render a unified diff without a second query.
|
||||
|
||||
export async function GET({ params }: { params: { id: string; fileId: string } }) {
|
||||
const row = db()
|
||||
.prepare(
|
||||
`SELECT verb, rel_path, sha256_before, sha256_after, content_before, content_after
|
||||
FROM deployment_files
|
||||
WHERE deployment_id = ? AND id = ?`
|
||||
)
|
||||
.get(params.id, Number(params.fileId)) as
|
||||
| {
|
||||
verb: string;
|
||||
rel_path: string;
|
||||
sha256_before: string | null;
|
||||
sha256_after: string | null;
|
||||
content_before: Buffer | null;
|
||||
content_after: Buffer | null;
|
||||
}
|
||||
| undefined;
|
||||
if (!row) throw error(404, 'file not found');
|
||||
|
||||
return json({
|
||||
verb: row.verb,
|
||||
relPath: row.rel_path,
|
||||
sha256Before: row.sha256_before,
|
||||
sha256After: row.sha256_after,
|
||||
before: row.content_before ? row.content_before.toString('utf8') : null,
|
||||
after: row.content_after ? row.content_after.toString('utf8') : null
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { subscribe } from '$lib/server/pipeline/bus.js';
|
||||
import { getAuthState } from '$lib/server/integrations/auth-state.js';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const HEARTBEAT_MS = 5_000;
|
||||
|
||||
export async function GET() {
|
||||
let heartbeat: NodeJS.Timeout | null = null;
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
const push = () => {
|
||||
const s = getAuthState();
|
||||
const payload = {
|
||||
type: 'auth-state',
|
||||
state: s,
|
||||
msRemaining: s.kind === 'ready' ? Math.max(0, s.expiresAt - Date.now()) : undefined
|
||||
};
|
||||
controller.enqueue(encoder.encode(`event: auth-state\ndata: ${JSON.stringify(payload)}\n\n`));
|
||||
};
|
||||
|
||||
unsubscribe = subscribe((event) => {
|
||||
if (event.type === 'auth-state') {
|
||||
controller.enqueue(encoder.encode(`event: auth-state\ndata: ${JSON.stringify(event)}\n\n`));
|
||||
}
|
||||
});
|
||||
push();
|
||||
// The auth stream double-serves as the token-countdown feed; the
|
||||
// frontend uses the msRemaining to render a per-second ticker,
|
||||
// so we push every 5s even without a state change.
|
||||
heartbeat = setInterval(push, HEARTBEAT_MS);
|
||||
},
|
||||
cancel() {
|
||||
if (heartbeat) clearInterval(heartbeat);
|
||||
if (unsubscribe) unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
Connection: 'keep-alive'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { subscribe, type PipelineEvent } from '$lib/server/pipeline/bus.js';
|
||||
|
||||
// Multiplexed SSE. Every event with a type field goes out. The client filters
|
||||
// by type (server-state | deployment-opened | sweep-tick | server-changed).
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const HEARTBEAT_MS = 20_000;
|
||||
|
||||
function send(controller: ReadableStreamDefaultController<Uint8Array>, event: PipelineEvent): void {
|
||||
controller.enqueue(encoder.encode(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`));
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
let heartbeat: NodeJS.Timeout | null = null;
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
unsubscribe = subscribe((event) => {
|
||||
if (
|
||||
event.type === 'server-state' ||
|
||||
event.type === 'deployment-opened' ||
|
||||
event.type === 'server-changed' ||
|
||||
event.type === 'sweep-tick'
|
||||
) {
|
||||
send(controller, event);
|
||||
}
|
||||
});
|
||||
controller.enqueue(encoder.encode(': hello\n\n'));
|
||||
heartbeat = setInterval(() => controller.enqueue(encoder.encode(': ping\n\n')), HEARTBEAT_MS);
|
||||
},
|
||||
cancel() {
|
||||
if (heartbeat) clearInterval(heartbeat);
|
||||
if (unsubscribe) unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
Connection: 'keep-alive'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { subscribe } from '$lib/server/pipeline/bus.js';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const HEARTBEAT_MS = 20_000;
|
||||
|
||||
export async function GET() {
|
||||
let heartbeat: NodeJS.Timeout | null = null;
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
unsubscribe = subscribe((event) => {
|
||||
if (event.type === 'server-status') {
|
||||
controller.enqueue(encoder.encode(`event: server-status\ndata: ${JSON.stringify(event)}\n\n`));
|
||||
}
|
||||
});
|
||||
controller.enqueue(encoder.encode(': hello\n\n'));
|
||||
heartbeat = setInterval(() => controller.enqueue(encoder.encode(': ping\n\n')), HEARTBEAT_MS);
|
||||
},
|
||||
cancel() {
|
||||
if (heartbeat) clearInterval(heartbeat);
|
||||
if (unsubscribe) unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
Connection: 'keep-alive'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { doPush } from '$lib/server/fleet/push.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
const body = (await request.json().catch(() => ({}))) as {
|
||||
patterns?: string[];
|
||||
dryRun?: boolean;
|
||||
delete?: boolean;
|
||||
create?: boolean;
|
||||
};
|
||||
const result = await doPush({
|
||||
patterns: body.patterns ?? ['*'],
|
||||
dryRun: body.dryRun ?? false,
|
||||
delete: body.delete ?? false,
|
||||
create: body.create ?? false,
|
||||
triggeredBy: 'ui'
|
||||
});
|
||||
if (result.deploymentId) void kick();
|
||||
return json(result);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { listServers, heldByBeta } from '$lib/server/fleet/servers.js';
|
||||
|
||||
export async function GET() {
|
||||
const servers = listServers().map((s) => ({
|
||||
...s,
|
||||
held: [...heldByBeta(s.name).entries()].map(([target, slug]) => ({ target, slug }))
|
||||
}));
|
||||
return json({ servers });
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import BetaPanel from '$ui/components/BetaPanel.svelte';
|
||||
|
||||
let staged = $state<Array<{ base: string; hits: string[] }>>([]);
|
||||
let betas = $state<Array<{
|
||||
slug: string; name: string; opened_at: string; updated_at: string; revision: number;
|
||||
servers: string[]; scripts: Array<{ staged_as: string; target: string; revision: number }>
|
||||
}>>([]);
|
||||
let loading = $state(true);
|
||||
|
||||
onMount(async () => {
|
||||
const res = await fetch('/api/betas');
|
||||
const body = (await res.json()) as { staged: typeof staged; betas: typeof betas };
|
||||
staged = body.staged;
|
||||
betas = body.betas;
|
||||
loading = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1>Betas</h1>
|
||||
|
||||
{#if loading}
|
||||
<p class="empty">loading…</p>
|
||||
{:else}
|
||||
<BetaPanel {staged} {betas} />
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
h1 { color: #ff6060; margin: 0 0 20px; }
|
||||
.empty { color: #666; }
|
||||
</style>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
interface ServerRow {
|
||||
server: string;
|
||||
restart_state: string;
|
||||
files_changed: number;
|
||||
players: number | null;
|
||||
error: string | null;
|
||||
}
|
||||
interface Deployment {
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
servers: ServerRow[];
|
||||
}
|
||||
|
||||
let deployments = $state<Deployment[]>([]);
|
||||
let loading = $state(true);
|
||||
|
||||
onMount(async () => {
|
||||
const res = await fetch('/api/deployments');
|
||||
const body = (await res.json()) as { deployments: Deployment[] };
|
||||
deployments = body.deployments;
|
||||
loading = false;
|
||||
});
|
||||
|
||||
function isActive(d: Deployment): boolean {
|
||||
return d.servers.some((s) => s.restart_state === 'pending' || s.restart_state === 'failed');
|
||||
}
|
||||
|
||||
function chipColor(state: string): { bg: string; fg: string } {
|
||||
switch (state) {
|
||||
case 'done': return { bg: '#2d4a2d', fg: '#a8e6a8' };
|
||||
case 'failed': return { bg: '#4a2d2d', fg: '#ff8080' };
|
||||
case 'pending': return { bg: '#3a2f00', fg: '#ffcc55' };
|
||||
case 'manual': return { bg: '#333', fg: '#aaa' };
|
||||
default: return { bg: '#222', fg: '#888' };
|
||||
}
|
||||
}
|
||||
|
||||
function ago(iso: string): string {
|
||||
const d = Date.now() - new Date(iso).getTime();
|
||||
if (d < 60_000) return 'just now';
|
||||
if (d < 3_600_000) return `${Math.floor(d / 60_000)}m ago`;
|
||||
if (d < 86_400_000) return `${Math.floor(d / 3_600_000)}h ago`;
|
||||
return `${Math.floor(d / 86_400_000)}d ago`;
|
||||
}
|
||||
|
||||
let active = $derived(deployments.filter(isActive));
|
||||
let history = $derived(deployments.filter((d) => !isActive(d)));
|
||||
</script>
|
||||
|
||||
<h1>Deployments</h1>
|
||||
|
||||
{#if loading}
|
||||
<p class="empty">loading…</p>
|
||||
{:else}
|
||||
<section>
|
||||
<h2>Active</h2>
|
||||
{#if active.length === 0}
|
||||
<p class="empty">nothing active</p>
|
||||
{:else}
|
||||
{#each active as d (d.id)}
|
||||
{@render deployRow(d)}
|
||||
{/each}
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>History (7 days)</h2>
|
||||
{#if history.length === 0}
|
||||
<p class="empty">no completed deployments in the retention window</p>
|
||||
{:else}
|
||||
{#each history as d (d.id)}
|
||||
{@render deployRow(d)}
|
||||
{/each}
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{#snippet deployRow(d: Deployment)}
|
||||
<a class="row" href="/deployments/{d.id}">
|
||||
<div class="head">
|
||||
<span class="action">{d.action}</span>
|
||||
<span class="when">{ago(d.started_at)}</span>
|
||||
</div>
|
||||
<div class="chips">
|
||||
{#each d.servers as s (s.server)}
|
||||
{@const c = chipColor(s.restart_state)}
|
||||
<span class="chip" style="background:{c.bg};color:{c.fg}" title={s.error ?? ''}>
|
||||
{s.server}{s.players !== null && s.players > 0 ? ` (${s.players}p)` : ''}
|
||||
</span>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="id">{d.id}</div>
|
||||
</a>
|
||||
{/snippet}
|
||||
|
||||
<style>
|
||||
h1 { color: #ff6060; margin: 0 0 20px; }
|
||||
h2 {
|
||||
margin: 30px 0 10px;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: #888;
|
||||
}
|
||||
.row {
|
||||
display: block;
|
||||
background: #141414;
|
||||
border: 1px solid #333;
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
margin-bottom: 8px;
|
||||
color: #ddd;
|
||||
text-decoration: none;
|
||||
}
|
||||
.row:hover { border-color: #555; }
|
||||
.head { display: flex; justify-content: space-between; margin-bottom: 8px; }
|
||||
.action { font-family: ui-monospace, monospace; font-size: 13px; }
|
||||
.when { color: #666; font-size: 12px; }
|
||||
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
|
||||
.chip {
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
.id { color: #444; font-family: ui-monospace, monospace; font-size: 11px; }
|
||||
.empty { color: #666; font-size: 13px; }
|
||||
</style>
|
||||
@@ -0,0 +1,203 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import DiffViewer from '$ui/components/DiffViewer.svelte';
|
||||
|
||||
interface FileRow {
|
||||
id: number;
|
||||
server: string;
|
||||
verb: string;
|
||||
rel_path: string;
|
||||
sha256_before: string | null;
|
||||
sha256_after: string | null;
|
||||
size_before: number | null;
|
||||
size_after: number | null;
|
||||
}
|
||||
interface ServerRow {
|
||||
deployment_id: string;
|
||||
server: string;
|
||||
files_changed: number;
|
||||
restart_state: string;
|
||||
players: number | null;
|
||||
checked_at: string | null;
|
||||
restarted_at: string | null;
|
||||
attempts: number;
|
||||
error: string | null;
|
||||
}
|
||||
interface Detail {
|
||||
deployment: {
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
triggered_by: string | null;
|
||||
};
|
||||
servers: ServerRow[];
|
||||
files: FileRow[];
|
||||
}
|
||||
|
||||
let detail = $state<Detail | null>(null);
|
||||
let openFile = $state<{ id: number; before: string | null; after: string | null; verb: string; relPath: string } | null>(null);
|
||||
|
||||
onMount(async () => {
|
||||
const id = $page.params.id;
|
||||
const res = await fetch(`/api/deployments/${id}`);
|
||||
detail = (await res.json()) as Detail;
|
||||
});
|
||||
|
||||
async function loadDiff(f: FileRow) {
|
||||
const res = await fetch(`/api/deployments/${$page.params.id}/file/${f.id}`);
|
||||
const body = (await res.json()) as { before: string | null; after: string | null; verb: string; relPath: string };
|
||||
openFile = { id: f.id, ...body };
|
||||
}
|
||||
|
||||
// Group files by server for the layout
|
||||
let byServer = $derived(() => {
|
||||
if (!detail) return new Map<string, FileRow[]>();
|
||||
const m = new Map<string, FileRow[]>();
|
||||
for (const f of detail.files) {
|
||||
if (!m.has(f.server)) m.set(f.server, []);
|
||||
m.get(f.server)!.push(f);
|
||||
}
|
||||
return m;
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if detail}
|
||||
<h1>{detail.deployment.action}</h1>
|
||||
<p class="meta">
|
||||
started {detail.deployment.started_at}
|
||||
{#if detail.deployment.finished_at} · finished {detail.deployment.finished_at}{/if}
|
||||
· <code>{detail.deployment.id}</code>
|
||||
</p>
|
||||
|
||||
<h2>Servers</h2>
|
||||
<div class="server-grid">
|
||||
{#each detail.servers as s (s.server)}
|
||||
<div class="srv srv-{s.restart_state}">
|
||||
<div class="name">{s.server}</div>
|
||||
<div class="line">state: {s.restart_state}</div>
|
||||
{#if s.players !== null}<div class="line">players: {s.players}</div>{/if}
|
||||
{#if s.error}<div class="line err">{s.error}</div>{/if}
|
||||
{#if s.restarted_at}<div class="line dim">restarted {s.restarted_at}</div>{/if}
|
||||
<div class="line dim">attempts: {s.attempts}</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<h2>Files</h2>
|
||||
{#each [...byServer().entries()] as [srv, files] (srv)}
|
||||
<div class="file-group">
|
||||
<h3>{srv}</h3>
|
||||
{#each files as f (f.id)}
|
||||
<button class="file-row" onclick={() => loadDiff(f)}>
|
||||
<span class="verb verb-{f.verb}">{f.verb}</span>
|
||||
<code>{f.rel_path}</code>
|
||||
<span class="sizes">
|
||||
{#if f.size_before !== null}{f.size_before}b{/if}
|
||||
{#if f.size_before !== null && f.size_after !== null} → {/if}
|
||||
{#if f.size_after !== null}{f.size_after}b{/if}
|
||||
</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if openFile}
|
||||
<div class="diff-scrim" onclick={() => (openFile = null)} onkeydown={(e) => { if (e.key === 'Escape') openFile = null; }} role="button" tabindex="-1">
|
||||
<div class="diff-modal" onclick={(e) => e.stopPropagation()} role="none">
|
||||
<button class="close" onclick={() => (openFile = null)}>close</button>
|
||||
<DiffViewer before={openFile.before} after={openFile.after} verb={openFile.verb} relPath={openFile.relPath} />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<p class="empty">loading…</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
h1 { color: #ff6060; margin: 0 0 4px; font-family: ui-monospace, monospace; font-size: 18px; }
|
||||
h2 {
|
||||
margin: 24px 0 8px;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: #888;
|
||||
}
|
||||
h3 { margin: 12px 0 4px; font-size: 13px; color: #ddd; font-family: ui-monospace, monospace; }
|
||||
.meta { color: #666; font-size: 12px; margin: 0 0 20px; font-family: ui-monospace, monospace; }
|
||||
.server-grid {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
}
|
||||
.srv {
|
||||
background: #141414;
|
||||
border: 1px solid #333;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
}
|
||||
.srv-done { border-color: #2d4a2d; }
|
||||
.srv-failed { border-color: #4a2d2d; }
|
||||
.srv-pending { border-color: #3a2f00; }
|
||||
.name { font-weight: 600; margin-bottom: 4px; }
|
||||
.line { font-size: 12px; color: #bbb; }
|
||||
.line.dim { color: #666; }
|
||||
.line.err { color: #ff6060; }
|
||||
.file-group { margin-bottom: 12px; }
|
||||
.file-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
background: #141414;
|
||||
border: 1px solid #2a2a2a;
|
||||
border-radius: 3px;
|
||||
padding: 4px 8px;
|
||||
margin: 2px 0;
|
||||
color: #ddd;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
.file-row:hover { border-color: #444; }
|
||||
.verb {
|
||||
padding: 1px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
.verb-added { background: #2d4a2d; color: #a8e6a8; }
|
||||
.verb-updated { background: #2d3a4a; color: #a8c8e6; }
|
||||
.verb-removed { background: #4a2d2d; color: #ff8080; }
|
||||
.verb-held { background: #3a2f00; color: #ffcc55; }
|
||||
.sizes { margin-left: auto; color: #666; font-size: 11px; font-family: ui-monospace, monospace; }
|
||||
code { font-family: ui-monospace, monospace; color: #ddd; }
|
||||
.empty { color: #666; }
|
||||
.diff-scrim {
|
||||
position: fixed; inset: 0;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
z-index: 100;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.diff-modal {
|
||||
max-width: 1000px;
|
||||
width: 92%;
|
||||
max-height: 92vh;
|
||||
overflow: auto;
|
||||
background: #0a0a0a;
|
||||
border: 1px solid #444;
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
}
|
||||
.close {
|
||||
float: right;
|
||||
background: #222;
|
||||
color: #ddd;
|
||||
border: 1px solid #444;
|
||||
border-radius: 3px;
|
||||
padding: 4px 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,125 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { statusByServer } from '$ui/stores/servers.js';
|
||||
|
||||
interface Server {
|
||||
name: string;
|
||||
komodo_type: string;
|
||||
komodo_name: string;
|
||||
komodo_server: string | null;
|
||||
iw4m_match: string | null;
|
||||
iw4m_value: string | null;
|
||||
last_players: number | null;
|
||||
last_checked_at: string | null;
|
||||
held: Array<{ target: string; slug: string }>;
|
||||
}
|
||||
interface DeploymentRow {
|
||||
id: string;
|
||||
action: string;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
servers: Array<{ server: string; restart_state: string; players: number | null; error: string | null; files_changed: number }>;
|
||||
}
|
||||
|
||||
let server = $state<Server | null>(null);
|
||||
let history = $state<DeploymentRow[]>([]);
|
||||
let name = $derived($page.params.name ?? '');
|
||||
|
||||
onMount(async () => {
|
||||
const [srvRes, depRes] = await Promise.all([fetch('/api/servers'), fetch('/api/deployments')]);
|
||||
const srvBody = (await srvRes.json()) as { servers: Server[] };
|
||||
const depBody = (await depRes.json()) as { deployments: DeploymentRow[] };
|
||||
server = srvBody.servers.find((s) => s.name === name) ?? null;
|
||||
history = depBody.deployments.filter((d) => d.servers.some((s) => s.server === name));
|
||||
});
|
||||
|
||||
let live = $derived($statusByServer.get(name)?.players);
|
||||
</script>
|
||||
|
||||
{#if server}
|
||||
<h1>{server.name}</h1>
|
||||
<div class="stats">
|
||||
<div class="stat">
|
||||
<div class="k">players</div>
|
||||
<div class="v">{live ?? server.last_players ?? '—'}</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="k">komodo</div>
|
||||
<div class="v">{server.komodo_type} · {server.komodo_name}</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="k">iw4m</div>
|
||||
<div class="v">{server.iw4m_match ?? '—'} · {server.iw4m_value ?? '—'}</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="k">held by beta</div>
|
||||
<div class="v">{server.held.length === 0 ? '—' : server.held.map((h) => h.target).join(', ')}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Deployment history</h2>
|
||||
{#if history.length === 0}
|
||||
<p class="empty">no deployments recorded on this server</p>
|
||||
{:else}
|
||||
{#each history as d (d.id)}
|
||||
{@const mine = d.servers.find((s) => s.server === name)!}
|
||||
<a class="row row-{mine.restart_state}" href="/deployments/{d.id}">
|
||||
<span class="a">{d.action}</span>
|
||||
<span class="s">{mine.restart_state}{mine.players !== null && mine.players > 0 ? ` (${mine.players}p)` : ''}</span>
|
||||
<span class="f">{mine.files_changed} file{mine.files_changed === 1 ? '' : 's'}</span>
|
||||
<span class="w">{d.started_at}</span>
|
||||
{#if mine.error}<span class="err">{mine.error}</span>{/if}
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
{:else}
|
||||
<p class="empty">loading…</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
h1 { color: #ff6060; margin: 0 0 20px; }
|
||||
h2 {
|
||||
margin: 30px 0 10px;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: #888;
|
||||
}
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.stat {
|
||||
background: #141414;
|
||||
border: 1px solid #333;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
}
|
||||
.k { color: #666; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
|
||||
.v { color: #ddd; font-family: ui-monospace, monospace; margin-top: 4px; }
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 160px 100px 220px 1fr;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: #141414;
|
||||
border: 1px solid #2a2a2a;
|
||||
border-radius: 4px;
|
||||
margin: 4px 0;
|
||||
color: #ddd;
|
||||
text-decoration: none;
|
||||
font-size: 12px;
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
.row-done { border-left: 3px solid #2d4a2d; }
|
||||
.row-failed { border-left: 3px solid #4a2d2d; }
|
||||
.row-pending { border-left: 3px solid #3a2f00; }
|
||||
.a { color: #ddd; }
|
||||
.s { color: #aaa; }
|
||||
.f { color: #888; }
|
||||
.w { color: #666; }
|
||||
.err { color: #ff6060; }
|
||||
.empty { color: #666; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user