65 lines
2.2 KiB
Markdown
65 lines
2.2 KiB
Markdown
# GitHub Actions — Deploy Workflow
|
|
|
|
## Übersicht
|
|
|
|
Der Workflow `deploy.yml` läuft automatisch bei jedem Push auf `main`.
|
|
|
|
- **Job 1 `build`**: Installiert Dependencies und baut das Frontend — rein zum Kompilierungs-Check.
|
|
- **Job 2 `deploy`**: Kopiert den Quellcode per SCP auf den Server und startet Docker neu. **Erfordert manuellen Approval** über das GitHub Environment `production`.
|
|
|
|
---
|
|
|
|
## 1. SSH Key als Secret hinterlegen
|
|
|
|
### SSH Key generieren (falls noch kein dedizierter Key vorhanden)
|
|
|
|
```bash
|
|
ssh-keygen -t ed25519 -C "github-actions-itnexus" -f ~/.ssh/github_actions_itnexus
|
|
```
|
|
|
|
Den Public Key auf dem Server hinterlegen:
|
|
|
|
```bash
|
|
cat ~/.ssh/github_actions_itnexus.pub | ssh root@192.168.0.194 "cat >> ~/.ssh/authorized_keys"
|
|
```
|
|
|
|
### Secrets in GitHub eintragen
|
|
|
|
Gehe zu: **Repository → Settings → Secrets and variables → Actions → New repository secret**
|
|
|
|
| Secret Name | Wert |
|
|
|---|---|
|
|
| `SSH_PRIVATE_KEY` | Inhalt von `~/.ssh/github_actions_itnexus` (Private Key, beginnt mit `-----BEGIN OPENSSH PRIVATE KEY-----`) |
|
|
| `SERVER_IP` | `192.168.0.194` |
|
|
|
|
---
|
|
|
|
## 2. Production Environment mit Required Reviewer einrichten
|
|
|
|
### Environment erstellen
|
|
|
|
1. Gehe zu: **Repository → Settings → Environments**
|
|
2. Klicke auf **New environment**
|
|
3. Name: `production` (exakt so, wie im Workflow hinterlegt)
|
|
4. Klicke auf **Configure environment**
|
|
|
|
### Required Reviewers setzen
|
|
|
|
1. Aktiviere **Required reviewers**
|
|
2. Füge `Simon Grüssing` (GitHub-Username) als Reviewer hinzu
|
|
3. Optional: **Prevent self-review** aktivieren wenn ein weiterer Reviewer vorhanden ist
|
|
4. Speichern mit **Save protection rules**
|
|
|
|
---
|
|
|
|
## 3. Approval-Prozess
|
|
|
|
1. Push auf `main` → Job `build` startet automatisch und läuft durch.
|
|
2. Nach erfolgreichem Build: Job `deploy` wartet auf Approval.
|
|
3. GitHub schickt eine **E-Mail-Benachrichtigung** an alle eingetragenen Reviewer.
|
|
4. Reviewer klickt in der E-Mail oder direkt im GitHub Actions Tab auf den Workflow-Run.
|
|
5. Unter **"This workflow run is waiting for a required review"** → **Review deployments** → Haken bei `production` setzen → **Approve and deploy**.
|
|
6. Erst dann startet der Deployment-Job.
|
|
|
|
> Tipp: Den Workflow-Status siehst du unter **Repository → Actions**.
|