112 lines
2.5 KiB
Markdown
112 lines
2.5 KiB
Markdown
# Example App - Forgejo CI/CD Template
|
|
|
|
Diese Vorlage zeigt, wie du eine Anwendung mit Forgejo Actions automatisch auf deinen Server deployst.
|
|
|
|
## Quick Start
|
|
|
|
### 1. Neues Repository in Forgejo erstellen
|
|
|
|
Gehe zu https://git.magholder.click und erstelle ein neues Repository.
|
|
|
|
### 2. Diese Dateien kopieren
|
|
|
|
```bash
|
|
# In dein Projektverzeichnis kopieren
|
|
cp -r templates/example-app/* mein-projekt/
|
|
cd mein-projekt
|
|
git init
|
|
git remote add origin git@git.magholder.click:USERNAME/mein-projekt.git
|
|
```
|
|
|
|
### 3. Repository-Variablen setzen
|
|
|
|
In Forgejo: **Repository Settings → Actions → Variables**
|
|
|
|
| Variable | Wert | Beschreibung |
|
|
|----------|------|--------------|
|
|
| `APP_NAME` | `mein-projekt` | Name der App (für Container und Pfade) |
|
|
| `DOMAIN` | `mein-projekt.magholder.click` | Domain für Traefik |
|
|
|
|
### 4. SSH-Key als Secret hinzufügen
|
|
|
|
In Forgejo: **Repository Settings → Actions → Secrets**
|
|
|
|
| Secret | Wert |
|
|
|--------|------|
|
|
| `SSH_PRIVATE_KEY` | Inhalt deines SSH Private Keys |
|
|
|
|
**SSH-Key generieren (falls nicht vorhanden):**
|
|
|
|
```bash
|
|
ssh-keygen -t ed25519 -f ~/.ssh/forgejo-deploy -N ""
|
|
|
|
# Public Key auf Server kopieren
|
|
ssh-copy-id -i ~/.ssh/forgejo-deploy.pub root@194.163.164.113
|
|
|
|
# Private Key als Secret verwenden
|
|
cat ~/.ssh/forgejo-deploy
|
|
```
|
|
|
|
### 5. Pushen und deployen
|
|
|
|
```bash
|
|
git add .
|
|
git commit -m "Initial commit"
|
|
git push -u origin main
|
|
```
|
|
|
|
Die Action wird automatisch gestartet und deployt deine App!
|
|
|
|
## Anpassen
|
|
|
|
### Eigenes Dockerfile
|
|
|
|
Ersetze das `Dockerfile` mit deinem eigenen Build-Prozess.
|
|
|
|
### Andere Ports
|
|
|
|
Wenn deine App nicht auf Port 80 läuft, füge in `docker-compose.yml` hinzu:
|
|
|
|
```yaml
|
|
labels:
|
|
- "traefik.http.services.${APP_NAME}.loadbalancer.server.port=3000"
|
|
```
|
|
|
|
### Umgebungsvariablen
|
|
|
|
Füge in `docker-compose.yml` hinzu:
|
|
|
|
```yaml
|
|
services:
|
|
app:
|
|
environment:
|
|
- DATABASE_URL=${DATABASE_URL}
|
|
```
|
|
|
|
Und setze `DATABASE_URL` als Secret in Forgejo.
|
|
|
|
## Workflow-Datei
|
|
|
|
Die CI/CD Pipeline ist in `.forgejo/workflows/deploy.yml` definiert:
|
|
|
|
1. **Checkout** - Code auschecken
|
|
2. **SSH Setup** - SSH-Key für Server-Zugang einrichten
|
|
3. **Deploy** - Dateien kopieren und `docker compose up -d`
|
|
|
|
## Troubleshooting
|
|
|
|
### Action läuft nicht
|
|
|
|
- Ist der Runner aktiv? Prüfe unter **Site Administration → Actions → Runners**
|
|
- Sind `runs-on: docker` Labels korrekt?
|
|
|
|
### SSH-Fehler
|
|
|
|
- Ist der Public Key auf dem Server in `~/.ssh/authorized_keys`?
|
|
- Stimmt der Private Key im Secret?
|
|
|
|
### Container startet nicht
|
|
|
|
```bash
|
|
ssh root@194.163.164.113 "docker logs APP_NAME"
|
|
```
|