This commit is contained in:
Gunnar Magholder 2026-03-05 15:57:52 +01:00
commit 54f7f59fd5
4 changed files with 183 additions and 0 deletions

9
Dockerfile Normal file
View file

@ -0,0 +1,9 @@
# Beispiel Dockerfile für eine einfache Web-App
# Ersetze dies mit deinem eigenen Dockerfile
FROM nginx:alpine
# Statische Dateien kopieren
COPY public/ /usr/share/nginx/html/
EXPOSE 80

112
README.md Normal file
View file

@ -0,0 +1,112 @@
# 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"
```

20
docker-compose.yml Normal file
View file

@ -0,0 +1,20 @@
# Docker Compose für Traefik Deployment
# APP_NAME und DOMAIN werden über Forgejo Repository-Variablen gesetzt
services:
app:
build: .
# Oder: image: dein-image:latest
container_name: ${APP_NAME:-example-app}
restart: unless-stopped
networks:
- traefik-public
labels:
- "traefik.enable=true"
- "traefik.http.routers.${APP_NAME:-example-app}.rule=Host(`${DOMAIN:-example.magholder.click}`)"
- "traefik.http.routers.${APP_NAME:-example-app}.entrypoints=websecure"
- "traefik.http.routers.${APP_NAME:-example-app}.tls.certresolver=letsencrypt"
networks:
traefik-public:
external: true

42
public/index.html Normal file
View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example App</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
text-align: center;
padding: 2rem;
}
h1 { font-size: 3rem; margin-bottom: 0.5rem; }
p { font-size: 1.2rem; opacity: 0.9; }
.deployed {
margin-top: 2rem;
padding: 1rem 2rem;
background: rgba(255,255,255,0.2);
border-radius: 8px;
font-size: 0.9rem;
}
</style>
</head>
<body>
<div class="container">
<h1>Example App</h1>
<p>Erfolgreich deployed via Forgejo Actions!</p>
<div class="deployed">
Push auf main → Automatisches Deployment
</div>
</div>
</body>
</html>