From 9962642325ecb157b24fdff0afbca8f487e66ac6 Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:48:08 +0000 Subject: [PATCH 01/11] feat: eID-programma zelf bouwen uit @dafkedd/eid (npm run build:exe) --- package-lock.json | 28 +++++++++ package.json | 5 +- scripts/build-exe.d.mts | 4 ++ scripts/build-exe.mjs | 125 ++++++++++++++++++++++++++++++++++++++++ tests/build-exe.test.ts | 22 +++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 scripts/build-exe.d.mts create mode 100644 scripts/build-exe.mjs create mode 100644 tests/build-exe.test.ts diff --git a/package-lock.json b/package-lock.json index a887aad..51fdd8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@types/node": "^22.0.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", + "esbuild": "^0.28.2", + "postject": "^1.0.0-alpha.6", "typescript": "^5.9.0", "vitest": "^3.2.7" }, @@ -2257,6 +2259,16 @@ "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==", "license": "MIT" }, + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/csstype": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.4.tgz", @@ -2603,6 +2615,22 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/postject": { + "version": "1.0.0-alpha.6", + "resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.6.tgz", + "integrity": "sha512-b9Eb8h2eVqNE8edvKdwqkrY6O7kAwmI8kcnBv1NScolYJbo59XUF0noFq+lxbC1yN20bmC0WBEbDC5H/7ASb0A==", + "dev": true, + "license": "MIT", + "dependencies": { + "commander": "^9.4.0" + }, + "bin": { + "postject": "dist/cli.js" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/react": { "version": "19.3.1", "resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz", diff --git a/package.json b/package.json index 9465757..2104a66 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "build:installer": "node scripts/build-installer.mjs", "version:patch": "node scripts/bump-version.mjs patch", "version:minor": "node scripts/bump-version.mjs minor", - "version:major": "node scripts/bump-version.mjs major" + "version:major": "node scripts/bump-version.mjs major", + "build:exe": "node scripts/build-exe.mjs" }, "dependencies": { "@dafkedd/eid": "file:vendor/dafkedd-eid-0.2.0.tgz", @@ -33,6 +34,8 @@ "@types/node": "^22.0.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", + "esbuild": "^0.28.2", + "postject": "^1.0.0-alpha.6", "typescript": "^5.9.0", "vitest": "^3.2.7" }, diff --git a/scripts/build-exe.d.mts b/scripts/build-exe.d.mts new file mode 100644 index 0000000..ee8ad55 --- /dev/null +++ b/scripts/build-exe.d.mts @@ -0,0 +1,4 @@ +import type { InstallerConfig } from "./build-installer.mjs"; +export function embeddedSettings(config: InstallerConfig): { origins: string[]; authOrigins?: string[]; testpage?: false }; +export function exeFileName(platform?: string, arch?: string): string; +export function buildExe(options?: { outDir?: string }): Promise<{ exe: string; version: string; sha256: string }>; diff --git a/scripts/build-exe.mjs b/scripts/build-exe.mjs new file mode 100644 index 0000000..b4f2e74 --- /dev/null +++ b/scripts/build-exe.mjs @@ -0,0 +1,125 @@ +#!/usr/bin/env node +/** + * Bouwt het eID-programma (dafke-eid) als zelfstandig programma (Node "single executable + * application") uit het meegeleverde pakket @dafkedd/eid, met de websites van ProjectX ingebakken. + * De gebruiker hoeft geen Node te hebben. Gebaseerd op scripts/build-exe.mjs van DafkeDD_EID. + * + * node scripts/build-exe.mjs [--out ] → /dafke-eid--[.exe] (standaard build/installer) + * + * Instellingen: installer/eid-installer.json (zelfde controles als build-installer.mjs). + * Gebouwd met de Node die dit script draait: bouw de Windows-.exe op Windows, met Node 22 of 24. + */ +import { execFileSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { createRequire } from "node:module"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; +import { parseArgs } from "node:util"; + +const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const SEA_FUSE = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"; + +/** Wat in het programma gebakken wordt. Nooit een token: dat is niet geheim in een download. */ +export function embeddedSettings(config) { + const embedded = { origins: config.origins }; + if (config.authOrigins.length) embedded.authOrigins = config.authOrigins; + if (!config.testpage) embedded.testpage = false; + return embedded; +} + +/** Naam van het programma voor dit platform, zoals in DafkeDD_EID. */ +export function exeFileName(platform = process.platform, arch = process.arch) { + const os = platform === "win32" ? "windows" : platform === "darwin" ? "macos" : platform; + return `dafke-eid-${os}-${arch}${platform === "win32" ? ".exe" : ""}`; +} + +/** Map van een pakket, ook als het package.json niet exporteert. */ +function packageDir(file, name) { + let dir = dirname(file); + while (!existsSync(join(dir, "package.json")) || JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).name !== name) { + const parent = dirname(dir); + if (parent === dir) throw new Error(`${name} niet gevonden`); + dir = parent; + } + return dir; +} + +function tryRun(command, args) { + try { + execFileSync(command, args, { stdio: "ignore" }); + return true; + } catch { + return false; + } +} + +export async function buildExe({ outDir = join(ROOT, "build", "installer") } = {}) { + const { readInstallerConfig } = await import("./build-installer.mjs"); + const { build } = await import("esbuild"); + const config = readInstallerConfig(JSON.parse(readFileSync(join(ROOT, "installer", "eid-installer.json"), "utf8"))); + const require = createRequire(join(ROOT, "package.json")); + const pkgDir = dirname(require.resolve("@dafkedd/eid/package.json")); + const version = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf8")).version; + const koffiDir = packageDir(require.resolve("koffi", { paths: [pkgDir] }), "koffi"); + const koffiRequire = createRequire(join(koffiDir, "package.json")); + const { platform, arch } = process; + const addon = join(dirname(koffiRequire.resolve(`@koromix/koffi-${platform}-${arch}/package.json`)), `${platform}_${arch}`, "koffi.node"); + if (!existsSync(addon)) throw new Error(`koffi.node niet gevonden op ${addon}`); + + const work = join(ROOT, "build", "sea", `${platform}-${arch}`); + const exe = join(outDir, exeFileName()); + rmSync(work, { recursive: true, force: true }); + mkdirSync(work, { recursive: true }); + mkdirSync(outDir, { recursive: true }); + + console.log(`▸ Bundelen: dafke-eid ${version} voor ${platform}-${arch}`); + const bundle = join(work, "dafke-eid.cjs"); + await build({ + entryPoints: [join(pkgDir, "dist", "cli.js")], + outfile: bundle, + bundle: true, + platform: "node", + format: "cjs", + target: "node22", + external: ["@koromix/*"], + alias: { koffi: join(koffiDir, "index.cjs") }, + define: { __DAFKEDD_EID_EMBEDDED__: JSON.stringify(JSON.stringify(embeddedSettings(config))) }, + legalComments: "none", + logLevel: "warning", + }); + + console.log("▸ SEA-blob maken"); + const blob = join(work, "sea-prep.blob"); + const seaConfig = join(work, "sea-config.json"); + writeFileSync( + seaConfig, + JSON.stringify({ main: bundle, output: blob, disableExperimentalSEAWarning: true, useSnapshot: false, useCodeCache: false, assets: { "koffi.node": addon } }), + ); + execFileSync(process.execPath, ["--experimental-sea-config", seaConfig], { stdio: "inherit" }); + + console.log(`▸ Programma maken: ${exe}`); + rmSync(exe, { force: true }); + copyFileSync(process.execPath, exe); + if (platform === "win32") tryRun("signtool", ["remove", "/s", exe]); + else if (platform === "darwin") tryRun("codesign", ["--remove-signature", exe]); + const postject = require.resolve("postject/dist/cli.js"); + const args = [postject, exe, "NODE_SEA_BLOB", blob, "--sentinel-fuse", SEA_FUSE]; + if (platform === "darwin") args.push("--macho-segment-name", "NODE_SEA"); + execFileSync(process.execPath, args, { stdio: "inherit" }); + if (platform === "darwin") execFileSync("codesign", ["--sign", "-", "--force", exe], { stdio: "inherit" }); + + const reported = execFileSync(exe, ["--version"], { encoding: "utf8" }).trim(); + if (reported !== version) throw new Error(`Programma meldt versie "${reported}", verwacht "${version}"`); + const hash = createHash("sha256").update(readFileSync(exe)).digest("hex"); + console.log(`✓ ${exe} (${(statSync(exe).size / 1024 / 1024).toFixed(1)} MB), ingebakken: ${config.origins.join(", ")}`); + return { exe, version, sha256: hash }; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { + const { values } = parseArgs({ options: { out: { type: "string" } } }); + buildExe(values.out ? { outDir: resolve(values.out) } : {}).catch((error) => { + console.error(error instanceof Error ? error.message : error); + process.exit(1); + }); +} diff --git a/tests/build-exe.test.ts b/tests/build-exe.test.ts new file mode 100644 index 0000000..2886cb1 --- /dev/null +++ b/tests/build-exe.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from "vitest"; +import { embeddedSettings, exeFileName } from "../scripts/build-exe.mjs"; +import { readInstallerConfig } from "../scripts/build-installer.mjs"; + +describe("embeddedSettings", () => { + it("bakt alleen origins in als de rest standaard is", () => { + expect(embeddedSettings(readInstallerConfig({ origins: ["https://a.be"] }))).toEqual({ origins: ["https://a.be"] }); + }); + it("neemt authOrigins en testpage mee, nooit een token", () => { + const settings = embeddedSettings(readInstallerConfig({ origins: ["https://a.be"], authOrigins: ["https://sso.a.be"], testpage: false })); + expect(settings).toEqual({ origins: ["https://a.be"], authOrigins: ["https://sso.a.be"], testpage: false }); + expect(JSON.stringify(settings)).not.toMatch(/token/i); + }); +}); + +describe("exeFileName", () => { + it("volgt de namen van DafkeDD_EID", () => { + expect(exeFileName("win32", "x64")).toBe("dafke-eid-windows-x64.exe"); + expect(exeFileName("darwin", "arm64")).toBe("dafke-eid-macos-arm64"); + expect(exeFileName("linux", "x64")).toBe("dafke-eid-linux-x64"); + }); +}); From 81c9f47a7016d8e834933f4529f6473bd11c92e4 Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:48:08 +0000 Subject: [PATCH 02/11] feat: Windows-setup bouwen zonder de DafkeDD_EID-repo --- installer/dafke-eid.iss | 151 ++++++++++++++++++++++++++++++++++ scripts/build-installer.d.mts | 11 +-- scripts/build-installer.mjs | 83 +++++++------------ tests/build-installer.test.ts | 56 ++++++------- 4 files changed, 211 insertions(+), 90 deletions(-) create mode 100644 installer/dafke-eid.iss diff --git a/installer/dafke-eid.iss b/installer/dafke-eid.iss new file mode 100644 index 0000000..cbb41fc --- /dev/null +++ b/installer/dafke-eid.iss @@ -0,0 +1,151 @@ +; Windows-setup voor het eID-programma van ProjectX (Inno Setup 6.3+). +; Overgenomen uit DafkeDD_EID (installer/dafke-eid.iss), zodat ProjectX-eID de setup zelf kan bouwen +; (lokaal en in de release-workflow). Wijzigingen daar ook hier overnemen. +; +; Bouwen: npm run build:installer (bouwt eerst het programma met scripts/build-exe.mjs) +; +; Installeert per gebruiker, zonder administratorrechten, in %LOCALAPPDATA%\DafkeDD\eid. Daarna roept de +; setup `dafke-eid install --from-setup` aan voor autostart, snelkoppeling en config.json. +; De AppId is dezelfde als in DafkeDD_EID: het is hetzelfde programma, een nieuwere setup werkt het bij. +; +; Stil installeren (IT): +; projectx-eid-setup.exe /VERYSILENT /ORIGINS=https://app.x.be /AUTHORIGINS=https://sso.x.be +; optioneel: /TOKEN=geheim /PORT=47820 /NOTESTPAGE +; Stil verwijderen: "%LOCALAPPDATA%\DafkeDD\eid\unins000.exe" /VERYSILENT + +#ifndef AppVersion + #define AppVersion "0.0.0" +#endif +#ifndef SourceExe + #define SourceExe "..\build\installer\dafke-eid-windows-x64.exe" +#endif +#ifndef OutputDir + #define OutputDir "..\public\downloads" +#endif + +[Setup] +; Nooit wijzigen: hieraan herkent Windows een update van dezelfde app. +AppId={{318FA63C-09B5-4C3B-A80A-0A742BE1826B} +AppName=DafkeDD eID +AppVersion={#AppVersion} +AppVerName=DafkeDD eID {#AppVersion} +AppPublisher=DafkeDD +AppPublisherURL=https://github.com/DafkeDD/DafkeDD_EID +AppSupportURL=https://github.com/DafkeDD/DafkeDD_EID/blob/main/docs/installeren.md +VersionInfoVersion={#AppVersion} +VersionInfoProductName=DafkeDD eID +PrivilegesRequired=lowest +DefaultDirName={localappdata}\DafkeDD\eid +DisableDirPage=yes +UsePreviousAppDir=no +DisableProgramGroupPage=yes +DisableWelcomePage=yes +DisableReadyPage=yes +ArchitecturesAllowed=x64compatible +ArchitecturesInstallIn64BitMode=x64compatible +MinVersion=10.0 +WizardStyle=modern +Compression=lzma2/max +SolidCompression=yes +OutputDir={#OutputDir} +OutputBaseFilename=projectx-eid-setup +UninstallDisplayName=DafkeDD eID +UninstallDisplayIcon={app}\dafke-eid.exe +; Het draaiende programma stoppen we zelf (PrepareToInstall), zonder Restart Manager-vraag. +CloseApplications=no +RestartApplications=no +; Geen logbestand standaard: de opdrachtregel (met /TOKEN) zou erin komen. Debuggen: /LOG="pad". +SetupLogging=no +ShowLanguageDialog=auto + +[Languages] +Name: "nl"; MessagesFile: "compiler:Languages\Dutch.isl" +Name: "en"; MessagesFile: "compiler:Default.isl" +Name: "fr"; MessagesFile: "compiler:Languages\French.isl" +Name: "de"; MessagesFile: "compiler:Languages\German.isl" + +[CustomMessages] +nl.Starting=DafkeDD eID starten... +en.Starting=Starting DafkeDD eID... +fr.Starting=Démarrage de DafkeDD eID... +de.Starting=DafkeDD eID wird gestartet... +nl.OpenTestPage=Testpagina openen +en.OpenTestPage=Open the test page +fr.OpenTestPage=Ouvrir la page de test +de.OpenTestPage=Testseite öffnen +nl.NotRunning=DafkeDD eID is geïnstalleerd, maar start (nog) niet. Open later de snelkoppeling "DafkeDD eID testen" of kijk in %1. +en.NotRunning=DafkeDD eID is installed but does not respond (yet). Open the "DafkeDD eID testen" shortcut later or check %1. +fr.NotRunning=DafkeDD eID est installé mais ne répond pas (encore). Ouvrez plus tard le raccourci « DafkeDD eID testen » ou consultez %1. +de.NotRunning=DafkeDD eID ist installiert, antwortet aber (noch) nicht. Öffnen Sie später die Verknüpfung „DafkeDD eID testen“ oder prüfen Sie %1. + +[Files] +Source: "{#SourceExe}"; DestDir: "{app}"; DestName: "dafke-eid.exe"; Flags: ignoreversion + +[Run] +Filename: "{app}\dafke-eid.exe"; Parameters: "test"; Description: "{cm:OpenTestPage}"; Flags: postinstall skipifsilent runhidden nowait + +[UninstallRun] +; Stopt het programma en haalt autostart en snelkoppeling weg; de bestanden verwijdert de setup. +Filename: "{app}\dafke-eid.exe"; Parameters: "uninstall --keep-files --silent"; Flags: runhidden waituntilterminated; RunOnceId: "DafkeEidUninstall" + +[UninstallDelete] +; config.json, logbestand en starter zijn door het programma zelf gemaakt. +Type: filesandordirs; Name: "{app}" + +[Code] +function HasSwitch(const Name: String): Boolean; +var + I: Integer; +begin + Result := False; + for I := 1 to ParamCount do + if CompareText(ParamStr(I), '/' + Name) = 0 then + Result := True; +end; + +function OptionArg(const Param, Flag: String): String; +var + Value: String; +begin + Value := ExpandConstant('{param:' + Param + '|}'); + if Value <> '' then + Result := ' ' + Flag + ' ' + AddQuotes(Value) + else + Result := ''; +end; + +{ Instellingen van de opdrachtregel doorgeven aan `dafke-eid install` (bewaard in config.json). } +function InstallArgs: String; +begin + Result := 'install --from-setup --silent' + + OptionArg('ORIGINS', '--origin') + + OptionArg('AUTHORIGINS', '--auth-origin') + + OptionArg('TOKEN', '--token') + + OptionArg('PORT', '--port'); + if HasSwitch('NOTESTPAGE') then + Result := Result + ' --no-testpage'; +end; + +{ Een draaiend programma houdt dafke-eid.exe vast: eerst stoppen (alleen processen van deze gebruiker). } +function PrepareToInstall(var NeedsRestart: Boolean): String; +var + ResultCode: Integer; +begin + Exec(ExpandConstant('{sys}\taskkill.exe'), '/F /IM dafke-eid.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + Result := ''; +end; + +procedure CurStepChanged(CurStep: TSetupStep); +var + ResultCode: Integer; +begin + if CurStep = ssPostInstall then + begin + WizardForm.StatusLabel.Caption := CustomMessage('Starting'); + if not Exec(ExpandConstant('{app}\dafke-eid.exe'), InstallArgs, ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ResultCode) then + ResultCode := -1; + Log(Format('dafke-eid install: code %d', [ResultCode])); + if (ResultCode <> 0) and not WizardSilent then + MsgBox(FmtMessage(CustomMessage('NotRunning'), [ExpandConstant('{app}\dafke-eid.log')]), mbInformation, MB_OK); + end; +end; diff --git a/scripts/build-installer.d.mts b/scripts/build-installer.d.mts index dce2ac6..1bc6b57 100644 --- a/scripts/build-installer.d.mts +++ b/scripts/build-installer.d.mts @@ -4,13 +4,8 @@ export interface InstallerConfig { testpage: boolean; setupName: string; } -export interface InstallerStep { - command: string; - args: string[]; - cwd: string; -} export function readInstallerConfig(raw: unknown): InstallerConfig; -export function installerSteps( +export function setupCommand( config: InstallerConfig, - paths: { eidRepo: string; outDir: string; workDir: string; iscc?: string; node?: string }, -): { version: string; exe: string; setup: string; steps: InstallerStep[] }; + options: { version: string; exe: string; outDir: string; iscc?: string; script?: string }, +): { command: string; args: string[]; setup: string }; diff --git a/scripts/build-installer.mjs b/scripts/build-installer.mjs index f662ff4..8d0720e 100644 --- a/scripts/build-installer.mjs +++ b/scripts/build-installer.mjs @@ -3,14 +3,12 @@ * Bouwt de Windows-setup van het eID-programma (dafke-eid) met de websites van ProjectX ingebakken. * Eindgebruikers dubbelklikken de setup: geen admin nodig, start automatisch bij aanmelden. * - * npm run build:installer → public/downloads/projectx-eid-setup.exe - * npm run build:installer -- --dry-run → toont alleen de stappen + * npm run build:installer → public/downloads/projectx-eid-setup.exe (+ .sha256) + * npm run build:installer -- --out → setup in een andere map * - * Vereist (alleen op Windows): - * - een kopie van de DafkeDD_EID-repo met `npm install` gedaan; pad via DAFKE_EID_REPO - * of --eid-repo (standaard ../DafkeDD_EID) - * - Node 22 of 24 - * - Inno Setup 6.3+ (winget install JRSoftware.InnoSetup), of het pad naar ISCC.exe in ISCC + * Alles zit in deze repo: het programma komt uit het pakket @dafkedd/eid (scripts/build-exe.mjs), + * de setup uit installer/dafke-eid.iss. Vereist (alleen op Windows): Node 22 of 24 en Inno Setup 6.3+ + * (winget install JRSoftware.InnoSetup), of het pad naar ISCC.exe in ISCC. * * Instellingen: installer/eid-installer.json. Er wordt bewust GEEN token ingebakken: iedereen die * de setup downloadt, kan het eruit halen. @@ -52,27 +50,12 @@ export function readInstallerConfig(raw) { return { origins, authOrigins, testpage: raw.testpage !== false, setupName }; } -/** De commando's om programma en setup te bouwen (zonder ze uit te voeren). */ -export function installerSteps(config, { eidRepo, outDir, workDir, iscc = "ISCC.exe", node = "node" }) { - const exeArgs = [join(eidRepo, "scripts", "build-exe.mjs")]; - for (const origin of config.origins) exeArgs.push("--origin", origin); - for (const origin of config.authOrigins) exeArgs.push("--auth-origin", origin); - if (!config.testpage) exeArgs.push("--no-testpage"); - exeArgs.push("--out", workDir); - const version = JSON.parse(readFileSync(join(eidRepo, "packages", "eid", "package.json"), "utf8")).version; - const exe = join(workDir, "dafke-eid-windows-x64.exe"); +/** Het ISCC-commando dat de setup bouwt rond het programma `exe`. */ +export function setupCommand(config, { version, exe, outDir, iscc = "ISCC.exe", script = join(ROOT, "installer", "dafke-eid.iss") }) { return { - version, - exe, + command: iscc, + args: [`/DAppVersion=${version}`, `/DSourceExe=${exe}`, `/DOutputDir=${outDir}`, `/F${config.setupName}`, "/Q", script], setup: join(outDir, `${config.setupName}.exe`), - steps: [ - { command: node, args: exeArgs, cwd: eidRepo }, - { - command: iscc, - args: [`/DAppVersion=${version}`, `/DSourceExe=${exe}`, `/DOutputDir=${outDir}`, `/F${config.setupName}`, "/Q", join(eidRepo, "installer", "dafke-eid.iss")], - cwd: eidRepo, - }, - ], }; } @@ -86,40 +69,32 @@ function findIscc() { return candidates.find((path) => existsSync(path)); } -function main() { - const { values } = parseArgs({ options: { "eid-repo": { type: "string" }, "dry-run": { type: "boolean" } } }); - const eidRepo = resolve(values["eid-repo"] ?? process.env.DAFKE_EID_REPO ?? join(ROOT, "..", "DafkeDD_EID")); - if (!existsSync(join(eidRepo, "scripts", "build-exe.mjs"))) { - console.error(`DafkeDD_EID-repo niet gevonden in ${eidRepo}.\nGeef het pad mee: DAFKE_EID_REPO= of --eid-repo .`); - process.exit(1); - } +async function main() { + const { values } = parseArgs({ options: { out: { type: "string" } } }); + const outDir = resolve(values.out ?? join(ROOT, "public", "downloads")); const config = readInstallerConfig(JSON.parse(readFileSync(join(ROOT, "installer", "eid-installer.json"), "utf8"))); - const dryRun = values["dry-run"] ?? false; - if (!dryRun && process.platform !== "win32") { - console.error("De setup kan alleen op Windows gebouwd worden (Inno Setup). Gebruik --dry-run om de stappen te zien."); + if (process.platform !== "win32") { + console.error("De setup kan alleen op Windows gebouwd worden (Inno Setup). Het programma alleen: node scripts/build-exe.mjs"); process.exit(1); } - const iscc = dryRun ? "ISCC.exe" : findIscc(); + const iscc = findIscc(); if (!iscc) { console.error("Inno Setup (ISCC.exe) niet gevonden. Installeer het met: winget install JRSoftware.InnoSetup\nof zet het pad in de omgevingsvariabele ISCC."); process.exit(1); } - const plan = installerSteps(config, { - eidRepo, - outDir: join(ROOT, "public", "downloads"), - workDir: join(ROOT, "build", "installer"), - iscc, - node: process.execPath, - }); - console.log(`▸ dafke-eid ${plan.version}, toegelaten: ${config.origins.join(", ")}`); - for (const step of plan.steps) { - console.log(`▸ ${[step.command, ...step.args].join(" ")}`); - if (!dryRun) execFileSync(step.command, step.args, { cwd: step.cwd, stdio: "inherit" }); - } - if (dryRun) return; - const hash = createHash("sha256").update(readFileSync(plan.setup)).digest("hex"); - writeFileSync(`${plan.setup}.sha256`, `${hash} ${config.setupName}.exe\n`); - console.log(`✓ ${plan.setup}\n sha256 ${hash}`); + const { buildExe } = await import("./build-exe.mjs"); + const { exe, version } = await buildExe(); + const step = setupCommand(config, { version, exe, outDir, iscc }); + console.log(`▸ Setup bouwen: ${[step.command, ...step.args].join(" ")}`); + execFileSync(step.command, step.args, { stdio: "inherit" }); + const hash = createHash("sha256").update(readFileSync(step.setup)).digest("hex"); + writeFileSync(`${step.setup}.sha256`, `${hash} ${config.setupName}.exe\n`); + console.log(`✓ ${step.setup}\n sha256 ${hash}`); } -if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) main(); +if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { + main().catch((error) => { + console.error(error instanceof Error ? error.message : error); + process.exit(1); + }); +} diff --git a/tests/build-installer.test.ts b/tests/build-installer.test.ts index 65ce2f2..0887c7a 100644 --- a/tests/build-installer.test.ts +++ b/tests/build-installer.test.ts @@ -1,9 +1,7 @@ import { readFileSync } from "node:fs"; -import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs"; -import { tmpdir } from "node:os"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; -import { installerSteps, readInstallerConfig } from "../scripts/build-installer.mjs"; +import { readInstallerConfig, setupCommand } from "../scripts/build-installer.mjs"; const base = { origins: ["https://projectx.voorbeeld.be"] }; @@ -43,33 +41,35 @@ describe("readInstallerConfig", () => { }); }); -describe("installerSteps", () => { - const repo = mkdtempSync(join(tmpdir(), "eid-repo-")); - mkdirSync(join(repo, "packages", "eid"), { recursive: true }); - writeFileSync(join(repo, "packages", "eid", "package.json"), JSON.stringify({ version: "9.8.7" })); - - it("bakt origins in het programma en geeft de setup een eigen naam", () => { - const config = readInstallerConfig({ origins: ["https://a.be", "https://b.be"], authOrigins: ["https://sso.a.be"], testpage: false }); - const plan = installerSteps(config, { eidRepo: repo, outDir: "/uit", workDir: "/werk", iscc: "iscc", node: "node" }); - expect(plan.version).toBe("9.8.7"); - const [exe, setup] = plan.steps; - expect(exe!.args).toEqual([ - join(repo, "scripts", "build-exe.mjs"), - "--origin", "https://a.be", - "--origin", "https://b.be", - "--auth-origin", "https://sso.a.be", - "--no-testpage", - "--out", "/werk", +describe("setupCommand", () => { + it("geeft versie, programma, uitvoermap en setupnaam door aan Inno Setup", () => { + const config = readInstallerConfig({ origins: ["https://a.be"] }); + const step = setupCommand(config, { version: "9.8.7", exe: "/werk/dafke-eid-windows-x64.exe", outDir: "/uit", iscc: "iscc" }); + expect(step.command).toBe("iscc"); + expect(step.args).toEqual([ + "/DAppVersion=9.8.7", + "/DSourceExe=/werk/dafke-eid-windows-x64.exe", + "/DOutputDir=/uit", + "/Fprojectx-eid-setup", + "/Q", + expect.stringMatching(/installer[\\/]dafke-eid\.iss$/), ]); - expect(setup!.command).toBe("iscc"); - expect(setup!.args).toContain("/DAppVersion=9.8.7"); - expect(setup!.args).toContain("/Fprojectx-eid-setup"); - expect(setup!.args).toContain(`/DSourceExe=${join("/werk", "dafke-eid-windows-x64.exe")}`); - expect(plan.setup).toBe(join("/uit", "projectx-eid-setup.exe")); + expect(step.setup).toBe(join("/uit", "projectx-eid-setup.exe")); + expect(step.args.join(" ")).not.toMatch(/token/i); }); +}); - it("geeft nooit een token door", () => { - const plan = installerSteps(readInstallerConfig(base), { eidRepo: repo, outDir: "/uit", workDir: "/werk" }); - expect(plan.steps.flatMap((s) => s.args).join(" ")).not.toMatch(/token/i); +describe("eigen Inno Setup-script", () => { + const iss = readFileSync(new URL("../installer/dafke-eid.iss", import.meta.url)); + const text = iss.toString("utf8"); + it("is UTF-8 met BOM (nodig voor Inno Setup)", () => { + expect([...iss.subarray(0, 3)]).toEqual([0xef, 0xbb, 0xbf]); + }); + it("houdt de AppId van DafkeDD_EID (zelfde programma)", () => { + expect(text).toContain("AppId={{318FA63C-09B5-4C3B-A80A-0A742BE1826B}"); + }); + it("bouwt projectx-eid-setup uit build/installer", () => { + expect(text).toContain("OutputBaseFilename=projectx-eid-setup"); + expect(text).toContain("build\\installer\\dafke-eid-windows-x64.exe"); }); }); From 46283f1fb3be4b5a3501f9f3270ed0be9c4e508f Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:48:08 +0000 Subject: [PATCH 03/11] ci: Windows-setup bouwen en testen, en aan de release hangen --- .github/workflows/ci.yml | 49 +++++++++++++++++++++++++++++++--- .github/workflows/release.yml | 12 +++++++-- tests/release-workflow.test.ts | 7 +++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f6b08b..a7efae2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,15 +38,58 @@ jobs: - run: npm test - run: npm run build + setup: + name: setup (Windows) + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + - name: Inno Setup klaarzetten + shell: pwsh + run: | + $iscc = @("${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe", "$env:ProgramFiles\Inno Setup 6\ISCC.exe") | Where-Object { Test-Path $_ } | Select-Object -First 1 + if (-not $iscc) { + choco install innosetup -y --no-progress + $iscc = @("${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe", "$env:ProgramFiles\Inno Setup 6\ISCC.exe") | Where-Object { Test-Path $_ } | Select-Object -First 1 + } + if (-not $iscc) { throw "ISCC.exe niet gevonden" } + "ISCC=$iscc" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 + - run: npm run build:installer + - name: Setup testen (stil installeren, starten, verwijderen) + shell: pwsh + run: | + $setup = "public\downloads\projectx-eid-setup.exe" + Start-Process -FilePath $setup -ArgumentList "/VERYSILENT","/SUPPRESSMSGBOXES","/NORESTART" -Wait + $exe = "$env:LOCALAPPDATA\DafkeDD\eid\dafke-eid.exe" + if (-not (Test-Path $exe)) { throw "Niet geïnstalleerd: $exe ontbreekt" } + $version = & $exe --version + Write-Host "Geïnstalleerd: dafke-eid $version" + & $exe read --mock + if ($LASTEXITCODE -ne 0) { throw "dafke-eid read --mock mislukt" } + Start-Process -FilePath "$env:LOCALAPPDATA\DafkeDD\eid\unins000.exe" -ArgumentList "/VERYSILENT","/SUPPRESSMSGBOXES" -Wait + Start-Sleep -Seconds 3 + if (Test-Path $exe) { throw "Na verwijderen staat $exe er nog" } + - uses: actions/upload-artifact@v4 + with: + name: windows-setup + path: | + public/downloads/projectx-eid-setup.exe + public/downloads/projectx-eid-setup.exe.sha256 + if-no-files-found: error + # Eén vaste naam om als vereiste check voor main in te stellen. ci-check: name: CI-check if: always() - needs: [check] + needs: [check, setup] runs-on: ubuntu-latest steps: - run: | - if [ "${{ needs.check.result }}" != "success" ]; then - echo "check: ${{ needs.check.result }}" + echo "check: ${{ needs.check.result }}, setup: ${{ needs.setup.result }}" + if [ "${{ needs.check.result }}" != "success" ] || [ "${{ needs.setup.result }}" != "success" ]; then exit 1 fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92dd60b..d40c3b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ name: Release # 1. ci alle tests (ci.yml) # 2. qa uitrollen naar QA (environment "qa") # 3. acc uitrollen naar acceptatie (environment "acc") -# 4. release tag v + GitHub-release (environment "production") +# 4. release tag v + GitHub-release met de Windows-setup (environment "production") # Met "Required reviewers" op een environment wacht die stap op een knop "Approve" in het tabblad Actions. # Bestaat tag v al, dan wordt er geen release gemaakt: verhoog eerst de versie (npm run version:patch). @@ -87,13 +87,21 @@ jobs: name="projectx-eid-${{ steps.version.outputs.version }}" git archive --format=zip --prefix="$name/" -o "$name.zip" HEAD sha256sum "$name.zip" > "$name.zip.sha256" + - name: Windows-setup ophalen (uit de CI-stap) + if: steps.version.outputs.exists == 'false' + uses: actions/download-artifact@v4 + with: + name: windows-setup + path: setup - name: Release maken if: steps.version.outputs.exists == 'false' env: GH_TOKEN: ${{ github.token }} run: | v="${{ steps.version.outputs.version }}" - gh release create "v$v" "projectx-eid-$v.zip" "projectx-eid-$v.zip.sha256" \ + cp setup/projectx-eid-setup.exe "projectx-eid-setup-$v.exe" + (cd setup && sha256sum projectx-eid-setup.exe | sed "s/projectx-eid-setup.exe/projectx-eid-setup-$v.exe/") > "projectx-eid-setup-$v.exe.sha256" + gh release create "v$v" "projectx-eid-setup-$v.exe" "projectx-eid-setup-$v.exe.sha256" "projectx-eid-$v.zip" "projectx-eid-$v.zip.sha256" \ --target "$GITHUB_SHA" \ --title "ProjectX eID $v" \ --generate-notes diff --git a/tests/release-workflow.test.ts b/tests/release-workflow.test.ts index c152928..92dc570 100644 --- a/tests/release-workflow.test.ts +++ b/tests/release-workflow.test.ts @@ -13,6 +13,13 @@ describe("release-workflow", () => { expect(release).toMatch(/release:[\s\S]*needs: acc[\s\S]*environment: production/); expect(ci).toContain("workflow_call:"); }); + it("hangt de Windows-setup uit CI aan de release", () => { + expect(ci).toMatch(/setup:[\s\S]*runs-on: windows-latest[\s\S]*npm run build:installer/); + expect(ci).toContain("name: windows-setup"); + expect(ci).toContain("needs: [check, setup]"); + expect(release).toContain("name: windows-setup"); + expect(release).toMatch(/gh release create[^\n]*projectx-eid-setup-\$v\.exe/); + }); it("maakt geen release als de tag al bestaat", () => { expect(release).toContain("steps.version.outputs.exists == 'false'"); }); From 9be59227b8ec771fe868e5e07eb073647974c581 Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:48:08 +0000 Subject: [PATCH 04/11] docs: setup zit in elke release en wordt in CI gebouwd (NL + EN) --- README.md | 16 +++++++++++----- README.nl.md | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ba64d6f..32e9648 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,9 @@ or run `npm run eid:bridge:mock` for a virtual reader through the real bridge. | `lib/eid-client.ts` | Picks the real bridge or the virtual card (`?mock=1`) | | `lib/eid-view.ts` | Turns card data into what the page shows, with masking | | `installer/eid-installer.json` | Websites baked into the setup | +| `scripts/build-exe.mjs` | Builds the eID program (`npm run build:exe`) | | `scripts/build-installer.mjs` | Builds the Windows setup (`npm run build:installer`) | +| `installer/dafke-eid.iss` | Inno Setup script (taken from DafkeDD_EID) | | `tests/` | Vitest tests with the virtual card | | `vendor/` | The `@dafkedd/eid` package as a `.tgz`, until it is published | @@ -58,17 +60,21 @@ the user signs in to Windows. 1. Put ProjectX's production address in `installer/eid-installer.json` (`origins`, and `authOrigins` if you use PIN login). -2. Once: `winget install JRSoftware.InnoSetup`, and `npm install` in your DafkeDD_EID repo. +2. Once: `winget install JRSoftware.InnoSetup`. 3. Build (on Windows, Node 22 or 24): ```powershell - $env:DAFKE_EID_REPO = "C:\path\to\DafkeDD_EID" npm run build:installer ``` +Everything is in this repo: the program is built from the bundled `@dafkedd/eid` package +(`npm run build:exe`, works on any platform) and the setup from `installer/dafke-eid.iss`. +You usually don't need to build the setup yourself: CI builds and tests it on Windows for every PR, +and every GitHub release contains `projectx-eid-setup-.exe`. + Result: `public/downloads/projectx-eid-setup.exe` (+ `.sha256`). The app automatically shows an "eID-programma installeren" button when the program is not running, pointing to this file (other -address: `NEXT_PUBLIC_EID_SETUP_URL`). `npm run build:installer -- --dry-run` shows the steps without building. +address: `NEXT_PUBLIC_EID_SETUP_URL`). IT can deploy the setup silently: `projectx-eid-setup.exe /VERYSILENT /SUPPRESSMSGBOXES` (see `docs/uitrollen.md` in DafkeDD_EID, in Dutch, for Intune and extra parameters). @@ -114,10 +120,10 @@ like in Azure DevOps: | Step | Environment | What | | --- | --- | --- | -| CI | — | Typecheck, tests and build on Linux and Windows | +| CI | — | Typecheck, tests and build on Linux and Windows; build and test the Windows setup | | QA | `qa` | Build for QA (deployment still to be filled in) | | ACC | `acc` | Build for acceptance (deployment still to be filled in) | -| Release | `production` | Tag `v` + GitHub release with zip and sha256 | +| Release | `production` | Tag `v` + GitHub release with the Windows setup, zip and sha256 | Making a release: diff --git a/README.nl.md b/README.nl.md index c80d439..cf52100 100644 --- a/README.nl.md +++ b/README.nl.md @@ -46,7 +46,9 @@ of start `npm run eid:bridge:mock` voor een virtuele lezer via de echte bridge. | `lib/eid-client.ts` | Kiest echte bridge of virtuele kaart (`?mock=1`) | | `lib/eid-view.ts` | Zet kaartgegevens om naar wat de pagina toont, met afscherming | | `installer/eid-installer.json` | Websites die in de setup worden ingebakken | +| `scripts/build-exe.mjs` | Bouwt het eID-programma (`npm run build:exe`) | | `scripts/build-installer.mjs` | Bouwt de Windows-setup (`npm run build:installer`) | +| `installer/dafke-eid.iss` | Inno Setup-script (overgenomen uit DafkeDD_EID) | | `tests/` | Vitest-tests met de virtuele kaart | | `vendor/` | Het pakket `@dafkedd/eid` als `.tgz`, tot het gepubliceerd is | @@ -58,17 +60,21 @@ start daarna automatisch bij het aanmelden in Windows. 1. Zet het adres van ProjectX in productie in `installer/eid-installer.json` (`origins`, en `authOrigins` als je aanmelden met PIN gebruikt). -2. Eenmalig: `winget install JRSoftware.InnoSetup`, en `npm install` in je DafkeDD_EID-repo. +2. Eenmalig: `winget install JRSoftware.InnoSetup`. 3. Bouwen (op Windows, Node 22 of 24): ```powershell - $env:DAFKE_EID_REPO = "C:\pad\naar\DafkeDD_EID" npm run build:installer ``` +Alles zit in deze repo: het programma wordt gebouwd uit het meegeleverde pakket `@dafkedd/eid` +(`npm run build:exe`, werkt op elk platform) en de setup uit `installer/dafke-eid.iss`. +Je hoeft de setup meestal niet zelf te bouwen: CI bouwt en test hem op Windows bij elke PR, en +elke release op GitHub bevat `projectx-eid-setup-.exe`. + Resultaat: `public/downloads/projectx-eid-setup.exe` (+ `.sha256`). De app toont automatisch de knop "eID-programma installeren" als het programma niet draait, en die wijst naar dit bestand (ander adres: -`NEXT_PUBLIC_EID_SETUP_URL`). Met `npm run build:installer -- --dry-run` zie je de stappen zonder te bouwen. +`NEXT_PUBLIC_EID_SETUP_URL`). IT kan de setup stil uitrollen: `projectx-eid-setup.exe /VERYSILENT /SUPPRESSMSGBOXES` (zie `docs/uitrollen.md` in DafkeDD_EID voor Intune en extra parameters). @@ -115,10 +121,10 @@ draaien alleen de tests (`ci.yml`). Alleen een push naar `release` start de rele | Stap | Environment | Wat | | --- | --- | --- | -| CI | — | Typecheck, tests en build op Linux en Windows | +| CI | — | Typecheck, tests en build op Linux en Windows; Windows-setup bouwen en testen | | QA | `qa` | Build voor QA (uitrollen nog in te vullen) | | ACC | `acc` | Build voor acceptatie (uitrollen nog in te vullen) | -| Release | `production` | Tag `v` + GitHub-release met zip en sha256 | +| Release | `production` | Tag `v` + GitHub-release met de Windows-setup, zip en sha256 | Een release maken: From 1752ed7cdb099eb6513e22f008ee17e7f5c51f0f Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:48:09 +0000 Subject: [PATCH 05/11] chore: versie 0.1.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 51fdd8a..476c2c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "projectx-eid", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "projectx-eid", - "version": "0.1.0", + "version": "0.1.1", "dependencies": { "@dafkedd/eid": "file:vendor/dafkedd-eid-0.2.0.tgz", "next": "^16.0.0", diff --git a/package.json b/package.json index 2104a66..dc6ba8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "projectx-eid", "private": true, - "version": "0.1.0", + "version": "0.1.1", "description": "ProjectX-eID: Belgische eID inlezen in een Next.js-app met @dafkedd/eid", "type": "module", "scripts": { From 09e21235be85595aada5c4eb262461c2ea39571a Mon Sep 17 00:00:00 2001 From: DafkeDD <78157379+DafkeDD@users.noreply.github.com> Date: Thu, 3 Dec 2026 03:49:27 +0000 Subject: [PATCH 06/11] fix(ci): setup-test hing op Start-Process -Wait, wacht nu alleen op de setup zelf en heeft tijdslimieten --- .github/workflows/ci.yml | 30 +++++++++++++++++++++++------- tests/release-workflow.test.ts | 6 ++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7efae2..62746d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: check: name: check (${{ matrix.os }}, Node ${{ matrix.node }}) runs-on: ${{ matrix.os }} + timeout-minutes: 15 strategy: fail-fast: false matrix: @@ -41,6 +42,7 @@ jobs: setup: name: setup (Windows) runs-on: windows-latest + timeout-minutes: 20 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -60,19 +62,33 @@ jobs: "ISCC=$iscc" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 - run: npm run build:installer - name: Setup testen (stil installeren, starten, verwijderen) + timeout-minutes: 10 shell: pwsh run: | - $setup = "public\downloads\projectx-eid-setup.exe" - Start-Process -FilePath $setup -ArgumentList "/VERYSILENT","/SUPPRESSMSGBOXES","/NORESTART" -Wait - $exe = "$env:LOCALAPPDATA\DafkeDD\eid\dafke-eid.exe" + $ErrorActionPreference = "Stop" + $setup = (Resolve-Path "public\downloads\projectx-eid-setup.exe").Path + $dir = "$env:LOCALAPPDATA\DafkeDD\eid" + $exe = "$dir\dafke-eid.exe" + # Niet Start-Process -Wait: dat wacht ook op alle kindprocessen, en de bridge blijft draaien. + function RunAndWait([string]$file, [string[]]$arguments, [string]$what) { + $p = Start-Process $file -ArgumentList $arguments -PassThru + if (-not $p.WaitForExit(180000)) { throw "$what hangt" } + if ($p.ExitCode -ne 0) { throw "$what gaf code $($p.ExitCode)" } + } + function Status { try { (Invoke-RestMethod http://127.0.0.1:47820/v1/status -Headers @{ Origin = "http://localhost:3000" } -TimeoutSec 2).name } catch { $null } } + + RunAndWait $setup @("/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART") "setup" if (-not (Test-Path $exe)) { throw "Niet geïnstalleerd: $exe ontbreekt" } - $version = & $exe --version - Write-Host "Geïnstalleerd: dafke-eid $version" + Write-Host "Geïnstalleerd: dafke-eid $(& $exe --version)" + for ($i = 0; $i -lt 30 -and (Status) -ne "dafke-eid"; $i++) { Start-Sleep 1 } + if ((Status) -ne "dafke-eid") { throw "het programma draait niet na installeren" } & $exe read --mock if ($LASTEXITCODE -ne 0) { throw "dafke-eid read --mock mislukt" } - Start-Process -FilePath "$env:LOCALAPPDATA\DafkeDD\eid\unins000.exe" -ArgumentList "/VERYSILENT","/SUPPRESSMSGBOXES" -Wait - Start-Sleep -Seconds 3 + + RunAndWait "$dir\unins000.exe" @("/VERYSILENT", "/SUPPRESSMSGBOXES") "verwijderen" + for ($i = 0; $i -lt 30 -and (Test-Path $exe); $i++) { Start-Sleep 1 } if (Test-Path $exe) { throw "Na verwijderen staat $exe er nog" } + if (Status) { throw "het programma draait nog na verwijderen" } - uses: actions/upload-artifact@v4 with: name: windows-setup diff --git a/tests/release-workflow.test.ts b/tests/release-workflow.test.ts index 92dc570..a1dd3c5 100644 --- a/tests/release-workflow.test.ts +++ b/tests/release-workflow.test.ts @@ -20,6 +20,12 @@ describe("release-workflow", () => { expect(release).toContain("name: windows-setup"); expect(release).toMatch(/gh release create[^\n]*projectx-eid-setup-\$v\.exe/); }); + it("wacht niet met Start-Process -Wait op de setup (de bridge blijft draaien) en heeft tijdslimieten", () => { + const code = ci.split("\n").filter((line) => !line.trim().startsWith("#")); + expect(code.filter((line) => /Start-Process.*-Wait\b/.test(line))).toEqual([]); + expect(ci).toContain("WaitForExit("); + expect(ci.match(/timeout-minutes:/g)?.length).toBeGreaterThanOrEqual(3); + }); it("maakt geen release als de tag al bestaat", () => { expect(release).toContain("steps.version.outputs.exists == 'false'"); }); From c634e444b8f2cbe03660ebf7a70775399bc56f85 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 12:09:58 +0000 Subject: [PATCH 07/11] build: Docker-image voor QA, ACC en productie (Next.js standalone), gebouwd en getest in CI Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QBvjDi4WTEVyahPGcQ9wS3 --- .dockerignore | 15 +++++++++++++++ .github/workflows/ci.yml | 24 +++++++++++++++++++++--- Dockerfile | 26 ++++++++++++++++++++++++++ next.config.ts | 2 ++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d44d5dd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +.github +node_modules +**/node_modules +.next +**/.next +out +build +coverage +*.tsbuildinfo +.env*.local +deploy +installer +tests +*.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62746d7..5c7d629 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,15 +97,33 @@ jobs: public/downloads/projectx-eid-setup.exe.sha256 if-no-files-found: error + # Het Docker-image voor QA, ACC en productie moet blijven bouwen (zie Dockerfile en deploy/). + docker: + name: docker image + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - run: docker build -t projectx-eid:ci . + - name: Container starten en controleren + run: | + docker run -d --name projectx-ci -p 3000:3000 projectx-eid:ci + for i in $(seq 1 30); do + if curl -fsS -o /dev/null http://127.0.0.1:3000/; then echo "OK"; exit 0; fi + sleep 2 + done + docker logs projectx-ci + exit 1 + # Eén vaste naam om als vereiste check voor main in te stellen. ci-check: name: CI-check if: always() - needs: [check, setup] + needs: [check, setup, docker] runs-on: ubuntu-latest steps: - run: | - echo "check: ${{ needs.check.result }}, setup: ${{ needs.setup.result }}" - if [ "${{ needs.check.result }}" != "success" ] || [ "${{ needs.setup.result }}" != "success" ]; then + echo "check: ${{ needs.check.result }}, setup: ${{ needs.setup.result }}, docker: ${{ needs.docker.result }}" + if [ "${{ needs.check.result }}" != "success" ] || [ "${{ needs.setup.result }}" != "success" ] || [ "${{ needs.docker.result }}" != "success" ]; then exit 1 fi diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..56a5921 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# syntax=docker/dockerfile:1 +# ProjectX als container, voor QA, ACC en productie op de eigen server (zie deploy/README.nl.md). +# De release-pipeline bouwt dit image één keer en zet het achtereenvolgens op QA, ACC en productie. + +ARG NODE_VERSION=22 + +FROM node:${NODE_VERSION}-bookworm-slim AS build +WORKDIR /app +ENV NEXT_TELEMETRY_DISABLED=1 +COPY . . +RUN npm ci --no-audit --no-fund && npm run build + +FROM node:${NODE_VERSION}-bookworm-slim AS run +WORKDIR /app +ENV NODE_ENV=production \ + NEXT_TELEMETRY_DISABLED=1 \ + HOSTNAME=0.0.0.0 \ + PORT=3000 +COPY --from=build --chown=node:node /app/.next/standalone ./ +COPY --from=build --chown=node:node /app/.next/static ./.next/static +COPY --from=build --chown=node:node /app/public ./public +USER node +EXPOSE 3000 +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ + CMD ["node", "-e", "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"] +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index 2f6491c..8e8e90c 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,6 +2,8 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { reactStrictMode: true, + // Zelfstandige server in .next/standalone, voor het Docker-image (zie Dockerfile en deploy/). + output: "standalone", }; export default nextConfig; From 7a5e4ae495a6d3bcc46db7948c0e22bd12137b62 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 12:09:58 +0000 Subject: [PATCH 08/11] ci: image naar ghcr.io en via SSH uitrollen naar QA, ACC en productie op de eigen Debian-server Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QBvjDi4WTEVyahPGcQ9wS3 --- .github/actions/deploy/action.yml | 78 ++++++++++++ .github/workflows/release.yml | 120 ++++++++++++++---- deploy/setup-server.sh | 199 ++++++++++++++++++++++++++++++ tests/deploy.test.ts | 31 +++++ tests/release-workflow.test.ts | 16 ++- 5 files changed, 417 insertions(+), 27 deletions(-) create mode 100644 .github/actions/deploy/action.yml create mode 100644 deploy/setup-server.sh create mode 100644 tests/deploy.test.ts diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml new file mode 100644 index 0000000..23ca6d7 --- /dev/null +++ b/.github/actions/deploy/action.yml @@ -0,0 +1,78 @@ +name: Uitrollen naar de server +description: Zet een image op de eigen server via SSH (zie deploy/README.nl.md). Slaat over met een waarschuwing als DEPLOY_HOST niet ingesteld is. + +inputs: + environment: + description: qa, acc of production + required: true + image: + description: Volledige image-naam, bv. ghcr.io/dafkedd/projectx-eid@sha256:… + required: true + url: + description: Adres om na het uitrollen te controleren (vars.DEPLOY_URL) + required: false + host: + required: false + port: + required: false + user: + required: false + ssh-key: + required: false + known-hosts: + required: false + registry-token: + description: Token waarmee de server het image van ghcr.io haalt (github.token, alleen tijdens deze job geldig) + required: true + +runs: + using: composite + steps: + - name: Uitrollen + shell: bash + env: + ENVIRONMENT: ${{ inputs.environment }} + IMAGE: ${{ inputs.image }} + DEPLOY_HOST: ${{ inputs.host }} + DEPLOY_PORT: ${{ inputs.port }} + DEPLOY_USER: ${{ inputs.user }} + DEPLOY_SSH_KEY: ${{ inputs.ssh-key }} + DEPLOY_KNOWN_HOSTS: ${{ inputs.known-hosts }} + REGISTRY_TOKEN: ${{ inputs.registry-token }} + run: | + if [ -z "$DEPLOY_HOST" ]; then + echo "::warning::Geen DEPLOY_HOST: $ENVIRONMENT niet uitgerold (zie deploy/README.nl.md)." + exit 0 + fi + if [ -z "$DEPLOY_SSH_KEY" ] || [ -z "$DEPLOY_KNOWN_HOSTS" ]; then + echo "::error::DEPLOY_SSH_KEY en DEPLOY_KNOWN_HOSTS zijn nodig om naar $DEPLOY_HOST uit te rollen." + exit 1 + fi + dir="$RUNNER_TEMP/ssh" + install -d -m 700 "$dir" + printf '%s\n' "$DEPLOY_SSH_KEY" > "$dir/key" + printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$dir/known_hosts" + chmod 600 "$dir/key" "$dir/known_hosts" + # De server staat voor deze sleutel alleen "deploy " toe; het token gaat via stdin. + printf '%s' "$REGISTRY_TOKEN" | ssh -i "$dir/key" -p "${DEPLOY_PORT:-22}" \ + -o UserKnownHostsFile="$dir/known_hosts" -o StrictHostKeyChecking=yes -o BatchMode=yes \ + -o ConnectTimeout=20 -o ServerAliveInterval=15 \ + "${DEPLOY_USER:-deploy}@$DEPLOY_HOST" "deploy $ENVIRONMENT $IMAGE" + rm -rf "$dir" + + - name: Controleren + if: inputs.url != '' && inputs.host != '' + shell: bash + env: + URL: ${{ inputs.url }} + run: | + for i in $(seq 1 20); do + if curl -fsS -o /dev/null --max-time 10 "$URL"; then + echo "OK: $URL" + echo "### ${{ inputs.environment }}: $URL" >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + sleep 6 + done + echo "::error::$URL antwoordt niet na het uitrollen." + exit 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d40c3b3..7ef5122 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,9 +2,13 @@ name: Release # Alleen op de branch `release` (meestal een merge main → release). Stappen, zoals in Azure DevOps: # 1. ci alle tests (ci.yml) -# 2. qa uitrollen naar QA (environment "qa") -# 3. acc uitrollen naar acceptatie (environment "acc") -# 4. release tag v + GitHub-release met de Windows-setup (environment "production") +# 2. image Docker-image bouwen (met de Windows-setup erin) en naar ghcr.io zetten +# 3. qa dat image uitrollen naar QA (environment "qa") +# 4. acc hetzelfde image naar acceptatie (environment "acc") +# 5. release hetzelfde image naar productie, tag v + GitHub-release met de Windows-setup +# (environment "production") +# Uitrollen gaat via SSH naar de eigen server (deploy/README.nl.md). Zonder secret DEPLOY_HOST wordt er +# niet uitgerold, alleen gewaarschuwd. # Met "Required reviewers" op een environment wacht die stap op een knop "Approve" in het tabblad Actions. # Bestaat tag v al, dan wordt er geen release gemaakt: verhoog eerst de versie (npm run version:patch). @@ -23,49 +27,119 @@ jobs: ci: uses: ./.github/workflows/ci.yml + image: + name: Image + needs: ci + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + packages: write + outputs: + image: ${{ steps.push.outputs.image }} + steps: + - uses: actions/checkout@v4 + - name: Windows-setup ophalen (uit de CI-stap), voor de downloadknop in de app + uses: actions/download-artifact@v4 + with: + name: windows-setup + path: public/downloads + - name: Bouwen en naar ghcr.io + id: push + env: + GH_TOKEN: ${{ github.token }} + run: | + repo="ghcr.io/${GITHUB_REPOSITORY,,}" + version=$(node -p "require('./package.json').version") + tag="$repo:$version-${GITHUB_SHA::7}" + echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin + docker build \ + --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ + --label "org.opencontainers.image.revision=$GITHUB_SHA" \ + --label "org.opencontainers.image.version=$version" \ + -t "$tag" -t "$repo:sha-$GITHUB_SHA" . + docker push "$tag" + docker push "$repo:sha-$GITHUB_SHA" + digest=$(docker inspect --format '{{index .RepoDigests 0}}' "$tag") + echo "image=$digest" >> "$GITHUB_OUTPUT" + echo "### Image: \`$tag\`" >> "$GITHUB_STEP_SUMMARY" + qa: name: QA - needs: ci + needs: image runs-on: ubuntu-latest - environment: qa + timeout-minutes: 15 + environment: + name: qa + url: ${{ vars.DEPLOY_URL }} + permissions: + contents: read + packages: read steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: ./.github/actions/deploy with: - node-version: 22 - cache: npm - - run: npm ci - - run: npm run build - # TODO: hier uitrollen naar de QA-omgeving (bv. Azure Web App, Vercel of een eigen server). - - run: echo "QA-build klaar voor ${GITHUB_SHA::7}. Uitrollen naar QA is nog niet ingesteld." + environment: qa + image: ${{ needs.image.outputs.image }} + url: ${{ vars.DEPLOY_URL }} + host: ${{ secrets.DEPLOY_HOST }} + port: ${{ secrets.DEPLOY_PORT }} + user: ${{ secrets.DEPLOY_USER }} + ssh-key: ${{ secrets.DEPLOY_SSH_KEY }} + known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }} + registry-token: ${{ github.token }} acc: name: ACC - needs: qa + needs: [image, qa] runs-on: ubuntu-latest - environment: acc + timeout-minutes: 15 + environment: + name: acc + url: ${{ vars.DEPLOY_URL }} + permissions: + contents: read + packages: read steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: ./.github/actions/deploy with: - node-version: 22 - cache: npm - - run: npm ci - - run: npm run build - # TODO: hier uitrollen naar de acceptatie-omgeving. - - run: echo "ACC-build klaar voor ${GITHUB_SHA::7}. Uitrollen naar ACC is nog niet ingesteld." + environment: acc + image: ${{ needs.image.outputs.image }} + url: ${{ vars.DEPLOY_URL }} + host: ${{ secrets.DEPLOY_HOST }} + port: ${{ secrets.DEPLOY_PORT }} + user: ${{ secrets.DEPLOY_USER }} + ssh-key: ${{ secrets.DEPLOY_SSH_KEY }} + known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }} + registry-token: ${{ github.token }} release: name: Release - needs: acc + needs: [image, acc] runs-on: ubuntu-latest - environment: production + environment: + name: production + url: ${{ vars.DEPLOY_URL }} permissions: contents: write + packages: read steps: - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Uitrollen naar productie + uses: ./.github/actions/deploy + with: + environment: production + image: ${{ needs.image.outputs.image }} + url: ${{ vars.DEPLOY_URL }} + host: ${{ secrets.DEPLOY_HOST }} + port: ${{ secrets.DEPLOY_PORT }} + user: ${{ secrets.DEPLOY_USER }} + ssh-key: ${{ secrets.DEPLOY_SSH_KEY }} + known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }} + registry-token: ${{ github.token }} - uses: actions/setup-node@v4 with: node-version: 22 diff --git a/deploy/setup-server.sh b/deploy/setup-server.sh new file mode 100644 index 0000000..7bc0870 --- /dev/null +++ b/deploy/setup-server.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env bash +# ProjectX: Debian-server eenmalig klaarzetten voor QA, ACC en productie (Docker + Caddy). +# Uitvoeren als root. Mag je opnieuw uitvoeren: bestaande sleutels en uitgerolde versies blijven staan. +# +# bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 \ +# --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be [--email jij@voorbeeld.be] +# +# Wat het doet: +# 1. Docker Engine + Compose installeren (officiële Docker-repository voor Debian) +# 2. gebruiker "deploy" aanmaken: GitHub Actions logt hiermee in en mag alléén /opt/projectx/bin/deploy uitvoeren +# 3. /opt/projectx/{caddy,qa,acc,production} met een compose-bestand per omgeving +# 4. Caddy starten: HTTPS-certificaten van Let's Encrypt, één subdomein per omgeving +# 5. de waarden tonen die je in GitHub zet (sleutel, known_hosts) +set -euo pipefail + +HOST="" SSH_PORT="22" QA="" ACC="" PROD="" EMAIL="" +while [ $# -gt 0 ]; do + case "$1" in + --host) HOST="$2"; shift 2 ;; + --ssh-port) SSH_PORT="$2"; shift 2 ;; + --qa) QA="$2"; shift 2 ;; + --acc) ACC="$2"; shift 2 ;; + --prod) PROD="$2"; shift 2 ;; + --email) EMAIL="$2"; shift 2 ;; + *) echo "Onbekende optie: $1" >&2; exit 2 ;; + esac +done +[ "$(id -u)" = 0 ] || { echo "Voer dit uit als root." >&2; exit 1; } +[ -n "$HOST" ] && [ -n "$QA" ] && [ -n "$ACC" ] && [ -n "$PROD" ] || { + echo "Gebruik: bash setup-server.sh --host --ssh-port --qa --acc --prod [--email ]" >&2 + exit 2 +} +for d in "$QA" "$ACC" "$PROD"; do + [[ "$d" =~ ^[a-z0-9.-]+$ ]] || { echo "Ongeldig domein: $d" >&2; exit 2; } +done +[[ "$SSH_PORT" =~ ^[0-9]+$ ]] || { echo "Ongeldige poort: $SSH_PORT" >&2; exit 2; } +. /etc/os-release +[ "${ID:-}" = debian ] || { echo "Dit script is voor Debian (gevonden: ${ID:-onbekend})." >&2; exit 1; } + +say() { printf '\n\033[1m==> %s\033[0m\n' "$*"; } +BASE=/opt/projectx + +say "1/5 Docker installeren" +if ! command -v docker >/dev/null || ! docker compose version >/dev/null 2>&1; then + apt-get update -q + apt-get install -y -q ca-certificates curl + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + chmod a+r /etc/apt/keyrings/docker.asc + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian ${VERSION_CODENAME} stable" \ + > /etc/apt/sources.list.d/docker.list + apt-get update -q + apt-get install -y -q docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +fi +systemctl enable --now docker >/dev/null +docker --version + +say "2/5 Gebruiker deploy" +id deploy >/dev/null 2>&1 || useradd --create-home --shell /bin/bash deploy +passwd -l deploy >/dev/null # geen wachtwoord: alleen met de sleutel +usermod -aG docker deploy +install -d -m 700 -o deploy -g deploy /home/deploy/.ssh +KEY="$BASE/github-deploy-key" +AUTH=/home/deploy/.ssh/authorized_keys +install -d -m 755 "$BASE" "$BASE/bin" +# Eén sleutel voor GitHub Actions. Bestaat hij al, dan blijft hij (anders klopt het secret in GitHub niet meer). +# Nieuwe sleutel nodig? rm /home/deploy/.ssh/authorized_keys en voer dit script opnieuw uit. +if [ ! -s "$AUTH" ]; then + rm -f "$KEY" "$KEY.pub" + ssh-keygen -q -t ed25519 -N "" -C "github-actions@projectx" -f "$KEY" + # De sleutel mag niets anders dan het deploy-script starten: geen shell, geen tunnels. + echo "restrict,command=\"$BASE/bin/deploy\" $(cat "$KEY.pub")" > "$AUTH" + chown deploy:deploy "$AUTH" + chmod 600 "$AUTH" "$KEY" +fi + +cat > "$BASE/bin/deploy" <<'DEPLOY' +#!/usr/bin/env bash +# Aangeroepen door GitHub Actions via SSH: "deploy ", registry-token op stdin. +set -euo pipefail +read -r cmd environment image extra <<<"${SSH_ORIGINAL_COMMAND:-}" || true +[ "${cmd:-}" = deploy ] && [ -z "${extra:-}" ] || { echo "Alleen: deploy " >&2; exit 2; } +case "$environment" in qa|acc|production) ;; *) echo "Onbekende omgeving: $environment" >&2; exit 2 ;; esac +[[ "$image" =~ ^ghcr\.io/[a-z0-9._/-]+(:[A-Za-z0-9._-]+)?(@sha256:[a-f0-9]{64})?$ ]] || { echo "Ongeldig image: $image" >&2; exit 2; } + +dir=/opt/projectx/$environment +cd "$dir" +previous=$(sed -n 's/^IMAGE=//p' .env 2>/dev/null || true) + +# Inloggen bij ghcr.io met het kortlevende GitHub-token, in een tijdelijke map: niets blijft bewaard. +export DOCKER_CONFIG; DOCKER_CONFIG=$(mktemp -d) +trap 'rm -rf "$DOCKER_CONFIG"' EXIT +token=$(head -c 4096) +if [ -n "$token" ]; then + printf '%s' "$token" | docker login ghcr.io -u github-actions --password-stdin >/dev/null +fi +docker pull -q "$image" + +up() { printf 'IMAGE=%s\nENVIRONMENT=%s\n' "$1" "$environment" > .env; docker compose -p "projectx-$environment" up -d --remove-orphans; } +healthy() { + for _ in $(seq 1 45); do + [ "$(docker inspect -f '{{.State.Health.Status}}' "projectx-$environment" 2>/dev/null)" = healthy ] && return 0 + sleep 2 + done + return 1 +} + +echo "Uitrollen naar $environment: $image" +up "$image" +if healthy; then + echo "OK: $environment draait $image" + docker image prune -af --filter "until=336h" >/dev/null || true + exit 0 +fi +docker logs --tail 50 "projectx-$environment" >&2 || true +if [ -n "$previous" ] && [ "$previous" != "$image" ]; then + echo "Niet gezond: terug naar $previous" >&2 + up "$previous" || true +fi +exit 1 +DEPLOY +chmod 755 "$BASE/bin/deploy" + +say "3/5 Omgevingen qa, acc, production" +docker network inspect web >/dev/null 2>&1 || docker network create web >/dev/null +for env in qa acc production; do + install -d -m 755 -o deploy -g deploy "$BASE/$env" + cat > "$BASE/$env/compose.yml" <<'COMPOSE' +# Beheerd door setup-server.sh. De versie (IMAGE) staat in .env en wordt gezet door /opt/projectx/bin/deploy. +services: + app: + image: ${IMAGE:?geen IMAGE in .env} + container_name: projectx-${ENVIRONMENT} + restart: unless-stopped + networks: [web] + security_opt: ["no-new-privileges:true"] + cap_drop: [ALL] + mem_limit: 512m + logging: + driver: json-file + options: { max-size: "10m", max-file: "3" } +networks: + web: + external: true +COMPOSE + chown deploy:deploy "$BASE/$env/compose.yml" +done + +say "4/5 Caddy (HTTPS)" +install -d -m 755 "$BASE/caddy" +{ + echo "# Beheerd door setup-server.sh: opnieuw uitvoeren overschrijft dit bestand." + if [ -n "$EMAIL" ]; then printf '{\n\temail %s\n}\n\n' "$EMAIL"; fi + printf '(common) {\n\tencode zstd gzip\n\theader {\n\t\tStrict-Transport-Security "max-age=31536000"\n\t\tX-Content-Type-Options nosniff\n\t\tReferrer-Policy strict-origin-when-cross-origin\n\t\t-Server\n\t}\n}\n\n' + printf '%s {\n\timport common\n\theader X-Robots-Tag "noindex, nofollow"\n\treverse_proxy projectx-qa:3000\n}\n\n' "$QA" + printf '%s {\n\timport common\n\theader X-Robots-Tag "noindex, nofollow"\n\treverse_proxy projectx-acc:3000\n}\n\n' "$ACC" + printf '%s {\n\timport common\n\treverse_proxy projectx-production:3000\n}\n' "$PROD" +} > "$BASE/caddy/Caddyfile" +cat > "$BASE/caddy/compose.yml" <<'COMPOSE' +services: + caddy: + image: caddy:2 + container_name: caddy + restart: unless-stopped + ports: ["80:80", "443:443", "443:443/udp"] + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile:ro + - data:/data + - config:/config + networks: [web] +networks: + web: + external: true +volumes: + data: + config: +COMPOSE +docker compose -f "$BASE/caddy/compose.yml" -p caddy up -d +docker exec caddy caddy reload --config /etc/caddy/Caddyfile >/dev/null 2>&1 || true + +say "5/5 Klaar. Zet deze waarden in GitHub (Settings → Secrets and variables → Actions → New repository secret)" +echo +echo "DEPLOY_HOST = $HOST" +echo "DEPLOY_PORT = $SSH_PORT" +echo "DEPLOY_USER = deploy" +echo +echo "DEPLOY_KNOWN_HOSTS = (alle regels hieronder)" +for f in /etc/ssh/ssh_host_*_key.pub; do + if [ "$SSH_PORT" = 22 ]; then printf '%s %s\n' "$HOST" "$(cut -d' ' -f1,2 "$f")"; else printf '[%s]:%s %s\n' "$HOST" "$SSH_PORT" "$(cut -d' ' -f1,2 "$f")"; fi +done +echo +if [ -f "$KEY" ]; then + echo "DEPLOY_SSH_KEY = (alles hieronder, ook de regels BEGIN en END)" + cat "$KEY" + echo + echo "Staat DEPLOY_SSH_KEY in GitHub? Gooi dan deze kopie weg: rm $KEY" +else + echo "DEPLOY_SSH_KEY = staat al in GitHub (de kopie op de server is weggegooid)." +fi diff --git a/tests/deploy.test.ts b/tests/deploy.test.ts new file mode 100644 index 0000000..27a330c --- /dev/null +++ b/tests/deploy.test.ts @@ -0,0 +1,31 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; + +const read = (name: string) => readFileSync(new URL(`../${name}`, import.meta.url), "utf8"); + +describe("uitrollen naar de eigen server", () => { + const setup = read("deploy/setup-server.sh"); + const action = read(".github/actions/deploy/action.yml"); + const installer = JSON.parse(read("installer/eid-installer.json")) as { origins: string[] }; + + it("laat de deploy-sleutel alleen het deploy-script starten", () => { + expect(setup).toContain('restrict,command=\\"$BASE/bin/deploy\\"'); + expect(setup).toMatch(/case "\$environment" in qa\|acc\|production\)/); + expect(setup).toContain("passwd -l deploy"); + }); + + it("controleert de server-sleutel en slaat over zonder DEPLOY_HOST", () => { + expect(action).toContain("StrictHostKeyChecking=yes"); + expect(action).toContain("::warning::Geen DEPLOY_HOST"); + expect(action).not.toMatch(/StrictHostKeyChecking=no|ssh-keyscan/); + }); + + it("bouwt een zelfstandige Next.js-server voor het image", () => { + expect(read("next.config.ts")).toContain('output: "standalone"'); + expect(read("Dockerfile")).toMatch(/USER node[\s\S]*CMD \["node", "server.js"\]/); + }); + + it("laat de websites van QA, ACC en productie toe in het eID-programma", () => { + for (const host of ["qa", "acc", "prod"]) expect(installer.origins).toContain(`https://${host}.dafkedd.be`); + }); +}); diff --git a/tests/release-workflow.test.ts b/tests/release-workflow.test.ts index a1dd3c5..f7f4558 100644 --- a/tests/release-workflow.test.ts +++ b/tests/release-workflow.test.ts @@ -8,15 +8,16 @@ describe("release-workflow", () => { expect(release).toMatch(/push:\n\s+branches: \[release\]/); expect(release).toContain("uses: ./.github/workflows/ci.yml"); expect(release).not.toContain("workflow_dispatch"); - expect(release).toMatch(/qa:[\s\S]*needs: ci[\s\S]*environment: qa/); - expect(release).toMatch(/acc:[\s\S]*needs: qa[\s\S]*environment: acc/); - expect(release).toMatch(/release:[\s\S]*needs: acc[\s\S]*environment: production/); + expect(release).toMatch(/image:\n[\s\S]*needs: ci\n/); + expect(release).toMatch(/qa:\n[\s\S]*needs: image\n[\s\S]*name: qa/); + expect(release).toMatch(/acc:\n[\s\S]*needs: \[image, qa\][\s\S]*name: acc/); + expect(release).toMatch(/release:\n[\s\S]*needs: \[image, acc\][\s\S]*name: production/); expect(ci).toContain("workflow_call:"); }); it("hangt de Windows-setup uit CI aan de release", () => { expect(ci).toMatch(/setup:[\s\S]*runs-on: windows-latest[\s\S]*npm run build:installer/); expect(ci).toContain("name: windows-setup"); - expect(ci).toContain("needs: [check, setup]"); + expect(ci).toContain("needs: [check, setup, docker]"); expect(release).toContain("name: windows-setup"); expect(release).toMatch(/gh release create[^\n]*projectx-eid-setup-\$v\.exe/); }); @@ -29,4 +30,11 @@ describe("release-workflow", () => { it("maakt geen release als de tag al bestaat", () => { expect(release).toContain("steps.version.outputs.exists == 'false'"); }); + it("rolt één image uit naar QA, ACC en productie via de deploy-actie", () => { + expect(release).toContain("docker push"); + expect(release.match(/uses: \.\/\.github\/actions\/deploy/g)?.length).toBe(3); + for (const env of ["qa", "acc", "production"]) expect(release).toContain(`environment: ${env}\n`); + expect(release.match(/image: \$\{\{ needs\.image\.outputs\.image \}\}/g)?.length).toBe(3); + expect(ci).toMatch(/docker:\n[\s\S]*docker build/); + }); }); From d21af13f78aa718fba222f2dc931cf41f3a4cb0b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 12:09:58 +0000 Subject: [PATCH 09/11] feat(installer): qa, acc en prod.dafkedd.be toelaten in het eID-programma Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QBvjDi4WTEVyahPGcQ9wS3 --- installer/eid-installer.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/installer/eid-installer.json b/installer/eid-installer.json index e5dd128..e51aaa3 100644 --- a/installer/eid-installer.json +++ b/installer/eid-installer.json @@ -1,6 +1,11 @@ { - "$comment": "Instellingen die in het eID-programma (dafke-eid) en de Windows-setup worden ingebakken. Zet hier het adres van ProjectX in productie bij. Geen token: wat in een programma zit, is niet geheim (zie README).", - "origins": ["http://localhost:3000"], + "$comment": "Instellingen die in het eID-programma (dafke-eid) en de Windows-setup worden ingebakken: de websites die het programma mogen gebruiken (lokaal, QA, ACC en productie). Geen token: wat in een programma zit, is niet geheim (zie README).", + "origins": [ + "http://localhost:3000", + "https://qa.dafkedd.be", + "https://acc.dafkedd.be", + "https://prod.dafkedd.be" + ], "authOrigins": [], "testpage": true, "setupName": "projectx-eid-setup" From 18eb9c27a469001e719934d6c585f763c258241f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 12:09:58 +0000 Subject: [PATCH 10/11] docs: server instellen en uitrollen (NL + EN) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QBvjDi4WTEVyahPGcQ9wS3 --- README.md | 14 ++++-- README.nl.md | 14 ++++-- deploy/README.md | 112 ++++++++++++++++++++++++++++++++++++++++++++ deploy/README.nl.md | 112 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+), 10 deletions(-) create mode 100644 deploy/README.md create mode 100644 deploy/README.nl.md diff --git a/README.md b/README.md index 32e9648..dbd357d 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ End users need the eID program. One command builds a setup with ProjectX's websi double-clicking is enough, no admin rights needed, and the program then starts automatically when the user signs in to Windows. -1. Put ProjectX's production address in `installer/eid-installer.json` (`origins`, and +1. ProjectX's websites (local, QA, ACC, production) are in `installer/eid-installer.json` (`origins`, and `authOrigins` if you use PIN login). 2. Once: `winget install JRSoftware.InnoSetup`. 3. Build (on Windows, Node 22 or 24): @@ -120,10 +120,14 @@ like in Azure DevOps: | Step | Environment | What | | --- | --- | --- | -| CI | — | Typecheck, tests and build on Linux and Windows; build and test the Windows setup | -| QA | `qa` | Build for QA (deployment still to be filled in) | -| ACC | `acc` | Build for acceptance (deployment still to be filled in) | -| Release | `production` | Tag `v` + GitHub release with the Windows setup, zip and sha256 | +| CI | — | Typecheck, tests and build on Linux and Windows; build and test the Windows setup; build the Docker image | +| Image | — | Docker image (with the Windows setup inside) to `ghcr.io` | +| QA | `qa` | Deploy that image to https://qa.dafkedd.be | +| ACC | `acc` | Deploy the same image to https://acc.dafkedd.be | +| Release | `production` | Same image to https://prod.dafkedd.be, then tag `v` + GitHub release with the Windows setup, zip and sha256 | + +Deployment goes over SSH to our own Debian server with Docker and Caddy. Setup and secrets: +[deploy/README.md](deploy/README.md). Making a release: diff --git a/README.nl.md b/README.nl.md index cf52100..b6e3237 100644 --- a/README.nl.md +++ b/README.nl.md @@ -58,7 +58,7 @@ Eindgebruikers hebben het eID-programma nodig. Met één commando bouw je een se van ProjectX al ingebakken zitten: dubbelklikken volstaat, zonder beheerdersrechten, en het programma start daarna automatisch bij het aanmelden in Windows. -1. Zet het adres van ProjectX in productie in `installer/eid-installer.json` (`origins`, en +1. De websites van ProjectX (lokaal, QA, ACC, productie) staan in `installer/eid-installer.json` (`origins`, en `authOrigins` als je aanmelden met PIN gebruikt). 2. Eenmalig: `winget install JRSoftware.InnoSetup`. 3. Bouwen (op Windows, Node 22 of 24): @@ -121,10 +121,14 @@ draaien alleen de tests (`ci.yml`). Alleen een push naar `release` start de rele | Stap | Environment | Wat | | --- | --- | --- | -| CI | — | Typecheck, tests en build op Linux en Windows; Windows-setup bouwen en testen | -| QA | `qa` | Build voor QA (uitrollen nog in te vullen) | -| ACC | `acc` | Build voor acceptatie (uitrollen nog in te vullen) | -| Release | `production` | Tag `v` + GitHub-release met de Windows-setup, zip en sha256 | +| CI | — | Typecheck, tests en build op Linux en Windows; Windows-setup bouwen en testen; Docker-image bouwen | +| Image | — | Docker-image (met de Windows-setup erin) naar `ghcr.io` | +| QA | `qa` | Dat image uitrollen naar https://qa.dafkedd.be | +| ACC | `acc` | Hetzelfde image naar https://acc.dafkedd.be | +| Release | `production` | Hetzelfde image naar https://prod.dafkedd.be, dan tag `v` + GitHub-release met de Windows-setup, zip en sha256 | + +Uitrollen gaat via SSH naar onze eigen Debian-server met Docker en Caddy. Instellen en secrets: +[deploy/README.nl.md](deploy/README.nl.md). Een release maken: diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..99d7d7d --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,112 @@ +# Deploying to your own server (QA, ACC, production) + +**English** · [Nederlands](README.nl.md) + +ProjectX runs on one Debian server, in Docker, with [Caddy](https://caddyserver.com) in front for HTTPS: + +| Environment | Address | Container | +| --- | --- | --- | +| QA | https://qa.dafkedd.be | `projectx-qa` | +| ACC | https://acc.dafkedd.be | `projectx-acc` | +| Production | https://prod.dafkedd.be | `projectx-production` | + +On a push to `release`, the release pipeline (`.github/workflows/release.yml`) builds one Docker image, +pushes it to `ghcr.io` and deploys **the same** image to QA, ACC and production in turn. GitHub logs in +over SSH as the user `deploy`. On the server that key can do nothing but start `/opt/projectx/bin/deploy`: +no shell, no reading files. If a new version does not become healthy, the server puts the previous +version back. + +## One-time setup + +### 1. DNS + +At the registrar of `dafkedd.be`, create three A records pointing to the server: + +| Name | Type | Value | +| --- | --- | --- | +| `qa` | A | `51.75.77.10` | +| `acc` | A | `51.75.77.10` | +| `prod` | A | `51.75.77.10` | + +Check (may take a while): + +```bash +nslookup qa.dafkedd.be +``` + +### 2. Prepare the server + +Log in as root and run the script. It installs Docker, creates the user `deploy`, sets up Caddy and +prints the values for GitHub at the end. You can run it again later. + +```bash +ssh -p 22822 root@51.75.77.10 +``` + +```bash +curl -fsSL https://raw.githubusercontent.com/DafkeDD/ProjectX-eID/developer/deploy/setup-server.sh -o setup-server.sh +bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be +``` + +Let's Encrypt only uses the email address to warn you when a certificate is about to expire. +If your hosting provider has a firewall, open ports 80 and 443 (and keep 22822 open). + +### 3. Secrets in GitHub + +Go to **Settings → Secrets and variables → Actions → Secrets → New repository secret** and create +these five, with the values the script printed: + +| Secret | Value | +| --- | --- | +| `DEPLOY_HOST` | `51.75.77.10` | +| `DEPLOY_PORT` | `22822` | +| `DEPLOY_USER` | `deploy` | +| `DEPLOY_KNOWN_HOSTS` | the lines starting with `[51.75.77.10]:22822` | +| `DEPLOY_SSH_KEY` | the private key, including `-----BEGIN …` and `-----END …` | + +Then delete the copy of the key on the server: + +```bash +rm /opt/projectx/github-deploy-key +``` + +### 4. Address per environment + +Go to **Settings → Environments**, open `qa`, `acc` and `production` (or create them with +**New environment**) and add `DEPLOY_URL` under **Environment variables** for each: + +| Environment | `DEPLOY_URL` | +| --- | --- | +| `qa` | `https://qa.dafkedd.be` | +| `acc` | `https://acc.dafkedd.be` | +| `production` | `https://prod.dafkedd.be` | + +After deploying, the pipeline checks that address. Also set **Required reviewers** on `acc` and +`production`, so the pipeline waits for your approval before those steps. + +## Deploying + +Release as described in the main README: PR `main → release`. The **Actions** tab shows +**Image → QA → ACC → Release**. As long as `DEPLOY_HOST` is not set, QA, ACC and production skip the +deployment with a warning. + +**Back to a previous version:** in **Actions**, open the run of that version and choose +**Re-run jobs** on the step of the environment. That puts exactly that run's image back. + +## Looking around on the server + +```bash +docker ps +docker logs --tail 100 projectx-production +docker logs --tail 100 caddy +cat /opt/projectx/production/.env +``` + +| Path | What | +| --- | --- | +| `/opt/projectx/bin/deploy` | Script GitHub calls over SSH | +| `/opt/projectx//` | `compose.yml` and `.env` (which image runs) | +| `/opt/projectx/caddy/` | Caddy's `Caddyfile` and `compose.yml` | + +To change a domain: run `setup-server.sh` again with the new names, and update +`installer/eid-installer.json` (the websites the eID program allows). diff --git a/deploy/README.nl.md b/deploy/README.nl.md new file mode 100644 index 0000000..34dd93d --- /dev/null +++ b/deploy/README.nl.md @@ -0,0 +1,112 @@ +# Uitrollen naar de eigen server (QA, ACC, productie) + +[English](README.md) · **Nederlands** + +ProjectX draait op één Debian-server, in Docker, met [Caddy](https://caddyserver.com) ervoor voor HTTPS: + +| Omgeving | Adres | Container | +| --- | --- | --- | +| QA | https://qa.dafkedd.be | `projectx-qa` | +| ACC | https://acc.dafkedd.be | `projectx-acc` | +| Productie | https://prod.dafkedd.be | `projectx-production` | + +De release-pipeline (`.github/workflows/release.yml`) bouwt bij een push naar `release` één Docker-image, +zet het op `ghcr.io` en rolt **hetzelfde** image na elkaar uit naar QA, ACC en productie. GitHub logt via +SSH in als de gebruiker `deploy`. Die sleutel mag op de server niets anders dan `/opt/projectx/bin/deploy` +starten: geen shell, geen bestanden lezen. Wordt een nieuwe versie niet gezond, dan zet de server de +vorige versie terug. + +## Eenmalig instellen + +### 1. DNS + +Maak bij de beheerder van `dafkedd.be` drie A-records die naar de server wijzen: + +| Naam | Type | Waarde | +| --- | --- | --- | +| `qa` | A | `51.75.77.10` | +| `acc` | A | `51.75.77.10` | +| `prod` | A | `51.75.77.10` | + +Controleren (mag een tijdje duren): + +```bash +nslookup qa.dafkedd.be +``` + +### 2. De server klaarzetten + +Log in als root en voer het script uit. Het installeert Docker, maakt de gebruiker `deploy`, zet Caddy +op en toont op het einde de waarden voor GitHub. Je mag het later opnieuw uitvoeren. + +```bash +ssh -p 22822 root@51.75.77.10 +``` + +```bash +curl -fsSL https://raw.githubusercontent.com/DafkeDD/ProjectX-eID/developer/deploy/setup-server.sh -o setup-server.sh +bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be +``` + +Het e-mailadres gebruikt Let's Encrypt alleen om te waarschuwen als een certificaat dreigt te vervallen. +Heeft je hostingprovider een firewall, zet dan poort 80 en 443 open (en laat 22822 open). + +### 3. Secrets in GitHub + +Ga naar **Settings → Secrets and variables → Actions → Secrets → New repository secret** en maak +deze vijf aan, met de waarden die het script toonde: + +| Secret | Waarde | +| --- | --- | +| `DEPLOY_HOST` | `51.75.77.10` | +| `DEPLOY_PORT` | `22822` | +| `DEPLOY_USER` | `deploy` | +| `DEPLOY_KNOWN_HOSTS` | de regels die beginnen met `[51.75.77.10]:22822` | +| `DEPLOY_SSH_KEY` | de privésleutel, inclusief `-----BEGIN …` en `-----END …` | + +Gooi daarna de kopie van de sleutel op de server weg: + +```bash +rm /opt/projectx/github-deploy-key +``` + +### 4. Adres per omgeving + +Ga naar **Settings → Environments**, open `qa`, `acc` en `production` (of maak ze met +**New environment**) en voeg onder **Environment variables** telkens `DEPLOY_URL` toe: + +| Environment | `DEPLOY_URL` | +| --- | --- | +| `qa` | `https://qa.dafkedd.be` | +| `acc` | `https://acc.dafkedd.be` | +| `production` | `https://prod.dafkedd.be` | + +Na het uitrollen controleert de pipeline dat adres. Zet ook **Required reviewers** op `acc` en +`production`, dan wacht de pipeline op jouw goedkeuring voor die stappen. + +## Uitrollen + +Gewoon releasen zoals in de hoofd-README: PR `main → release`. In het tabblad **Actions** zie je +**Image → QA → ACC → Release**. Zolang `DEPLOY_HOST` niet ingesteld is, slaan QA, ACC en productie +het uitrollen over met een waarschuwing. + +**Terug naar een vorige versie:** open in **Actions** de run van die versie en kies +**Re-run jobs** op de stap van de omgeving. Die zet precies het image van toen terug. + +## Op de server kijken + +```bash +docker ps +docker logs --tail 100 projectx-production +docker logs --tail 100 caddy +cat /opt/projectx/production/.env +``` + +| Map | Wat | +| --- | --- | +| `/opt/projectx/bin/deploy` | Script dat GitHub via SSH aanroept | +| `/opt/projectx//` | `compose.yml` en `.env` (welk image draait) | +| `/opt/projectx/caddy/` | `Caddyfile` en `compose.yml` van Caddy | + +Een domein wijzigen: voer `setup-server.sh` opnieuw uit met de nieuwe namen, en pas +`installer/eid-installer.json` aan (de websites die het eID-programma toelaat). From 68001d754a2a9e758b26ecdea009167af5bf45e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 12:11:03 +0000 Subject: [PATCH 11/11] docs: inloggen als debian en het setupscript met sudo starten (NL + EN) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QBvjDi4WTEVyahPGcQ9wS3 --- deploy/README.md | 6 +++--- deploy/README.nl.md | 6 +++--- deploy/setup-server.sh | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/deploy/README.md b/deploy/README.md index 99d7d7d..7578c90 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -36,16 +36,16 @@ nslookup qa.dafkedd.be ### 2. Prepare the server -Log in as root and run the script. It installs Docker, creates the user `deploy`, sets up Caddy and +Log in (on OVH as `debian`; root usually may not log in directly) and run the script with `sudo`. It installs Docker, creates the user `deploy`, sets up Caddy and prints the values for GitHub at the end. You can run it again later. ```bash -ssh -p 22822 root@51.75.77.10 +ssh -p 22822 debian@51.75.77.10 ``` ```bash curl -fsSL https://raw.githubusercontent.com/DafkeDD/ProjectX-eID/developer/deploy/setup-server.sh -o setup-server.sh -bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be +sudo bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be ``` Let's Encrypt only uses the email address to warn you when a certificate is about to expire. diff --git a/deploy/README.nl.md b/deploy/README.nl.md index 34dd93d..43a14fd 100644 --- a/deploy/README.nl.md +++ b/deploy/README.nl.md @@ -36,16 +36,16 @@ nslookup qa.dafkedd.be ### 2. De server klaarzetten -Log in als root en voer het script uit. Het installeert Docker, maakt de gebruiker `deploy`, zet Caddy +Log in (bij OVH als `debian`, root mag meestal niet rechtstreeks) en voer het script uit met `sudo`. Het installeert Docker, maakt de gebruiker `deploy`, zet Caddy op en toont op het einde de waarden voor GitHub. Je mag het later opnieuw uitvoeren. ```bash -ssh -p 22822 root@51.75.77.10 +ssh -p 22822 debian@51.75.77.10 ``` ```bash curl -fsSL https://raw.githubusercontent.com/DafkeDD/ProjectX-eID/developer/deploy/setup-server.sh -o setup-server.sh -bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be +sudo bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be --email jij@dafkedd.be ``` Het e-mailadres gebruikt Let's Encrypt alleen om te waarschuwen als een certificaat dreigt te vervallen. diff --git a/deploy/setup-server.sh b/deploy/setup-server.sh index 7bc0870..50429e5 100644 --- a/deploy/setup-server.sh +++ b/deploy/setup-server.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # ProjectX: Debian-server eenmalig klaarzetten voor QA, ACC en productie (Docker + Caddy). -# Uitvoeren als root. Mag je opnieuw uitvoeren: bestaande sleutels en uitgerolde versies blijven staan. +# Uitvoeren als root (of met sudo). Mag je opnieuw uitvoeren: bestaande sleutels en uitgerolde versies blijven staan. # -# bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 \ +# sudo bash setup-server.sh --host 51.75.77.10 --ssh-port 22822 \ # --qa qa.dafkedd.be --acc acc.dafkedd.be --prod prod.dafkedd.be [--email jij@voorbeeld.be] # # Wat het doet: @@ -25,7 +25,7 @@ while [ $# -gt 0 ]; do *) echo "Onbekende optie: $1" >&2; exit 2 ;; esac done -[ "$(id -u)" = 0 ] || { echo "Voer dit uit als root." >&2; exit 1; } +[ "$(id -u)" = 0 ] || { echo "Voer dit uit als root of met sudo." >&2; exit 1; } [ -n "$HOST" ] && [ -n "$QA" ] && [ -n "$ACC" ] && [ -n "$PROD" ] || { echo "Gebruik: bash setup-server.sh --host --ssh-port --qa --acc --prod [--email ]" >&2 exit 2