Beispiel-Deploy-Workflow für Dienst-Repos
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03e83d68b8
commit
beba2d7ef1
1 file changed
+56
@@ -0,0 +1,56 @@
|
||||
# Beispiel: .gitea/workflows/deploy.yml im Repo eines Dienstes
|
||||
#
|
||||
# Voraussetzungen (Setup mit create-deploy-user.py --project-path owner/repo):
|
||||
# Variable deploy_user – Deploy-User (wird vom Skript gesetzt)
|
||||
# Secret deploy_pass – Passwort/App-Token des Users (wird vom Skript gesetzt)
|
||||
# Variable deploy_host – Hostname/IP des Zielservers (manuell setzen)
|
||||
#
|
||||
# Das Repo enthält docker-compose.yml (und optional docker-compose.override.yml)
|
||||
# im Wurzelverzeichnis; sie landen in ~/deployment auf dem Server.
|
||||
name: deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
# Nie zwei Deploys gleichzeitig für denselben Dienst
|
||||
concurrency:
|
||||
group: deploy-${{ gitea.repository }}
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
DEPLOY_USER: ${{ vars.deploy_user }}
|
||||
DEPLOY_HOST: ${{ vars.deploy_host }}
|
||||
SSHPASS: ${{ secrets.deploy_pass }}
|
||||
SSH_OPTS: -o StrictHostKeyChecking=accept-new -o PubkeyAuthentication=no
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Compose-Datei validieren
|
||||
run: docker compose -f docker-compose.yml config --quiet
|
||||
|
||||
- name: Tools installieren
|
||||
run: sudo apt-get update -qq && sudo apt-get install -y -qq sshpass rsync
|
||||
|
||||
- name: Dateien nach ~/deployment synchronisieren
|
||||
run: |
|
||||
sshpass -e rsync -az --delete \
|
||||
--exclude '.git' --exclude '.gitea' --exclude '.env' \
|
||||
-e "ssh $SSH_OPTS" \
|
||||
./ "$DEPLOY_USER@$DEPLOY_HOST:deployment/"
|
||||
|
||||
- name: Deploy (pull → build → up)
|
||||
run: |
|
||||
sshpass -e ssh $SSH_OPTS "$DEPLOY_USER@$DEPLOY_HOST" \
|
||||
"sudo /usr/local/bin/docker-deploy.sh $DEPLOY_USER deploy"
|
||||
|
||||
- name: Logs bei Fehler
|
||||
if: failure()
|
||||
run: |
|
||||
sshpass -e ssh $SSH_OPTS "$DEPLOY_USER@$DEPLOY_HOST" \
|
||||
"sudo /usr/local/bin/docker-deploy.sh $DEPLOY_USER logs" || true
|
||||
Reference in new issue
Block a user