Deploy production #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy production | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Shutdown old instance over ssh | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.DB_SSH_HOST }} | |
| username: ${{ secrets.DB_SSH_USER }} | |
| key: ${{ secrets.DB_SSH_KEY }} | |
| script: | | |
| set -euo pipefail | |
| if [ -d /home/${{ secrets.DB_SSH_USER }}/kcidb-ng ] && [ -f /home/${{ secrets.DB_SSH_USER }}/kcidb-ng/docker-compose.yaml ]; then | |
| cd /home/${{ secrets.DB_SSH_USER }}/kcidb-ng | |
| docker compose -f docker-compose.yaml down | |
| else | |
| echo "No existing deployment found in /home/${{ secrets.DB_SSH_USER }}/kcidb-ng." | |
| exit 0 | |
| fi | |
| - name: Copy new docker-compose file over ssh | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.DB_SSH_HOST }} | |
| username: ${{ secrets.DB_SSH_USER }} | |
| key: ${{ secrets.DB_SSH_KEY }} | |
| source: "docker-compose.yaml" | |
| target: "/home/${{ secrets.DB_SSH_USER }}/kcidb-ng/" | |
| - name: Pull and start new instance over ssh | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.DB_SSH_HOST }} | |
| username: ${{ secrets.DB_SSH_USER }} | |
| key: ${{ secrets.DB_SSH_KEY }} | |
| script: | | |
| set -euo pipefail | |
| cd /home/${{ secrets.DB_SSH_USER }}/kcidb-ng | |
| test -f docker-compose.yaml || { | |
| echo "Missing docker-compose.yaml in /home/${{ secrets.DB_SSH_USER }}/kcidb-ng" | |
| exit 1 | |
| } | |
| docker compose -f docker-compose.yaml pull | |
| docker compose -f docker-compose.yaml up -d --remove-orphans |