Infra: split dev and production (releases, services, deploy script)

- Production now runs from ~/freezmo-prod/current (release symlink) as a
  standalone server on :3207; releases are exported by scripts/deploy.sh,
  built and e2e-verified on a temp port, switched atomically, health-
  checked via the new /api/healthz (commit + build time) and rolled back
  automatically on failure. Last 5 releases kept; scripts/rollback.sh for
  manual rollback. Shared env + data live in ~/freezmo-prod/shared/ and
  are symlinked into every release (existing sync/push data migrated and
  verified identical).
- Dev runs from ~/freezmo via freezmo-dev.service: next dev on :3217
  (LAN only), its own build folder (.next-dev via NEXT_DIST_DIR), its own
  data (~/freezmo/.freezmo-dev), DEV badge, dev favicon/theme colour,
  "Freezmo Dev" PWA identity and never the production service worker.
- /api/healthz + the Settings Details version row (short commit + build
  time). output: standalone in next.config (next start still works).
- AGENTS.md documents the workflow rules: only dev updates during a task,
  temporary dirs/ports for test builds, and deploy-at-the-end as the only
  production path. README gains an Environments and deploy section.
- Fix found by the rehearsal: lib/dev-mode.ts must not be a client module
  (a server component importing a constant from a "use client" module
  gets a truthy proxy, which baked dev metadata into production builds).
- SW -> freezmo-v34.
This commit is contained in:
Martin Dvořák 2026-10-11 19:25:29 +00:00
commit 3f52ab47c2
22 changed files with 665 additions and 35 deletions

37
app/api/healthz/route.ts Normal file
View file

@ -0,0 +1,37 @@
import { readFileSync } from "node:fs";
import path from "node:path";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
/**
* Deploy health check: reports which release is running. The deploy script
* writes `release.json` next to the server (in the standalone root) and polls
* this route after switching `current`; a mismatch or an unreachable server
* triggers the automatic rollback.
*
* In a dev checkout there is no release.json — the route answers with the
* commit baked into the environment, or "dev".
*/
export async function GET() {
let release: { commit?: string; short?: string; builtAt?: string; release?: string } | null = null;
try {
release = JSON.parse(readFileSync(path.join(process.cwd(), "release.json"), "utf8"));
} catch {
release = null;
}
const commit = release?.commit ?? process.env.FREEZMO_COMMIT ?? "dev";
return Response.json(
{
ok: true,
commit,
short: release?.short ?? commit.slice(0, 7),
builtAt: release?.builtAt ?? null,
release: release?.release ?? null,
dev: commit === "dev",
uptimeSeconds: Math.round(process.uptime()),
},
{ headers: { "Cache-Control": "no-store" } },
);
}

View file

@ -5,6 +5,9 @@ import { InstallSheet } from "@/components/InstallSheet";
import { OfflineBanner } from "@/components/OfflineBanner";
import { ServiceWorkerRegistrar } from "@/components/ServiceWorkerRegistrar";
import { Toaster } from "@/components/Toaster";
import { IS_DEV_INSTANCE } from "@/lib/dev-mode";
const devInstanceJs = IS_DEV_INSTANCE ? "true" : "false";
import "./globals.css";
export const metadata: Metadata = {
@ -33,7 +36,12 @@ export const metadata: Metadata = {
{ url: "/icons/splash-1668x2388.png", media: "(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2)" },
],
},
icons: {
icons: IS_DEV_INSTANCE
? {
// Dev wears its own favicon so the two instances are never confused.
icon: [{ url: "/icons/dev-favicon.svg", type: "image/svg+xml" }],
}
: {
icon: [
// ?v=2 busts browser favicon caches after the icon redesign.
{ url: "/icons/favicon-32.png?v=2", sizes: "32x32", type: "image/png" },
@ -62,10 +70,12 @@ export const viewport: Viewport = {
// font-size rule in globals.css stops iOS Safari's focus auto-zoom, which
// ignores the viewport meta anyway.
viewportFit: "cover",
themeColor: [
{ media: "(prefers-color-scheme: light)", color: "#f4f7fd" },
{ media: "(prefers-color-scheme: dark)", color: "#0e1424" },
],
themeColor: IS_DEV_INSTANCE
? [{ media: "(prefers-color-scheme: light)", color: "#b45309" }, { media: "(prefers-color-scheme: dark)", color: "#b45309" }]
: [
{ media: "(prefers-color-scheme: light)", color: "#f4f7fd" },
{ media: "(prefers-color-scheme: dark)", color: "#0e1424" },
],
};
/**
@ -73,7 +83,7 @@ export const viewport: Viewport = {
* `theme-color` meta in step with the *app* theme (the SSR metas follow the
* OS preference, which is wrong once the user has picked a theme here).
*/
const themeScript = `(function(){try{var s=localStorage.getItem('freezmo.theme');var d=s?s==='dark':window.matchMedia('(prefers-color-scheme: dark)').matches;if(d)document.documentElement.classList.add('dark');var l=localStorage.getItem('freezmo.locale.v1');if(l==='cs'||l==='en')document.documentElement.lang=l;var m=document.querySelector('meta[name="theme-color"][data-app]');if(!m){m=document.createElement('meta');m.setAttribute('name','theme-color');m.setAttribute('data-app','1');document.head.insertBefore(m,document.head.firstChild);}m.setAttribute('content',d?'#0e1424':'#f4f7fd');}catch(e){}})();`;
const themeScript = `(function(){try{var DEV=${devInstanceJs};var s=localStorage.getItem('freezmo.theme');var d=s?s==='dark':window.matchMedia('(prefers-color-scheme: dark)').matches;if(d)document.documentElement.classList.add('dark');var l=localStorage.getItem('freezmo.locale.v1');if(l==='cs'||l==='en')document.documentElement.lang=l;var m=document.querySelector('meta[name="theme-color"][data-app]');if(!m){m=document.createElement('meta');m.setAttribute('name','theme-color');m.setAttribute('data-app','1');document.head.insertBefore(m,document.head.firstChild);}m.setAttribute('content',DEV?'#b45309':(d?'#0e1424':'#f4f7fd'));}catch(e){}})();`;
/**
* Captures Chrome's `beforeinstallprompt` (it can fire before React hydrates)

View file

@ -4,7 +4,35 @@ import type { MetadataRoute } from "next";
* Web app manifest — what makes Freezmo installable on iOS/Android
* (iOS reads the apple-* meta tags in app/layout.tsx as well).
*/
const devInstance = process.env.NEXT_PUBLIC_FREEZMO_DEV === "1";
export default function manifest(): MetadataRoute.Manifest {
if (devInstance) {
return {
// A distinct identity so the dev PWA installs next to the real one.
id: "/dev",
name: "Freezmo Dev — notes to study feed",
short_name: "Freezmo Dev",
description: "Development instance of Freezmo (hot reload). Not the production app.",
start_url: "/",
scope: "/",
display: "standalone",
display_override: ["standalone", "minimal-ui"],
orientation: "portrait",
background_color: "#1c1917",
theme_color: "#b45309",
categories: ["education", "productivity"],
icons: [
{ src: "/icons/dev-icon.svg", sizes: "any", type: "image/svg+xml", purpose: "any" },
{ src: "/icons/icon-512.png", sizes: "512x512", type: "image/png", purpose: "any" },
],
shortcuts: [
{ name: "New deck", short_name: "New", url: "/create" },
{ name: "Library", short_name: "Library", url: "/" },
],
};
}
return {
id: "/",
name: "Freezmo — notes to study feed",