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. | |
| 35 | void ensureEnvSiteAdmin().catch(() => {}); | |
| 36 | ||
| 988380a | 37 | // Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never |
| 52ad8b1 | 38 | // throws — safe to run on every start. Block L3 layers extra activity (more |
| 39 | // issues, an open + merged PR on todo-api, AI-review comment, auto-merge | |
| 40 | // audit row) so the live /demo page has content out of the box. | |
| 988380a | 41 | if (process.env.DEMO_SEED_ON_BOOT === "1") { |
| 52ad8b1 | 42 | void (async () => { |
| 43 | try { | |
| 44 | await ensureDemoContent(); | |
| 45 | await ensureDemoActivity(); | |
| 46 | } catch { | |
| 47 | /* never throw out of boot */ | |
| 48 | } | |
| 49 | })(); | |
| 988380a | 50 | } |
| 51 | ||
| fc1817a | 52 | console.log(` |
| 53 | gluecron v0.1.0 | |
| 54 | ────────────────────── | |
| 55 | http://localhost:${config.port} | |
| 56 | repos: ${config.gitReposPath} | |
| 57 | `); | |
| 58 | ||
| f764c07 | 59 | // BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset |
| 60 | // (dev / non-systemd hosts). Fire-and-forget; never throws. | |
| 61 | void notifySystemdReady().catch(() => {}); | |
| 62 | ||
| fc1817a | 63 | export default { |
| 64 | port: config.port, | |
| 65 | fetch: app.fetch, | |
| 66 | }; |