fix: Gitea Traefik routing and connection pool optimization
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
This commit is contained in:
162
deployment/docs/guides/production-database-connection.md
Normal file
162
deployment/docs/guides/production-database-connection.md
Normal file
@@ -0,0 +1,162 @@
|
||||
# Production Database Connection Guide
|
||||
|
||||
## Übersicht
|
||||
|
||||
Die Production-Application verbindet sich mit der separaten PostgreSQL-Production-Datenbank über das `postgres-production-internal` Network.
|
||||
|
||||
## Network-Konfiguration
|
||||
|
||||
### Production Application Stack
|
||||
|
||||
Die Production-Application-Services (`php`, `queue-worker`, `scheduler`) müssen mit dem `postgres-production-internal` Network verbunden sein.
|
||||
|
||||
**Konfiguration**:
|
||||
- **Datei**: `docker-compose.postgres-override.yml`
|
||||
- **Network**: `postgres-production-internal`
|
||||
- **Verbindung**: Services werden diesem Network hinzugefügt
|
||||
|
||||
### Docker Compose Usage
|
||||
|
||||
```bash
|
||||
# Production Stack mit Datenbank-Verbindung starten
|
||||
docker compose -f docker-compose.base.yml \
|
||||
-f docker-compose.production.yml \
|
||||
-f docker-compose.postgres-override.yml \
|
||||
up -d
|
||||
```
|
||||
|
||||
## Services
|
||||
|
||||
Die folgenden Services werden mit dem `postgres-production-internal` Network verbunden:
|
||||
|
||||
1. **php** - PHP-FPM Application Container
|
||||
2. **queue-worker** - Background Job Processor
|
||||
3. **scheduler** - Cron Job Executor
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Die Application verwendet folgende Environment-Variablen für die Datenbank-Verbindung:
|
||||
|
||||
```env
|
||||
DB_HOST=postgres-production
|
||||
DB_PORT=5432
|
||||
DB_DATABASE=michaelschiemer
|
||||
DB_USERNAME=postgres
|
||||
DB_PASSWORD_FILE=/run/secrets/db_user_password
|
||||
```
|
||||
|
||||
**Wichtig**: `DB_PASSWORD` wird über Docker Secrets geladen (`DB_PASSWORD_FILE`).
|
||||
|
||||
## Verifizierung
|
||||
|
||||
### 1. Network-Verbindung prüfen
|
||||
|
||||
```bash
|
||||
# Prüfe, ob php-Container im Network ist
|
||||
docker network inspect postgres-production-internal | grep php
|
||||
|
||||
# Erwartet: Container-Name sollte erscheinen
|
||||
```
|
||||
|
||||
### 2. Datenbank-Verbindung testen
|
||||
|
||||
```bash
|
||||
# Von php-Container aus
|
||||
docker exec php php -r "
|
||||
\$dsn = 'pgsql:host=postgres-production;port=5432;dbname=michaelschiemer';
|
||||
\$pdo = new PDO(\$dsn, 'postgres', getenv('DB_PASSWORD'));
|
||||
echo 'Connection successful: ' . \$pdo->query('SELECT version()')->fetchColumn();
|
||||
"
|
||||
```
|
||||
|
||||
### 3. Network-Isolation verifizieren
|
||||
|
||||
```bash
|
||||
# Prüfe, ob Production-App NICHT auf Staging-DB zugreifen kann
|
||||
docker exec php nc -zv postgres-staging 5432
|
||||
|
||||
# Erwartet: Connection refused oder timeout (keine Verbindung möglich)
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Problem: Container kann Datenbank nicht erreichen
|
||||
|
||||
**Lösung**:
|
||||
1. Prüfe, ob `postgres-production-internal` Network existiert:
|
||||
```bash
|
||||
docker network ls | grep postgres-production-internal
|
||||
```
|
||||
|
||||
2. Prüfe, ob Container im Network ist:
|
||||
```bash
|
||||
docker network inspect postgres-production-internal
|
||||
```
|
||||
|
||||
3. Prüfe, ob PostgreSQL-Production-Stack läuft:
|
||||
```bash
|
||||
docker ps | grep postgres-production
|
||||
```
|
||||
|
||||
### Problem: DB_HOST nicht korrekt
|
||||
|
||||
**Lösung**:
|
||||
1. Prüfe Environment-Variablen:
|
||||
```bash
|
||||
docker exec php printenv | grep DB_
|
||||
```
|
||||
|
||||
2. Prüfe `.env`-Datei im Application-Stack:
|
||||
```bash
|
||||
cat ~/deployment/stacks/production/.env | grep DB_
|
||||
```
|
||||
|
||||
3. Prüfe Ansible-Template:
|
||||
- `deployment/ansible/templates/application.env.j2`
|
||||
- Sollte `DB_HOST=postgres-production` für Production setzen
|
||||
|
||||
## Migration von alter Konfiguration
|
||||
|
||||
Falls die Production-Application noch die alte `postgres` (geteilte Datenbank) verwendet:
|
||||
|
||||
1. **Backup erstellen**:
|
||||
```bash
|
||||
cd ~/deployment/stacks/postgresql
|
||||
docker exec postgres-backup /scripts/backup.sh
|
||||
```
|
||||
|
||||
2. **PostgreSQL-Production-Stack starten**:
|
||||
```bash
|
||||
cd ~/deployment/stacks/postgresql-production
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
3. **Datenbank migrieren** (siehe `migrate-to-separate-databases.md`)
|
||||
|
||||
4. **Application-Stack aktualisieren**:
|
||||
- `.env`-Datei: `DB_HOST=postgres-production`
|
||||
- Network: `postgres-production-internal` hinzufügen
|
||||
|
||||
5. **Stack neu starten**:
|
||||
```bash
|
||||
cd ~/deployment/stacks/production
|
||||
docker compose -f docker-compose.base.yml \
|
||||
-f docker-compose.production.yml \
|
||||
-f docker-compose.postgres-override.yml \
|
||||
up -d
|
||||
```
|
||||
|
||||
## Ansible-Integration
|
||||
|
||||
Das Ansible-Setup konfiguriert die Datenbank-Verbindung automatisch:
|
||||
|
||||
- **Template**: `deployment/ansible/templates/application.env.j2`
|
||||
- **Variable**: `db_host_default: "postgres-production"` (in `group_vars/production/vars.yml`)
|
||||
- **Network**: Wird über `docker-compose.postgres-override.yml` konfiguriert
|
||||
|
||||
## Weitere Ressourcen
|
||||
|
||||
- **PostgreSQL-Production-Stack**: `deployment/stacks/postgresql-production/README.md`
|
||||
- **Migrations-Guide**: `deployment/docs/guides/migrate-to-separate-databases.md`
|
||||
- **Staging-Datenbank**: `deployment/docs/guides/staging-test-plan.md`
|
||||
|
||||
Reference in New Issue
Block a user