mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 00:25:38 -04:00
Docker self-hosting support: - Dockerfile (multi-stage Alpine build with tini init) - docker-compose.yml with named volume for SQLite persistence - /api/health endpoint for container health checks - Auto-migration on startup via drizzle-orm/libsql/migrator - Graceful shutdown (SIGTERM stops scheduler, closes DB) - Next.js standalone output mode for minimal image size Database driver migration (better-sqlite3 → @libsql/client): - Eliminates native C++ compilation, enabling Alpine Docker images - All DB queries converted from sync to async across services and routes - DATABASE_URL now uses libsql file: prefix format - drizzle.config.ts dialect changed to turso for libsql support - Initial migration files generated in drizzle/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1006 B
TypeScript
33 lines
1006 B
TypeScript
export async function onRequestError() {
|
|
// Required by Next.js instrumentation
|
|
}
|
|
|
|
export async function register() {
|
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
// Run database migrations on startup
|
|
if (process.env.NODE_ENV === "production") {
|
|
const { runMigrations } = await import("@/lib/db/migrate");
|
|
await runMigrations();
|
|
|
|
const { initJobs } = await import("@/lib/jobs/init");
|
|
initJobs();
|
|
|
|
// Graceful shutdown — stop jobs and close DB on container stop
|
|
const { scheduler } = await import("@/lib/jobs/scheduler");
|
|
const { client } = await import("@/lib/db/client");
|
|
|
|
const shutdown = () => {
|
|
console.log("[shutdown] Stopping scheduler...");
|
|
scheduler.stop();
|
|
console.log("[shutdown] Closing database...");
|
|
client.close();
|
|
console.log("[shutdown] Clean shutdown complete");
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGTERM", shutdown);
|
|
process.on("SIGINT", shutdown);
|
|
}
|
|
}
|
|
}
|