nikhilachale is deploying Chess app π #11
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: GitHub Actions Demo | |
| run-name: ${{ github.actor }} is deploying Chess app π | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| Redeploy: | |
| runs-on: ubuntu-latest | |
| name: Redeploy Chess app to production | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Test connectivity | |
| run: | | |
| echo "Testing network connectivity to server..." | |
| if timeout 10 ping -c 3 3.110.54.252; then | |
| echo "β Server is pingable" | |
| else | |
| echo "β οΈ Ping failed, but server might still be reachable via SSH" | |
| fi | |
| if timeout 10 nc -z 3.110.54.252 22; then | |
| echo "β SSH port (22) is accessible" | |
| else | |
| echo "β SSH port (22) is not accessible" | |
| exit 1 | |
| fi | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| timeout 10 ssh-keyscan -H 3.110.54.252 >> ~/.ssh/known_hosts || true | |
| - name: Deploy using Docker Compose | |
| run: | | |
| ssh -i ~/.ssh/deploy_key \ | |
| -o StrictHostKeyChecking=no \ | |
| -o ConnectTimeout=30 \ | |
| -o ServerAliveInterval=10 \ | |
| -o ServerAliveCountMax=3 \ | |
| ec2-user@3.110.54.252 << 'EOF' | |
| set -e | |
| echo "β Connected to server" | |
| echo "π Navigating to project directory..." | |
| cd ~/Chess || { echo "β Project directory not found"; exit 1; } | |
| echo "π₯ Pulling latest code..." | |
| git pull origin main | |
| echo "π Stopping existing containers..." | |
| docker-compose down || true | |
| echo "π Starting containers with latest images..." | |
| docker-compose up -d --pull always | |
| echo "β³ Waiting for containers to start..." | |
| sleep 10 | |
| echo "π Container status:" | |
| docker-compose ps | |
| echo "π Checking container health..." | |
| if docker ps --filter "name=chess-ui" --filter "status=running" | grep -q chess-ui; then | |
| echo "β UI container is running" | |
| else | |
| echo "β UI container failed to start" | |
| docker logs chess-ui --tail 20 | |
| fi | |
| if docker ps --filter "name=chess-ws" --filter "status=running" | grep -q chess-ws; then | |
| echo "β WebSocket container is running" | |
| else | |
| echo "β WebSocket container failed to start" | |
| docker logs chess-ws --tail 20 | |
| fi | |
| echo "π Chess app deployed successfully!" | |
| EOF |