Compare commits

...

10 Commits

Author SHA1 Message Date
810f295c8d chore: rename container volume
Some checks failed
Backup Docker Volumes (All Servers) / Backup devops (push) Has been cancelled
2025-10-28 15:35:04 +01:00
d7044b651f Merge branch 'main' of ssh://git.hashdot.co:2222/lars/homelab 2025-10-28 15:31:52 +01:00
5e20055aeb feat: add docmost to devops server 2025-10-28 15:31:33 +01:00
8d8cde5aa7 ci: rename git clone folder 2025-10-27 23:49:21 +01:00
80fcbe3fca ci: clone/pull repo 2025-10-27 23:44:13 +01:00
4c1754d0af ci: change COMPOSE_PATH 2025-10-27 23:40:10 +01:00
3f73b9352d ci: test deploy workflow 2025-10-27 23:35:34 +01:00
fc3005ecd5 fix: var names 2025-10-27 23:20:18 +01:00
3bc56f9f6d chore: test var name 2025-10-27 23:18:39 +01:00
a904f88077 ci: fix step names 2025-10-27 23:16:21 +01:00
3 changed files with 276 additions and 10 deletions

View File

@@ -22,11 +22,13 @@ jobs:
# exclude_volumes: "temp-volume,cache-volume"
fail-fast: false # Andere Server weiterlaufen lassen wenn einer fehlschlägt
name: Backup ${{ matrix.server.name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set server context
- name: Set server context for ${{ matrix.server.name }}
run: |
echo "SERVER_NAME=${{ matrix.server.name }}" >> $GITHUB_ENV
echo "SERVER_HOST=${{ matrix.server.host }}" >> $GITHUB_ENV
@@ -36,14 +38,14 @@ jobs:
echo "Host: ${{ matrix.server.host }}"
echo "User: ${{ matrix.server.user }}"
- name: Setup SSH
- name: Setup SSH for ${{ matrix.server.name }}
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ matrix.server.host }} >> ~/.ssh/known_hosts
- name: Upload backup script to server
- name: Upload backup script to ${{ matrix.server.name }}
run: |
echo "Uploading backup script to ${{ matrix.server.name }}..."
scp scripts/backup-servers/backup-docker-volumes.sh \
@@ -52,7 +54,7 @@ jobs:
ssh ${{ matrix.server.user }}@${{ matrix.server.host }} \
"chmod +x /tmp/backup-docker-volumes.sh"
- name: Create backup on remote server
- name: Create backup on ${{ matrix.server.name }}
run: |
BACKUP_DATE=$(date +%Y%m%d_%H%M%S)
echo "BACKUP_DATE=$BACKUP_DATE" >> $GITHUB_ENV
@@ -61,7 +63,7 @@ jobs:
ssh ${{ matrix.server.user }}@${{ matrix.server.host }} \
"BACKUP_DATE='$BACKUP_DATE' SERVER_NAME='${{ matrix.server.name }}' EXCLUDE_VOLUMES='${{ matrix.server.exclude_volumes }}' /tmp/backup-docker-volumes.sh"
- name: Download backups from remote server
- name: Download backups from ${{ matrix.server.name }}
run: |
mkdir -p backups/${{ matrix.server.name }}
@@ -72,14 +74,14 @@ jobs:
echo "Downloaded files:"
ls -lh backups/${{ matrix.server.name }}/$BACKUP_DATE/
- name: Upload backup artifacts
- name: Upload backup artifacts for ${{ matrix.server.name }}
uses: actions/upload-artifact@v3
with:
name: backup-${{ matrix.server.name }}-${{ env.BACKUP_DATE }}
path: backups/${{ matrix.server.name }}/${{ env.BACKUP_DATE }}
retention-days: 30
- name: Cleanup old backups on remote server
- name: Cleanup old backups on ${{ matrix.server.name }} (keep last 7 days)
if: always()
run: |
echo "Cleaning up old backups on ${{ matrix.server.name }}..."
@@ -91,7 +93,7 @@ jobs:
ls -lh ~/backups/ 2>/dev/null || echo "No backups found"
CLEANUP_EOF
- name: Cleanup temporary files
- name: Cleanup temporary files on ${{ matrix.server.name }}
if: always()
run: |
echo "Cleaning up temporary files on ${{ matrix.server.name }}..."

