From 095815e0f34e51f23847553c2a7062a97b391993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Mon, 16 Nov 2026 13:03:00 +0100 Subject: [PATCH] Deploy with Gitea Actions instead of Jenkins on Node 26, drop SonarQube One job: npm ci, tsc --noEmit, npm test on Node 26; on pushes to master it builds, prunes dev dependencies and rsyncs dist/, src/ (Swagger reads it) and node_modules/ over SSH as plesk-plutodev, then restarts Passenger and smoke-tests /docs/. The server's .env, logs/, tmp/ and public/ are never touched - .env is no longer generated by CI but kept on the server. Plesk moves from Node 12.22.12 to 26 with this; the bundle built on 26 also starts on 12, so the order of deploy and Plesk switch doesn't matter. SonarQube leftovers are gone. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/deploy.yml | 106 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .nvmrc | 1 + DEPLOYMENT.md | 108 ++++++++++++++++++++++++++++++++++++ package-lock.json | 34 ------------ package.json | 9 +-- sonar-project.properties | 6 -- 7 files changed, 216 insertions(+), 49 deletions(-) create mode 100644 .gitea/workflows/deploy.yml create mode 100644 .nvmrc create mode 100644 DEPLOYMENT.md delete mode 100644 sonar-project.properties diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..4732282 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,106 @@ +# Tests every push and pull request; deploys pushes to master to the Plesk server (api.plutodev.de). +# Setup and what the deploy may touch: DEPLOYMENT.md. +# +# Same pattern as the Nachklang API (git.plutodev.de/Nachklang/API): build here, deliver over SSH as +# the Plesk subscription user (plesk-plutodev), restart Passenger. The app folder also holds things +# the deploy must never touch (.env with the secrets, logs/, tmp/), so only the app's own folders +# are synced with --delete and nothing is deleted at the top level. +name: Test and deploy + +on: + push: + branches: [master] + pull_request: + +jobs: + # One job, not test + deploy: every job starts in a fresh container, so two jobs meant checking out, + # setting up Node and running `npm ci` twice (~2 min each, 2026-11-08). The deploy steps only run + # for pushes to master; on pull requests the job ends after the tests. The condition is spelled out + # on every deploy step rather than stored in an env flag: a flag compared as a string ('true') would + # skip the deploy silently - and green - if the runner ever rendered the boolean differently. + test-and-deploy: + runs-on: ubuntu-latest + env: + DEPLOY_HOST: ${{ vars.DEPLOY_HOST }} + DEPLOY_PORT: ${{ vars.DEPLOY_PORT }} + DEPLOY_USER: ${{ vars.DEPLOY_USER }} + DEPLOY_PATH: ${{ vars.DEPLOY_PATH }} + # Absolute on purpose: rsync passes its -e string to ssh without a shell, and ssh expands "~" + # from the passwd entry, not $HOME (found in the Nachklang calendar migration, 2026-11-08). + SSH_DIR: /tmp/deploy-ssh + steps: + - uses: actions/checkout@v4 + # .nvmrc = 26, the Node version Plesk runs this app with from the switchover on (it was + # 12.22.12 until 2026-11-16). Build and test with the same one. + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - run: npm ci + - run: npx tsc --noEmit + - run: npm test + + - name: Build + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: npm run build + # Only runtime dependencies go to the server (no typescript, jest, ...). + - name: Prune dev dependencies + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: npm prune --omit=dev + + - name: SSH setup + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + env: + DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} + DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} + run: | + test -n "$DEPLOY_HOST" && test -n "$DEPLOY_USER" && test -n "$DEPLOY_PATH" + if ! command -v rsync >/dev/null 2>&1 || ! command -v ssh >/dev/null 2>&1; then + apt-get update && apt-get install -y --no-install-recommends rsync openssh-client + fi + install -m 700 -d "$SSH_DIR" + printf '%s\n' "$DEPLOY_SSH_KEY" > "$SSH_DIR/key" + chmod 600 "$SSH_DIR/key" + # Pinned host key, never trust-on-first-use. + printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$SSH_DIR/known_hosts" + + - name: Upload + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + rsh="ssh -p ${DEPLOY_PORT:-22} -i $SSH_DIR/key -o UserKnownHostsFile=$SSH_DIR/known_hosts -o IdentitiesOnly=yes -o BatchMode=yes" + target="$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH" + # The app's own folders, each mirrored exactly (--delete within the folder only). public/ is + # not in the repo (gitignored) and not deployed - the server's own copy stays. + # src/ is needed at runtime: swagger-jsdoc reads the route docs from src/models/**/*.ts. + for dir in dist src node_modules; do + rsync -az --delete -e "$rsh" "$dir/" "$target/$dir/" + done + # Single files at the top level, without --delete: .env, logs/ and tmp/ live there too. + # package.json is what makes Node treat dist/ as ES modules ("type": "module"). + rsync -az -e "$rsh" package.json package-lock.json "$target/" + + - name: Restart + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + # Passenger restarts the app on its next request when tmp/restart.txt is touched. + ssh -p "${DEPLOY_PORT:-22}" -i "$SSH_DIR/key" -o "UserKnownHostsFile=$SSH_DIR/known_hosts" \ + -o IdentitiesOnly=yes -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \ + "mkdir -p '$DEPLOY_PATH/tmp' && touch '$DEPLOY_PATH/tmp/restart.txt'" + + # Set DEPLOY_SMOKE_URL to a page that must answer 200 without a key, e.g. + # https://api.plutodev.de/docs/ (the Swagger UI; also proves src/ was deployed). + - name: Smoke test + if: github.event_name == 'push' && github.ref == 'refs/heads/master' && vars.DEPLOY_SMOKE_URL != '' + env: + DEPLOY_SMOKE_URL: ${{ vars.DEPLOY_SMOKE_URL }} + run: | + # Passenger starts the app on the first request after the restart; give it a moment. + for _ in 1 2 3 4 5 6; do + if curl -fsS -o /dev/null "$DEPLOY_SMOKE_URL"; then echo "OK: $DEPLOY_SMOKE_URL"; exit 0; fi + sleep 5 + done + echo "Smoke test failed: $DEPLOY_SMOKE_URL" + exit 1 + + - name: Remove key + if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master' + run: rm -f "$SSH_DIR/key" diff --git a/.gitignore b/.gitignore index 14999a3..c668538 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ logs/ node_modules/ public/ coverage/ -testResults/ diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..6f4247a --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +26 diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md new file mode 100644 index 0000000..1a4f5fe --- /dev/null +++ b/DEPLOYMENT.md @@ -0,0 +1,108 @@ +# Deployment + +`api.plutodev.de` runs on the Plesk server as a Node.js app (Phusion Passenger) and is deployed by +**Gitea Actions** (`.gitea/workflows/deploy.yml`), which replaces the Jenkins job (switchover +2026-11). Same workflow as `Paddy/api.pmueller.me` and the Nachklang API; the reusable how-to is in +Patrick's PKM ("Jenkins to Gitea Actions for a Plesk Node.js App"). + +``` +push to master ──▶ Gitea ──▶ runner (container on the server) + └─ one job: npm ci, tsc --noEmit, npm test (Node 26) + └─ (master only) build, prune dev deps ─ rsync over SSH ─▶ + plesk-plutodev@pmueller.me:/var/www/vhosts/plutodev.de/api.plutodev.de + + tmp/restart.txt +``` + +## Plesk (as configured, 2026-11-16) + +*Websites & Domains → api.plutodev.de → Node.js*: + +| Setting | Value | +|---|---| +| Node.js version | **26** - switched from 12.22.12 (end of life since 2022) with the Gitea switchover, see "Node version" | +| Application root | `/api.plutodev.de` (= `/var/www/vhosts/plutodev.de/api.plutodev.de`) | +| Document root | `/api.plutodev.de/public` | +| Application startup file | `dist/app.js` | +| Application mode | production | +| Environment variable | `PORT=443` (Passenger takes over the port) | + +## Configuration: `.env` lives on the server + +The app reads its settings from `.env` in the app root (`dotenv`): database credentials and names, +`TWITCH_HIGHLIGHTS_ACCESS_KEY`, `HCAPTCHA_SECRET`, ... The Jenkins job **wrote that file on every +deploy** from its own credentials. The workflow never touches it: since the switchover the `.env` on +the server is the source of truth and is edited there (Plesk file manager), or the values move to +Plesk's *Node.js → Environment → Secrets*. Nothing secret is stored in Gitea for this app. + +The code also reads `CRAWLER_ACCESS_KEY`, which the Jenkins-generated `.env` never contained +(2026-11-16) - either unused or set elsewhere; not checked. + +## What the deploy touches - and what it must not + +| Path | How | Why it's needed at runtime | +|---|---|---| +| `dist/` | mirrored (`--delete` inside) | the compiled app | +| `src/` | mirrored | swagger-jsdoc reads `./src/models/**/*.router.ts` for `/docs` | +| `node_modules/` | mirrored, production dependencies only (`npm prune --omit=dev`) | runtime dependencies | +| `package.json`, `package-lock.json` | copied, no delete | (CommonJS - the app ran without them) | + +**Never touched**: `.env`, `logs/` (Winston), `tmp/` (Passenger's `restart.txt`), `public/` (Passenger's +document root; gitignored in this repo, and Jenkins never copied it either). + +## Node version + +Until 2026-11-16 Plesk ran this app on **Node 12.22.12**; with the switchover it moves to **26** +(`.nvmrc` 26, so CI builds and tests with the same version). + +Checked locally (2026-11-16), as **x86_64** like the runner (`podman --platform linux/amd64`): +`npm ci` on Node 26 downloads bcrypt 5.0.1's prebuilt N-API binary (`napi-v3`), `tsc`, the test, +build and prune pass, and the pruned bundle starts under Node 26 *and* under Node 12.22.12 (`/docs/` +200, `bcrypt` loads). So the order doesn't matter: the first deploy may land while Plesk still says +12, then switch Plesk to 26. Database queries were not exercised (no DB) - check one endpoint per +app after the switch. + +Don't test this on the Mac's default (arm64) containers: bcrypt 5.0.1 has no arm64 prebuilt, so npm +compiles it there, and that compile fails on Node 26 - a local artefact, not what the runner does. + +## Gitea settings + +The repo belongs to the **organisation `PlutoDev`**, so user-level settings of `Paddy` don't apply. +On the organisation (*PlutoDev → Settings → Actions*), for all PlutoDev repos: secrets +`DEPLOY_SSH_KEY` (the shared private deploy key `gitea-actions Paddy` - PlutoDev is a private project +now), `DEPLOY_KNOWN_HOSTS` (`[pmueller.me]:42069 ssh-ed25519 …`, same server); variables +`DEPLOY_HOST=pmueller.me`, `DEPLOY_PORT=42069`, `DEPLOY_USER=plesk-plutodev`. + +On this repository (*plutoapi-v2 → Settings → Actions → Variables*): + +| Variable | Value | +|---|---| +| `DEPLOY_PATH` | `/var/www/vhosts/plutodev.de/api.plutodev.de` | +| `DEPLOY_SMOKE_URL` | `https://api.plutodev.de/docs/` | + +## Switchover + +1. SSH for `plesk-plutodev` (was `/bin/false`, set to `/bin/bash` 2026-11-16, done): the shared public key + appended to `/var/www/vhosts/plutodev.de/.ssh/authorized_keys` (`.ssh` `700`, file `600`), the user + added to the key-only `Match User …` line in `/etc/ssh/sshd_config`. +2. Pause the Jenkins job (done 2026-11-16). Its credentials (`DB_USER`, `DB_PASSWORD`, `TWITCH_HIGHLIGHTS_ACCESS_KEY`, + `HCAPTCHA_SECRET`) can be deleted from Jenkins afterwards - they're in the server's `.env`. +3. **Fix file ownership** (as root): `ls -ld .` first (the folder keeps its group), then + `find . -mindepth 1 ! -user plesk-plutodev -exec chown -h plesk-plutodev:psacln {} +` - `-h` for + the symlinks in `node_modules/.bin/`. +4. Set the variables, open a PR → green run → merge → watch the deploy, check `/docs/`. +5. Plesk → *api.plutodev.de → Node.js*: version 26, restart; check `/docs/` and one endpoint per app. + +Rollback: revert the commit on `master`; the workflow deploys the previous state. + +## Cleaned up with the switchover (2026-11-16) + +- SonarQube is gone: `sonar-project.properties`, `jest-sonar-reporter`, the `--coverage + --testResultsProcessor` flags and the `jestSonar` config. + +## Checked locally (2026-11-16) + +- `actionlint`: no findings. +- `node:26-bookworm` (x86_64): `npm ci`, `tsc --noEmit`, `npm test`, build, `npm prune --omit=dev`; + the bundle then ran under Node 26 and Node 12 (see "Node version"). + +Not checked: the workflow on the real runner. diff --git a/package-lock.json b/package-lock.json index acf640a..66b64e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,6 @@ "@types/winston": "^2.4.4", "is-number": "^7.0.0", "jest": "^28.1.1", - "jest-sonar-reporter": "^2.0.0", "source-map-support": "^0.5.19", "ts-jest": "^28.0.5", "tslint": "^6.1.3", @@ -4584,18 +4583,6 @@ "node": ">=8" } }, - "node_modules/jest-sonar-reporter": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", - "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", - "dev": true, - "dependencies": { - "xml": "^1.0.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/jest-util": { "version": "28.1.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.1.1.tgz", @@ -6631,12 +6618,6 @@ "node": "^12.13.0 || ^14.15.0 || >=16" } }, - "node_modules/xml": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", - "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", - "dev": true - }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -10298,15 +10279,6 @@ } } }, - "jest-sonar-reporter": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", - "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", - "dev": true, - "requires": { - "xml": "^1.0.1" - } - }, "jest-util": { "version": "28.1.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.1.1.tgz", @@ -11896,12 +11868,6 @@ "signal-exit": "^3.0.7" } }, - "xml": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", - "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", - "dev": true - }, "y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index f13f055..8b013a9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "tsc && node ./dist/app.js", "build": "tsc", "debug": "export DEBUG=* && npm run start", - "test": "jest --coverage --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js" + "test": "jest" }, "keywords": [], "author": "", @@ -40,16 +40,9 @@ "@types/winston": "^2.4.4", "is-number": "^7.0.0", "jest": "^28.1.1", - "jest-sonar-reporter": "^2.0.0", "source-map-support": "^0.5.19", "ts-jest": "^28.0.5", "tslint": "^6.1.3", "typescript": "^4.9.4" - }, - "jestSonar": { - "sonar56x": true, - "reportPath": "testResults", - "reportFile": "sonar-report.xml", - "indent": 4 } } diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 0977066..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,6 +0,0 @@ -sonar.projectKey=pd-api -sonar.sources=src -sonar.tests=test -sonar.language=ts -sonar.javascript.lcov.reportPaths=coverage/lcov.info -sonar.testExecutionReportPaths=testResults/sonar-report.xml -- 2.54.0