feat: add Redis password configuration via env var #98
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 Backend | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - 'backend/**' | |
| - '.github/workflows/build-and-push.yml' | |
| workflow_dispatch: | |
| jobs: | |
| deploy-backend: | |
| name: Deploy backend to production via SSH | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Deploy to production | |
| env: | |
| SSH_HOST: ${{ secrets.DEPLOY_SERVER_HOST }} | |
| SSH_USER: ${{ secrets.DEPLOY_SERVER_USER }} | |
| SSH_PORT: ${{ secrets.DEPLOY_SERVER_PORT }} | |
| SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519 | |
| chmod 600 ~/.ssh/id_ed25519 | |
| ssh-keyscan -p $SSH_PORT -H $SSH_HOST >> ~/.ssh/known_hosts 2>/dev/null | |
| # Deploy: pull latest code and rebuild | |
| # Using SSH keepalive to prevent timeout during long Docker builds | |
| ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -i ~/.ssh/id_ed25519 -p $SSH_PORT $SSH_USER@$SSH_HOST << 'EOF' | |
| set -e | |
| cd /opt/sidechain/backend | |
| echo "π₯ Fetching latest code..." | |
| git fetch origin main | |
| git reset --hard origin/main | |
| git checkout origin/main | |
| echo "π³ Building backend Docker image..." | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml build backend | |
| echo "π³ Pulling other Docker images..." | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml pull | |
| echo "π Stopping old services..." | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml down --remove-orphans || true | |
| echo "π§Ή Cleaning up stale containers..." | |
| docker container prune -f || true | |
| echo "π Starting all services..." | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d | |
| echo "π Deployment complete!" | |
| EOF |