8155ff456b
Containerize the two non-desktop apps for the booth appliance. The desktop app stays on its own tag-only release.yml. - apps/server/Dockerfile: multi-stage node:22-alpine. `pnpm deploy --legacy --prod` (NOT prune — the monorepo native better-sqlite3 won't resolve under a root prune) yields a self-contained bundle; build stage adds node-gyp toolchain, runtime adds libstdc++; non-root, healthcheck. Migrates the mounted DB on boot via a drizzle-kit- free runtime migrator (packages/db/scripts/migrate-runtime.mjs) — drizzle-kit is a devDep, pruned from prod. - apps/server/src/static-spa.ts: Fastify serves the built React SPA (one container serves API + UI). GET-only fallback to index.html, excludes /api + /health so it never shadows the backend; a no-op in dev (no dist). Registered last in server.ts. - apps/vision/Dockerfile: uv base, --extra alpr, model weights PRE-WARMED into the image as the runtime user so fast_alpr boots offline (0 downloads at runtime). Engine env- selected (VISION_RECOGNIZER stub|fast_alpr). - Branch-aware: docker-compose.yml (base) + .dev.yml (build local, stub, ports) + .prod.yml (pull pinned, fast_alpr, vision internal, restart always); REGISTRY/TAG from env so a branch deploy pulls that branch's image. - .gitea/workflows/build-images.yml: on push to dev/main, run the full turbo build+lint+ test gate, then buildx push both images to git.infra.msai.al/mca/parking_solution with branch + branch-<sha> tags (registry cache; optional Komodo webhook behind KOMODO_ENABLED). - .dockerignore excludes **/parking.sqlite* so the signed ledger is NEVER baked. Verified locally (Docker 29): server image migrates + serves API+SPA (/health 200, / + /booth HTML, /api/nope JSON 404, no sqlite outside /data); vision image boots fast_alpr with 0 runtime downloads; compose stack healthy with server→vision over the private network. Wiki: new container-deployment.md; vision-service-packaging open Qs resolved; index + log. Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
41 lines
1.6 KiB
JavaScript
Executable File
41 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Apply Drizzle migrations against the DATABASE_URL sqlite file using the runtime
|
|
// migrator (drizzle-orm/better-sqlite3/migrator) — NOT drizzle-kit. This lets the
|
|
// container run migrations on boot with only runtime deps installed (drizzle-kit is a
|
|
// devDep, pruned out of the production image). Same migration set + folder the test
|
|
// helper uses (packages/db/src/testing.ts), so the schema matches production exactly.
|
|
//
|
|
// Usage: DATABASE_URL=/data/parking.sqlite node scripts/migrate-runtime.mjs
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { mkdirSync } from "node:fs";
|
|
import Database from "better-sqlite3";
|
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
|
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) {
|
|
console.error("[migrate] DATABASE_URL is required");
|
|
process.exit(1);
|
|
}
|
|
|
|
// Migrations folder ships beside this package (packages/db/drizzle); from scripts/ that's ../drizzle.
|
|
const migrationsFolder = resolve(dirname(fileURLToPath(import.meta.url)), "../drizzle");
|
|
|
|
// Ensure the DB's parent dir exists (a fresh mounted volume may be empty).
|
|
try {
|
|
mkdirSync(dirname(resolve(url)), { recursive: true });
|
|
} catch {
|
|
/* dir already exists (or url has no dir) — fine */
|
|
}
|
|
|
|
const sqlite = new Database(url);
|
|
sqlite.pragma("journal_mode = WAL");
|
|
sqlite.pragma("foreign_keys = ON");
|
|
const db = drizzle(sqlite);
|
|
|
|
console.log(`[migrate] applying migrations from ${migrationsFolder} → ${url}`);
|
|
migrate(db, { migrationsFolder });
|
|
sqlite.close();
|
|
console.log("[migrate] done");
|