Blame · Line-by-line history
index.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| fc1817a | 1 | import { mkdir } from "fs/promises"; |
| 2 | import app from "./app"; | |
| 3 | import { config } from "./lib/config"; | |
| eafe8c6 | 4 | import { startWorker } from "./lib/workflow-runner"; |
| 2b821b7 | 5 | import { startAutopilot } from "./lib/autopilot"; |
| 988380a | 6 | import { ensureDemoContent } from "./lib/demo-seed"; |
| 52ad8b1 | 7 | import { ensureDemoActivity } from "./lib/demo-activity-seed"; |
| 2d985e5 | 8 | import { ensureEnvSiteAdmin } from "./lib/admin-bootstrap"; |
| 96942a6 | 9 | import { maybeSelfBootstrap } from "./lib/self-bootstrap"; |
| f764c07 | 10 | import { notifySystemdReady } from "./lib/systemd-notify"; |
| fc1817a | 11 | |
| 12 | // Ensure repos directory exists | |
| 13 | await mkdir(config.gitReposPath, { recursive: true }); | |
| 14 | ||
| 96942a6 | 15 | // Self-bootstrap: if Gluecron's own canonical repo (`ccantynz/Gluecron.com.git` |
| 16 | // by default) doesn't exist on disk yet, initialize it from the GitHub mirror | |
| 17 | // and install the post-receive hook. This is the platform's self-healing path | |
| 18 | // — once it runs successfully on a host, future deploys flow through Gluecron | |
| 19 | // itself with no external CI tooling. Fire-and-forget; never blocks startup. | |
| 20 | void maybeSelfBootstrap().catch((err) => { | |
| 21 | console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`); | |
| 22 | }); | |
| 23 | ||
| eafe8c6 | 24 | // Start the Actions-equivalent workflow worker (Block C1). Polls |
| 25 | // workflow_runs for queued rows and executes them sequentially. | |
| 26 | startWorker(); | |
| 27 | ||
| 2b821b7 | 28 | // Autopilot: periodic mirror sync, merge-queue progress, weekly digests, |
| 29 | // advisory rescans. No-op when AUTOPILOT_DISABLED=1. | |
| 30 | startAutopilot(); | |
| 31 | ||
| 2d985e5 | 32 | // Site-admin bootstrap from env (SITE_ADMIN_USERNAME). Idempotent — if the |
| 33 | // user exists, they get a row in site_admins; if not, logged and retried | |
| 34 | // on next boot. Background-fired so a slow DB doesn't block startup. | |
| a28cede | 35 | void ensureEnvSiteAdmin().catch((err) => { |
| 36 | console.warn( | |
| 37 | "[admin-bootstrap] ensureEnvSiteAdmin failed:", | |
| 38 | err instanceof Error ? err.message : err | |
| 39 | ); | |
| 40 | }); | |
| 2d985e5 | 41 | |
| 988380a | 42 | // Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never |
| 52ad8b1 | 43 | // throws — safe to run on every start. Block L3 layers extra activity (more |
| 44 | // issues, an open + merged PR on todo-api, AI-review comment, auto-merge | |
| 45 | // audit row) so the live /demo page has content out of the box. | |
| 988380a | 46 | if (process.env.DEMO_SEED_ON_BOOT === "1") { |
| 52ad8b1 | 47 | void (async () => { |
| 48 | try { | |
| 49 | await ensureDemoContent(); | |
| 50 | await ensureDemoActivity(); | |
| 51 | } catch { | |
| 52 | /* never throw out of boot */ | |
| 53 | } | |
| 54 | })(); | |
| 988380a | 55 | } |
| 56 | ||
| fc1817a | 57 | console.log(` |
| 58 | gluecron v0.1.0 | |
| 59 | ────────────────────── | |
| 60 | http://localhost:${config.port} | |
| 61 | repos: ${config.gitReposPath} | |
| 62 | `); | |
| 63 | ||
| f764c07 | 64 | // BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset |
| 65 | // (dev / non-systemd hosts). Fire-and-forget; never throws. | |
| a28cede | 66 | void notifySystemdReady().catch((err) => { |
| 67 | console.warn( | |
| 68 | "[systemd] notifySystemdReady failed:", | |
| 69 | err instanceof Error ? err.message : err | |
| 70 | ); | |
| 71 | }); | |
| f764c07 | 72 | |
| fc1817a | 73 | export default { |
| 74 | port: config.port, | |
| 75 | fetch: app.fetch, | |
| 76 | }; |