225
.gitea/workflows/deploy.yml Normal file
View File

@@ -0,0 +1,225 @@
name: Deploy Docker Compose
on:
workflow_dispatch:
inputs:
server:
description: 'Target server to deploy'
required: true
type: choice
options:
- devops
- production
- staging
- all
service:
description: 'Service to deploy (leave empty for all)'
required: false
type: string
default: ''
action:
description: 'Docker Compose action'
required: true
type: choice
options:
- up
- restart
- pull-and-up
- down
- logs
default: 'pull-and-up'
detach:
description: 'Run in detached mode'
required: false
type: boolean
default: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set deployment context
id: context
run: |
echo "=== Deployment Configuration ==="
echo "Server: ${{ inputs.server }}"
echo "Service: ${{ inputs.service || 'all services' }}"
echo "Action: ${{ inputs.action }}"
echo "Detached: ${{ inputs.detach }}"
# Git Repo URL (aus Gitea)
REPO_URL="https://git.hashdot.co/${{ github.repository }}.git"
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV
# Server-Konfiguration setzen
case "${{ inputs.server }}" in
devops)
echo "HOST=10.0.0.175" >> $GITHUB_ENV
echo "USER=lars" >> $GITHUB_ENV
echo "COMPOSE_PATH=/home/lars/devops/servers/production/devops" >> $GITHUB_ENV
;;
production)
echo "HOST=10.0.0.180" >> $GITHUB_ENV
echo "USER=lars" >> $GITHUB_ENV
echo "COMPOSE_PATH=/home/lars/production" >> $GITHUB_ENV
;;
staging)
echo "HOST=10.0.0.185" >> $GITHUB_ENV
echo "USER=lars" >> $GITHUB_ENV
echo "COMPOSE_PATH=/home/lars/staging" >> $GITHUB_ENV
;;
all)
echo "DEPLOY_ALL=true" >> $GITHUB_ENV
;;
esac
# Service-Parameter setzen
if [ -n "${{ inputs.service }}" ]; then
echo "SERVICE_ARG=${{ inputs.service }}" >> $GITHUB_ENV
else
echo "SERVICE_ARG=" >> $GITHUB_ENV
fi
# Detach-Flag setzen
if [ "${{ inputs.detach }}" == "true" ]; then
echo "DETACH_FLAG=-d" >> $GITHUB_ENV
else
echo "DETACH_FLAG=" >> $GITHUB_ENV
fi
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Füge alle möglichen Hosts hinzu
ssh-keyscan -H 10.0.0.175 >> ~/.ssh/known_hosts 2>/dev/null || true
ssh-keyscan -H 10.0.0.180 >> ~/.ssh/known_hosts 2>/dev/null || true
ssh-keyscan -H 10.0.0.185 >> ~/.ssh/known_hosts 2>/dev/null || true
- name: Deploy to single server
if: inputs.server != 'all'
run: |
echo "=== Deploying to ${{ inputs.server }} ==="
# Check ob Repo existiert, sonst clonen
ssh $USER@$HOST "
export COMPOSE_PATH='$COMPOSE_PATH'
export REPO_URL='$REPO_URL'
if [ -d \"\$COMPOSE_PATH/.git\" ]; then
echo 'Repository already exists, pulling latest changes...'
cd \$COMPOSE_PATH && git pull
else
echo 'Repository not found, cloning...'
PARENT_DIR=\$(dirname \$COMPOSE_PATH)
mkdir -p \$PARENT_DIR
cd \$PARENT_DIR
git clone \$REPO_URL \homelab
echo 'Repository cloned successfully'
fi
"
# Docker Compose Aktion ausführen
case "${{ inputs.action }}" in
up)
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose up $DETACH_FLAG $SERVICE_ARG"
;;
restart)
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose restart $SERVICE_ARG"
;;
pull-and-up)
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose pull $SERVICE_ARG && docker compose up $DETACH_FLAG $SERVICE_ARG"
;;
down)
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose down $SERVICE_ARG"
;;
logs)
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose logs --tail=100 $SERVICE_ARG"
;;
esac
- name: Deploy to all servers
if: inputs.server == 'all'
run: |
echo "=== Deploying to all servers ==="
# Definiere alle Server
declare -A SERVERS=(
["devops"]="lars@10.0.0.175:/home/lars/ghq/git.hashdot.co/lars/homelab/servers/production/devops"
["production"]="lars@10.0.0.180:/home/lars/production"
["staging"]="lars@10.0.0.185:/home/lars/staging"
)
for server in "${!SERVERS[@]}"; do
IFS=':' read -r user_host compose_path <<< "${SERVERS[$server]}"
echo ""
echo ">>> Deploying to $server..."
# Check ob Repo existiert, sonst clonen
ssh $user_host "
export COMPOSE_PATH='$compose_path'
export REPO_URL='$REPO_URL'
if [ -d \"\$COMPOSE_PATH/.git\" ]; then
echo 'Repository already exists, pulling latest changes...'
cd \$COMPOSE_PATH && git pull
else
echo 'Repository not found, cloning...'
PARENT_DIR=\$(dirname \$COMPOSE_PATH)
mkdir -p \$PARENT_DIR
cd \$PARENT_DIR
git clone \$REPO_URL \$(basename \$COMPOSE_PATH)
echo 'Repository cloned successfully'
fi
" || { echo "Failed to setup git for $server"; continue; }
# Docker Compose Aktion
case "${{ inputs.action }}" in
up)
ssh $user_host "cd $compose_path && docker compose up $DETACH_FLAG $SERVICE_ARG"
;;
restart)
ssh $user_host "cd $compose_path && docker compose restart $SERVICE_ARG"
;;
pull-and-up)
ssh $user_host "cd $compose_path && docker compose pull $SERVICE_ARG && docker compose up $DETACH_FLAG $SERVICE_ARG"
;;
down)
ssh $user_host "cd $compose_path && docker compose down $SERVICE_ARG"
;;
logs)
ssh $user_host "cd $compose_path && docker compose logs --tail=100 $SERVICE_ARG"
;;
esac
echo ">>> $server deployment completed"
done
- name: Verify deployment
if: inputs.action != 'down' && inputs.action != 'logs'
run: |
echo "=== Verifying deployment ==="
if [ "${{ inputs.server }}" != "all" ]; then
ssh $USER@$HOST "cd $COMPOSE_PATH && docker compose ps"
else
echo "Skipping verification for 'all' - check individual server logs"
fi
- name: Deployment summary
if: always()
run: |
echo "=== Deployment Summary ==="
echo "Server: ${{ inputs.server }}"
echo "Service: ${{ inputs.service || 'all services' }}"
echo "Action: ${{ inputs.action }}"
echo "Status: ${{ job.status }}"
echo ""
echo "Deployment completed at $(date)"

