forked from fahrPool/fahrPool
fix: add reproducible render step for kong.yml and 99-roles.sql templates
generate-secrets.js only printed the four secret env vars; nothing rendered volumes/db/init/99-roles.sql or volumes/api/kong.yml from their committed .template files, so a fresh clone following the brief's own setup steps would hit the auth/rest/storage crash-loops and Kong 401s already diagnosed during the original task. Add scripts/render-templates.js, which reads .env and writes both rendered files with the real secrets substituted in. Document the full sequence (generate secrets -> fill .env -> render templates -> docker compose up) in the header comments of generate-secrets.js and .env.example. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
e0a3e756d8
commit
a8ca6445cb
|
|
@ -3,6 +3,13 @@ POSTGRES_PASSWORD=
|
|||
JWT_SECRET=
|
||||
ANON_KEY=
|
||||
SERVICE_ROLE_KEY=
|
||||
# ANON_KEY hier oben zusaetzlich auch fuer NEXT_PUBLIC_SUPABASE_ANON_KEY unten eintragen.
|
||||
#
|
||||
# Danach WICHTIG: `node scripts/render-templates.js` ausfuehren, bevor
|
||||
# `docker compose up -d` laeuft -- das rendert volumes/db/init/99-roles.sql
|
||||
# und volumes/api/kong.yml aus ihren .template-Vorlagen mit den echten
|
||||
# Werten aus dieser .env. Ohne diesen Schritt crashloopen auth/rest/storage
|
||||
# bzw. Kong liefert 401 auf jede Route.
|
||||
|
||||
POSTGRES_DB=postgres
|
||||
POSTGRES_PORT=5432
|
||||
|
|
|
|||
|
|
@ -1,4 +1,19 @@
|
|||
#!/usr/bin/env node
|
||||
// Voller Setup-Ablauf fuer den self-hosted Produktions-Stack (Task 4):
|
||||
//
|
||||
// 1. node scripts/generate-secrets.js
|
||||
// -> gibt POSTGRES_PASSWORD/JWT_SECRET/ANON_KEY/SERVICE_ROLE_KEY aus
|
||||
// 2. Werte in eine neue .env (Kopie von .env.example) eintragen
|
||||
// (ANON_KEY zusaetzlich auch fuer NEXT_PUBLIC_SUPABASE_ANON_KEY)
|
||||
// 3. node scripts/render-templates.js
|
||||
// -> rendert volumes/db/init/99-roles.sql und volumes/api/kong.yml
|
||||
// aus ihren .template-Vorlagen mit den echten Werten aus .env.
|
||||
// Ohne diesen Schritt fehlen die tatsaechlich gemounteten Dateien
|
||||
// und auth/rest/storage crashloopen bzw. Kong liefert 401 auf
|
||||
// jede Route.
|
||||
// 4. docker compose up -d && docker compose ps
|
||||
//
|
||||
// Schritte 1-2 dieser Datei; Schritt 3 in scripts/render-templates.js.
|
||||
const crypto = require("crypto");
|
||||
|
||||
function base64url(buffer) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env node
|
||||
// Rendert die beiden lokal benoetigten Config-Dateien aus ihren committeten
|
||||
// .template-Vorlagen, mit den echten Secrets aus .env eingesetzt:
|
||||
//
|
||||
// volumes/db/init/99-roles.sql <- volumes/db/init/99-roles.sql.template
|
||||
// volumes/api/kong.yml <- volumes/api/kong.yml.template
|
||||
//
|
||||
// Beide Templates enthalten Platzhalter im Format __VARNAME__. Ohne diesen
|
||||
// Render-Schritt fehlen die tatsaechlich gemounteten Dateien und
|
||||
// auth/rest/storage crashloopen bzw. Kong liefert 401 auf jede Route (siehe
|
||||
// Abweichungen in .superpowers/sdd/task-4-report.md).
|
||||
//
|
||||
// Nutzung (siehe auch Kommentar-Kopf von generate-secrets.js):
|
||||
// node scripts/render-templates.js
|
||||
//
|
||||
// Erwartet eine bereits vorhandene .env (siehe .env.example) mit
|
||||
// POSTGRES_PASSWORD, ANON_KEY, SERVICE_ROLE_KEY.
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
const envPath = path.join(repoRoot, ".env");
|
||||
|
||||
function loadEnv(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.error(
|
||||
`Fehler: ${filePath} nicht gefunden. Erst .env aus .env.example anlegen ` +
|
||||
`(Werte mit "node scripts/generate-secrets.js" erzeugen).`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
const env = {};
|
||||
for (const rawLine of fs.readFileSync(filePath, "utf8").split("\n")) {
|
||||
const line = rawLine.trim();
|
||||
if (!line || line.startsWith("#")) continue;
|
||||
const eq = line.indexOf("=");
|
||||
if (eq === -1) continue;
|
||||
env[line.slice(0, eq).trim()] = line.slice(eq + 1).trim();
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
function renderTemplate(templateRelPath, outputRelPath, replacements) {
|
||||
const templatePath = path.join(repoRoot, templateRelPath);
|
||||
const outputPath = path.join(repoRoot, outputRelPath);
|
||||
let content = fs.readFileSync(templatePath, "utf8");
|
||||
for (const [placeholder, value] of Object.entries(replacements)) {
|
||||
content = content.split(placeholder).join(value);
|
||||
}
|
||||
fs.writeFileSync(outputPath, content);
|
||||
console.log(`Geschrieben: ${outputRelPath} (aus ${templateRelPath})`);
|
||||
}
|
||||
|
||||
const env = loadEnv(envPath);
|
||||
|
||||
for (const key of ["POSTGRES_PASSWORD", "ANON_KEY", "SERVICE_ROLE_KEY"]) {
|
||||
if (!env[key]) {
|
||||
console.error(`Fehler: ${key} fehlt oder ist leer in .env.`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
renderTemplate(
|
||||
path.join("volumes", "db", "init", "99-roles.sql.template"),
|
||||
path.join("volumes", "db", "init", "99-roles.sql"),
|
||||
{ __POSTGRES_PASSWORD__: env.POSTGRES_PASSWORD }
|
||||
);
|
||||
|
||||
renderTemplate(path.join("volumes", "api", "kong.yml.template"), path.join("volumes", "api", "kong.yml"), {
|
||||
__ANON_KEY__: env.ANON_KEY,
|
||||
__SERVICE_ROLE_KEY__: env.SERVICE_ROLE_KEY,
|
||||
});
|
||||
Loading…
Reference in New Issue