Update .env.example for local and production database configurations, ensuring clarity on usage. Modify .gitattributes to enforce LF line endings for shell scripts. Enhance README.md with Docker and Coolify setup instructions for production deployment.

This commit is contained in:
2026-05-23 12:43:51 +02:00
parent 6577db475a
commit 054141020d
10 changed files with 624 additions and 3 deletions
+140
View File
@@ -0,0 +1,140 @@
# FlixCooks auf Coolify deployen
Zwei getrennte Ressourcen: **PostgreSQL** und **PHP-Web-App** (dieses Repo als Dockerfile).
## Architektur
```
┌──────────────────── Coolify Server ────────────────────┐
│ │
│ ┌──────────────┐ ┌─────────────────────────┐ │
│ │ PostgreSQL │◄────────│ FlixCooks (dieses Image) │ │
│ │ (Service B) │ :5432 │ Apache + PHP 8.3 │ │
│ └──────────────┘ │ Port 80 → Traefik/HTTPS │ │
│ ▲ └─────────────────────────┘ │
│ │ ▲ │
│ Volume (Daten) Volume optional: │
│ data/ (site.json) │
└─────────────────────────────────────────────────────────┘
```
Die App startet **nicht**, wenn `DATABASE_URL` fehlt oder Postgres nicht erreichbar ist.
---
## 1. PostgreSQL in Coolify anlegen
1. Neues **Database** → PostgreSQL (16).
2. Notieren:
- Benutzer, Passwort, Datenbankname
- **Internal URL** (Host ist oft der Service-Name, z.B. `postgresql-xxxxx` oder was Coolify anzeigt)
3. Format für die App:
```text
postgresql://USER:PASSWORD@HOST:5432/DATABASE
```
Beispiel (Platzhalter durch Coolify-Werte ersetzen):
```text
postgresql://flixcooks:geheim@postgresql-flixcooks:5432/flixcooks
```
**Wichtig:** In der App den **internen** Hostnamen verwenden (gleiches Coolify-Netzwerk), nicht `127.0.0.1`.
---
## 2. Web-App in Coolify anlegen
1. Neues **Application** → Build Pack: **Dockerfile** (Repository dieses Projekts).
2. Dockerfile-Pfad: `Dockerfile` (Root).
3. Port: **80** (Container exponiert Apache auf 80).
4. Health Check (optional, empfohlen):
- Path: `/health.php`
- Erwartet HTTP 200 mit `{"status":"ok"}`
### Environment Variables (Pflicht)
| Variable | Beschreibung |
|----------|----------------|
| `DATABASE_URL` | Interne Postgres-URL von Coolify |
| `FLIXCOOKS_ADMIN_KEY` | Starkes Passwort für `/admin.php` |
### Environment Variables (optional)
| Variable | Default | Beschreibung |
|----------|---------|----------------|
| `RUN_DB_SEED` | `false` | Einmalig `true` setzen → importiert `data/recipes.json` beim Start |
| `DB_WAIT_MAX_TRIES` | `30` | Warteversuche bis Postgres da ist (à 2 s) |
Nach dem ersten erfolgreichen Deploy: `RUN_DB_SEED` wieder auf `false` oder entfernen.
### Persistent Storage (empfohlen)
Mount für Impressum/Datenschutz (`data/site.json`):
| Mount Path (Container) | Inhalt |
|------------------------|--------|
| `/var/www/html/data` | `site.json` bleibt nach Redeploy erhalten |
Rezepte liegen in Postgres **kein** Volume für Rezepte nötig.
---
## 3. Erstes Deployment (Checkliste)
1. Postgres-Service läuft (healthy).
2. App mit `DATABASE_URL` + `FLIXCOOKS_ADMIN_KEY` deployen.
3. Einmalig `RUN_DB_SEED=true` → Redeploy → Rezepte prüfen auf der Startseite.
4. `RUN_DB_SEED` deaktivieren.
5. `https://deine-domain/admin.php` testen.
6. `https://deine-domain/health.php``{"status":"ok"}`.
### Schema ohne Seed
Tabellen legt der Container beim Start automatisch an (`scripts/schema.sql` via `require_database()`). Ohne Seed ist die DB leer → Seite lädt, aber keine Rezepte, bis du im Admin anlegst oder seedest.
---
## 4. Lokaler Test vor Coolify
```bash
# Starkes Admin-Passwort setzen
export FLIXCOOKS_ADMIN_KEY="dein-geheimes-passwort"
# Mit Seed
export RUN_DB_SEED=true
docker compose build
docker compose up -d
curl http://127.0.0.1:8080/health.php
```
---
## 5. Updates / Redeploy
- Neues Image bauen lassen (Git push → Coolify rebuild).
- Postgres-Volume bleibt → Daten bleiben.
- `data/`-Volume bleibt → Site-Settings bleiben.
- Kein manuelles `db-seed` bei Updates, außer du leerst die DB bewusst.
---
## 6. Sicherheit
- `.env` wird **nicht** ins Image kopiert (`.dockerignore`).
- Admin-Key **nur** über `FLIXCOOKS_ADMIN_KEY` in Coolify, nicht in `.htaccess` für Production verlassen.
- Postgres nicht öffentlich exponieren, wenn nicht nötig (nur interne URL).
---
## 7. Troubleshooting
| Problem | Lösung |
|---------|--------|
| Container startet nicht | Logs: DB nicht erreichbar → `DATABASE_URL` Host/Passwort prüfen |
| 503 „Datenbank nicht verfügbar“ | Gleiches Netzwerk in Coolify? Internal URL? |
| Leere Seite, Health OK | `RUN_DB_SEED=true` einmalig oder Admin-Rezepte anlegen |
| Admin geht nicht | `FLIXCOOKS_ADMIN_KEY` gesetzt? |
| `site.json` verloren nach Deploy | Volume auf `/var/www/html/data` mounten |