Deploy with Gitea Actions instead of Jenkins on Node 26, drop SonarQube #18
No files matched your search
@@ -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"
|
||||||
@@ -9,4 +9,3 @@ logs/
|
|||||||
node_modules/
|
node_modules/
|
||||||
public/
|
public/
|
||||||
coverage/
|
coverage/
|
||||||
testResults/
|
|
||||||
+108
@@ -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.
|
||||||
Generated
-34
@@ -36,7 +36,6 @@
|
|||||||
"@types/winston": "^2.4.4",
|
"@types/winston": "^2.4.4",
|
||||||
"is-number": "^7.0.0",
|
"is-number": "^7.0.0",
|
||||||
"jest": "^28.1.1",
|
"jest": "^28.1.1",
|
||||||
"jest-sonar-reporter": "^2.0.0",
|
|
||||||
"source-map-support": "^0.5.19",
|
"source-map-support": "^0.5.19",
|
||||||
"ts-jest": "^28.0.5",
|
"ts-jest": "^28.0.5",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
@@ -4584,18 +4583,6 @@
|
|||||||
"node": ">=8"
|
"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": {
|
"node_modules/jest-util": {
|
||||||
"version": "28.1.1",
|
"version": "28.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.1.1.tgz",
|
"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": "^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": {
|
"node_modules/y18n": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"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": {
|
"jest-util": {
|
||||||
"version": "28.1.1",
|
"version": "28.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-28.1.1.tgz",
|
||||||
@@ -11896,12 +11868,6 @@
|
|||||||
"signal-exit": "^3.0.7"
|
"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": {
|
"y18n": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
|
|||||||
+1
-8
@@ -7,7 +7,7 @@
|
|||||||
"start": "tsc && node ./dist/app.js",
|
"start": "tsc && node ./dist/app.js",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"debug": "export DEBUG=* && npm run start",
|
"debug": "export DEBUG=* && npm run start",
|
||||||
"test": "jest --coverage --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
@@ -40,16 +40,9 @@
|
|||||||
"@types/winston": "^2.4.4",
|
"@types/winston": "^2.4.4",
|
||||||
"is-number": "^7.0.0",
|
"is-number": "^7.0.0",
|
||||||
"jest": "^28.1.1",
|
"jest": "^28.1.1",
|
||||||
"jest-sonar-reporter": "^2.0.0",
|
|
||||||
"source-map-support": "^0.5.19",
|
"source-map-support": "^0.5.19",
|
||||||
"ts-jest": "^28.0.5",
|
"ts-jest": "^28.0.5",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"typescript": "^4.9.4"
|
"typescript": "^4.9.4"
|
||||||
},
|
|
||||||
"jestSonar": {
|
|
||||||
"sonar56x": true,
|
|
||||||
"reportPath": "testResults",
|
|
||||||
"reportFile": "sonar-report.xml",
|
|
||||||
"indent": 4
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
|
||||||
Reference in new issue
Block a user