mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-17 16:46:51 +02:00
66 lines
2.5 KiB
YAML
66 lines
2.5 KiB
YAML
name: Deploy to Swarm
|
|
|
|
on:
|
|
push:
|
|
paths:
|
|
- 'docker/**'
|
|
|
|
jobs:
|
|
fact-finding:
|
|
name: Detect changed environments
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
changed_envs: ${{ steps.detect.outputs.changed_envs }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Determine which environments changed
|
|
id: detect
|
|
run: |
|
|
echo "changed_envs=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^docker/' | cut -d/ -f2 | sort -u | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
|
|
deploy:
|
|
name: Deploy
|
|
runs-on: ubuntu-latest
|
|
needs: fact-finding
|
|
strategy:
|
|
matrix:
|
|
env: [ test ]
|
|
environment: ${{ matrix.env }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Exit if this environment wasn't changed
|
|
run: |
|
|
echo "Changed envs: '${{ needs.fact-finding.outputs.changed_envs }}'"
|
|
if [[ ! " ${{ needs.fact-finding.outputs.changed_envs }} " =~ " ${{ matrix.env }} " ]]; then
|
|
echo "Environment '${{ matrix.env }}' was not modified. Skipping."
|
|
exit 0
|
|
fi
|
|
- name: Build & push Nginx image to GHCR
|
|
if: steps.detect.outputs.changed_envs != ''
|
|
run: |
|
|
docker build -t ghcr.io/2martens/docker-nginx:${{ matrix.env }} docker/${{ matrix.env }}/nginx
|
|
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u 2martens --password-stdin
|
|
docker push ghcr.io/2martens/docker-nginx:${{ matrix.env }}
|
|
- name: Copy files to remote
|
|
if: steps.detect.outputs.changed_envs != ''
|
|
uses: burnett01/rsync-deployments@7.0.2
|
|
with:
|
|
switches: -az -r --del
|
|
path: docker/${{ matrix.env }}/stack-config/.
|
|
remote_path: ~/tmp/stack-config
|
|
remote_host: ${{ secrets.DEPLOY_HOST }}
|
|
remote_port: ${{ secrets.DEPLOY_PORT }}
|
|
remote_user: ${{ secrets.DEPLOY_USER }}
|
|
remote_key: ${{ secrets.DEPLOY_KEY }}
|
|
- name: Deploy applications
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: ${{ secrets.DEPLOY_USER }}
|
|
key: ${{ secrets.DEPLOY_KEY }}
|
|
script: |
|
|
docker pull ghcr.io/2martens/docker-nginx:${{ matrix.env }}
|
|
docker service update --image ghcr.io/2martens/docker-nginx:${{ matrix.env }} nginx-proxy
|
|
for f in ~/tmp/stack-config/*.yaml; do
|
|
NAME=$(basename "$f" .yaml)
|
|
docker stack deploy -c "$f" "$NAME"
|
|
done |