Refactor server to use BullMQ for queue management; update Redis conn… #26
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 to EC2 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to EC2 | |
| env: | |
| EC2_HOST: ${{ secrets.EC2_HOST }} | |
| EC2_USER: ${{ secrets.EC2_USER }} | |
| EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }} | |
| EC2_SSH_PORT: ${{ secrets.EC2_SSH_PORT || 22 }} | |
| run: | | |
| # Create SSH key file | |
| mkdir -p ~/.ssh | |
| echo "$EC2_SSH_KEY" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| # Add EC2 to known_hosts | |
| ssh-keyscan -p $EC2_SSH_PORT $EC2_HOST >> ~/.ssh/known_hosts 2>/dev/null | |
| # Deploy via SSH | |
| ssh -i ~/.ssh/deploy_key -p $EC2_SSH_PORT $EC2_USER@$EC2_HOST << 'EOF' | |
| cd ~/split-it | |
| echo "=== Backing up env files ===" | |
| cp deploy/env/.env.production /tmp/.env.production.server.backup 2>/dev/null || true | |
| cp .env.production /tmp/.env.production.frontend.backup 2>/dev/null || true | |
| echo "=== Pulling latest code ===" | |
| # Stash any local changes and handle untracked files | |
| git stash --include-untracked || true | |
| git fetch origin | |
| git reset --hard origin/master || git reset --hard origin/main | |
| echo "=== Restoring env files ===" | |
| mkdir -p deploy/env | |
| cp /tmp/.env.production.server.backup deploy/env/.env.production 2>/dev/null || echo "Warning: No server env backup found" | |
| cp /tmp/.env.production.frontend.backup .env.production 2>/dev/null || echo "Warning: No frontend env backup found" | |
| echo "=== Building frontend ===" | |
| npm run build | |
| echo "=== Stopping containers ===" | |
| docker-compose -f deploy/docker/docker-compose.production.yml down | |
| echo "=== Clearing nginx cache ===" | |
| docker system prune -f || true | |
| echo "=== Starting containers ===" | |
| docker-compose -f deploy/docker/docker-compose.production.yml --env-file deploy/env/.env.production up -d --force-recreate | |
| echo "=== Waiting for services to start ===" | |
| sleep 10 | |
| echo "=== Checking container status ===" | |
| docker-compose -f deploy/docker/docker-compose.production.yml ps | |
| echo "=== Checking API health ===" | |
| curl -s https://split-it.live/api/health | jq . || echo "Health check failed" | |
| echo "=== Deployment complete ===" | |
| EOF | |
| # Cleanup | |
| rm ~/.ssh/deploy_key |