View File

@@ -78,7 +78,7 @@ services:
networks:
- gitea
volumes:
- minio-data:/data
- gitea-minio:/data
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 5s
@@ -86,6 +86,42 @@ services:
retries: 5
docmost:
image: docmost/docmost:latest
container_name: docmost
depends_on:
- docmost-db
- docmost-redis
environment:
APP_URL: "https://docs.hashdot.co"
APP_SECRET: "REPLACE_WITH_LONG_SECRET"
DATABASE_URL: "postgresql://docmost:docmost@docmost-db:5432/docmost?schema=public"
REDIS_URL: "redis://docmost-redis:6379"
ports:
- "3100:3000"
restart: unless-stopped
volumes:
- docmost:/app/data/storage
docmost-db:
image: postgres:16-alpine
container_name: docmost-db
environment:
POSTGRES_DB: docmost
POSTGRES_USER: docmost
POSTGRES_PASSWORD: docmost
restart: unless-stopped
volumes:
- docmost-database:/var/lib/postgresql/data
docmost-redis:
image: redis:7.2-alpine
container_name: docmost-redis
restart: unless-stopped
volumes:
- docmost-redis:/data
networks:
gitea:
external: false
@@ -95,4 +131,7 @@ volumes:
gitea-runner-data:
gitea-database:
gitea-data:
minio-data:
gitea-minio:
docmost:
docmost-database:
docmost-redis: