Portainer-Deployment: Env-Interpolation statt env_file, lokales Webhook-Test-Skript
- docker-compose.yml: Variablen per Interpolation (lokal aus .env, in Portainer aus Stack-Env) - tools/test-webhook.mjs: signierte Fake-Testzustellung gegen die lokale Instanz - README: Portainer-Anleitung präzisiert (Git-Auth für privates Repo, Pull and redeploy) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// Simuliert eine Gitea-Testzustellung gegen die lokale Bot-Instanz.
|
||||
// Nutzung: node tools/test-webhook.mjs (Bot muss laufen: npm run dev)
|
||||
import 'dotenv/config';
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
const secret = process.env.GITEA_WEBHOOK_SECRET;
|
||||
if (!secret) {
|
||||
console.error('GITEA_WEBHOOK_SECRET fehlt in der .env');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const port = process.env.HTTP_PORT || 3080;
|
||||
const url = `http://localhost:${port}/webhooks/gitea`;
|
||||
|
||||
const sha = crypto.randomBytes(20).toString('hex'); // zufällige SHA → Dedupe greift nicht
|
||||
const payload = JSON.stringify({
|
||||
ref: 'refs/heads/main',
|
||||
compare_url: 'https://git.d4rkst3r.de/D4rkst3r/EcoGame',
|
||||
repository: {
|
||||
full_name: 'D4rkst3r/EcoGame (Test)',
|
||||
html_url: 'https://git.d4rkst3r.de/D4rkst3r/EcoGame',
|
||||
},
|
||||
pusher: { username: 'D4rkst3r' },
|
||||
sender: { avatar_url: null },
|
||||
commits: [
|
||||
{
|
||||
id: sha,
|
||||
message: 'Testzustellung — wenn du das im Discord siehst, funktioniert der Commit-Feed 🎉',
|
||||
url: `https://git.d4rkst3r.de/D4rkst3r/EcoGame/commit/${sha}`,
|
||||
author: { name: 'D4rkst3r', username: 'D4rkst3r' },
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const signature = crypto.createHmac('sha256', secret).update(payload).digest('hex');
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'x-gitea-event': 'push',
|
||||
'x-gitea-signature': signature,
|
||||
},
|
||||
body: payload,
|
||||
});
|
||||
|
||||
console.log(`${res.status} →`, await res.json());
|
||||
Reference in New Issue
Block a user