Der Kunde betreibt die Anwendung auf einem Windows Server mit vorhandenem Node.js und PostgreSQL, ohne Docker. Ausgeliefert wird ein fertiges Paket (npm run paket:windows, rund 8 MB Zip); auf dem Server braucht es weder npm noch einen Build. - scripts/windows-paket.mjs: Standalone-Build plus Migrationen und Betriebsskripte. Loest die Turbopack-Symlinks auf und laesst sharp weg (next/image wird nicht benutzt); bricht ab, sobald eine native Datei oder ein Symlink im Paket landet. - scripts/db-setup.mjs: ersetzt deploy/db-init ausserhalb des Containers -- Datenbank mit ICU de-AT, Anwendungsrolle ohne BYPASSRLS, Erweiterungen, auth-Attrappe. Wiederholbar, liest nur DATABASE_URL und MIGRATE_DATABASE_URL. - deploy/windows/: Installation (Dienst ueber NSSM als LocalService, nur auf 127.0.0.1), Update mit Sicherung vorab, Nachtlauf und Sicherung als geplante Aufgaben, IIS als HTTPS-Proxy, Freischaltung der ersten Person, Anleitung. - engines: Node bis 26. Geprueft: Paket auf dem Mac gebaut, entpackt an einem fremden Pfad unter Linux mit Node 26 gegen PostgreSQL 18 eingerichtet, migriert und gestartet (/login, Logo, CSS, Nachtlauf 401/200). Die PowerShell-Skripte sind nur geparst, auf Windows selbst noch nicht gelaufen.
138 lines
6.4 KiB
JavaScript
138 lines
6.4 KiB
JavaScript
#!/usr/bin/env node
|
|
// Baut das Auslieferungspaket für den Betrieb auf einem Windows-Server ohne
|
|
// Docker (siehe deploy/windows/README.md).
|
|
//
|
|
// npm run paket:windows baut neu und packt
|
|
// npm run paket:windows -- --ohne-build packt den vorhandenen Build
|
|
//
|
|
// Ergebnis: dist/alpenwerk-hr-windows-<datum>-<commit>/ und daneben dieselbe
|
|
// Fassung als .zip. Auf dem Server wird nur Node gebraucht — kein npm, kein
|
|
// Zugang zur Paketquelle, kein Build.
|
|
//
|
|
// ═══ Warum das Paket überall gebaut werden kann ═══
|
|
//
|
|
// Der Standalone-Build enthält nur JavaScript, mit einer Ausnahme: `sharp`,
|
|
// das Next für die Bildoptimierung von next/image mitverfolgt — samt einer
|
|
// Binärdatei für das Betriebssystem, auf dem gebaut wurde. Die Anwendung
|
|
// benutzt next/image nirgends (das Logo ist ein schlichtes <img>), sharp wird
|
|
// also nie geladen und fliegt hier raus. Danach prüft das Skript, dass keine
|
|
// einzige native Datei (*.node) mehr im Paket liegt; sonst bricht es ab.
|
|
//
|
|
// ═══ Symlinks ═══
|
|
//
|
|
// Turbopack legt unter .next/node_modules Verweise wie `pg-<hash>` →
|
|
// ../../node_modules/pg an. Ein Zip-Archiv trägt die unter Windows nicht
|
|
// verlässlich, deshalb werden sie beim Kopieren aufgelöst.
|
|
|
|
import { execFileSync } from "node:child_process";
|
|
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
import { join, relative } from "node:path";
|
|
|
|
const ohneBuild = process.argv.includes("--ohne-build");
|
|
|
|
function lauf(befehl, args) {
|
|
execFileSync(befehl, args, { stdio: "inherit", shell: process.platform === "win32" });
|
|
}
|
|
|
|
if (!ohneBuild) lauf("npm", ["run", "build"]);
|
|
|
|
if (!existsSync(".next/standalone/server.js")) {
|
|
console.error("Kein Standalone-Build gefunden (.next/standalone/server.js). Erst `npm run build`.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const commit = execFileSync("git", ["rev-parse", "--short", "HEAD"], { encoding: "utf8" }).trim();
|
|
const unsauber = execFileSync("git", ["status", "--porcelain"], { encoding: "utf8" }).trim() !== "";
|
|
const datum = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
|
const name = `alpenwerk-hr-windows-${datum}-${commit}${unsauber ? "-lokal" : ""}`;
|
|
const ziel = join("dist", name);
|
|
const app = join(ziel, "app");
|
|
|
|
rmSync(ziel, { recursive: true, force: true });
|
|
rmSync(`${ziel}.zip`, { force: true });
|
|
mkdirSync(app, { recursive: true });
|
|
|
|
// ── Anwendung ─────────────────────────────────────────────────────────
|
|
cpSync(".next/standalone", app, { recursive: true });
|
|
// `dereference` von cpSync wirkt nur auf die Quelle selbst, nicht auf
|
|
// verschachtelte Verweise — deshalb hier von Hand: Verweis weg, Ziel als
|
|
// echtes Verzeichnis an seine Stelle.
|
|
(function aufloesen(verzeichnis) {
|
|
for (const eintrag of readdirSync(verzeichnis)) {
|
|
const pfad = join(verzeichnis, eintrag);
|
|
const info = lstatSync(pfad);
|
|
if (info.isSymbolicLink()) {
|
|
const quelle = realpathSync(join(".next/standalone", relative(app, pfad)));
|
|
rmSync(pfad, { force: true });
|
|
cpSync(quelle, pfad, { recursive: true });
|
|
} else if (info.isDirectory()) {
|
|
aufloesen(pfad);
|
|
}
|
|
}
|
|
})(app);
|
|
cpSync("public", join(app, "public"), { recursive: true });
|
|
cpSync(".next/static", join(app, ".next/static"), { recursive: true });
|
|
|
|
for (const weg of ["node_modules/sharp", "node_modules/@img"]) {
|
|
rmSync(join(app, weg), { recursive: true, force: true });
|
|
}
|
|
// Eine .env gehört nie ins Paket — sie liegt auf dem Server neben der
|
|
// Anwendung, nicht darin.
|
|
for (const datei of readdirSync(app)) {
|
|
if (datei.startsWith(".env")) rmSync(join(app, datei), { force: true });
|
|
}
|
|
|
|
// ── Datenbank-Werkzeuge ───────────────────────────────────────────────
|
|
// Mit denselben relativen Pfaden wie im Repository: beide Skripte lesen
|
|
// db/migrations bzw. deploy/db-init vom Arbeitsverzeichnis aus, und `pg` finden
|
|
// sie in app/node_modules.
|
|
mkdirSync(join(app, "scripts"), { recursive: true });
|
|
cpSync("scripts/migrate.mjs", join(app, "scripts/migrate.mjs"));
|
|
cpSync("scripts/db-setup.mjs", join(app, "scripts/db-setup.mjs"));
|
|
cpSync("db/migrations", join(app, "db/migrations"), { recursive: true });
|
|
mkdirSync(join(app, "deploy/db-init"), { recursive: true });
|
|
cpSync("deploy/db-init/01-auth-attrappe.sql", join(app, "deploy/db-init/01-auth-attrappe.sql"));
|
|
|
|
// ── Betriebsskripte ───────────────────────────────────────────────────
|
|
cpSync("deploy/windows", join(ziel, "windows"), { recursive: true });
|
|
|
|
writeFileSync(
|
|
join(ziel, "VERSION.txt"),
|
|
[
|
|
`Commit: ${commit}${unsauber ? " (mit lokalen, nicht eingecheckten Änderungen)" : ""}`,
|
|
`Gebaut: ${new Date().toISOString()}`,
|
|
`Mit Node: ${process.version}`,
|
|
"",
|
|
].join("\r\n")
|
|
);
|
|
|
|
// ── Prüfungen ─────────────────────────────────────────────────────────
|
|
const fremd = [];
|
|
(function durchsuchen(verzeichnis) {
|
|
for (const eintrag of readdirSync(verzeichnis)) {
|
|
const pfad = join(verzeichnis, eintrag);
|
|
const info = lstatSync(pfad);
|
|
if (info.isSymbolicLink()) fremd.push(`Symlink: ${pfad}`);
|
|
else if (info.isDirectory()) durchsuchen(pfad);
|
|
else if (eintrag.endsWith(".node")) fremd.push(`Native Datei: ${pfad}`);
|
|
}
|
|
})(ziel);
|
|
if (fremd.length > 0) {
|
|
console.error("Das Paket ist nicht plattformunabhängig:\n " + fremd.join("\n "));
|
|
process.exit(1);
|
|
}
|
|
if (!existsSync(join(app, ".next/node_modules")) || !statSync(join(app, "node_modules/pg")).isDirectory()) {
|
|
console.error("pg fehlt im Paket — der Build hat sich verändert, die Annahmen hier stimmen nicht mehr.");
|
|
process.exit(1);
|
|
}
|
|
|
|
// ── Zip ──────────────────────────────────────────────────────────────
|
|
// tar mit -a wählt das Format nach der Endung; bsdtar auf macOS und das tar
|
|
// in Windows 10+ können beide Zip schreiben.
|
|
try {
|
|
execFileSync("tar", ["-a", "-c", "-f", `${name}.zip`, name], { cwd: "dist", stdio: "inherit" });
|
|
console.log(`\nPaket: ${ziel}.zip`);
|
|
} catch {
|
|
console.log(`\nZip konnte nicht erstellt werden; das Verzeichnis ${ziel} ist vollständig.`);
|
|
}
|