45 lines
1.3 KiB
YAML
45 lines
1.3 KiB
YAML
name: CD – staged deploy
|
||
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
|
||
jobs:
|
||
detect-changes:
|
||
runs-on: deploy
|
||
outputs:
|
||
services: ${{ steps.set-matrix.outputs.services }}
|
||
steps:
|
||
- name: Fix git ownership and Fetch
|
||
run: |
|
||
git config --global --add safe.directory /srv/homelab
|
||
cd /srv/homelab
|
||
git fetch origin main
|
||
git reset --hard origin/main
|
||
|
||
- id: set-matrix
|
||
name: Generate service list
|
||
run: |
|
||
cd /srv/homelab
|
||
# Собираем список папок в JSON-массив для матрицы
|
||
DIRS=$(git diff --name-only HEAD~1 HEAD | cut -d/ -f1 | sort -u | xargs -I{} sh -c 'if [ -f {}/compose.yaml ] || [ -f {}/docker-compose.yaml ]; then echo \"{}\"; fi' | paste -sd,)
|
||
echo "services=[$DIRS]" >> $GITEA_OUTPUT
|
||
|
||
apply-deploy:
|
||
needs: detect-changes
|
||
if: needs.detect-changes.outputs.services != '[]'
|
||
runs-on: deploy
|
||
strategy:
|
||
matrix:
|
||
service: ${{ fromJson(needs.detect-changes.outputs.services) }}
|
||
fail-fast: false
|
||
|
||
name: Deploy ${{ matrix.service }}
|
||
steps:
|
||
- name: Deploy Service
|
||
run: |
|
||
cd /srv/homelab/${{ matrix.service }}
|
||
echo "Syncing and starting ${{ matrix.service }}..."
|
||
docker compose pull
|
||
docker compose up -d --remove-orphans
|