|
| 1 | +name: Deploy Playground Proxy |
| 2 | + |
| 3 | +# Auto-deploys the sandbox proxy to the playground server whenever proxy source |
| 4 | +# changes land on main. Fills the gap left by playground-proxy-ci.yml (tests |
| 5 | +# only) — build-context containers don't auto-update on PR merge without this. |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - 'docker/playground/proxy/**' |
| 12 | + - 'docker/docker-compose.playground.yml' |
| 13 | + - '.github/workflows/playground-proxy-deploy.yml' |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + reason: |
| 17 | + description: "Reason for manual trigger" |
| 18 | + required: false |
| 19 | + default: "manual redeploy" |
| 20 | + |
| 21 | +env: |
| 22 | + PLAYGROUND_IP: ${{ secrets.PLAYGROUND_IP }} |
| 23 | + PROXY_SRC: docker/playground/proxy |
| 24 | + PROXY_DEST: /opt/playground/playground/proxy |
| 25 | + COMPOSE_FILE: /opt/playground/docker-compose.yml |
| 26 | + |
| 27 | +jobs: |
| 28 | + deploy-proxy: |
| 29 | + name: Deploy sandbox proxy |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up SSH |
| 35 | + run: | |
| 36 | + mkdir -p ~/.ssh |
| 37 | + echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key |
| 38 | + chmod 600 ~/.ssh/deploy_key |
| 39 | + ssh-keyscan -H "$PLAYGROUND_IP" >> ~/.ssh/known_hosts 2>/dev/null || true |
| 40 | +
|
| 41 | + - name: Copy proxy source to server |
| 42 | + run: | |
| 43 | + scp -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no \ |
| 44 | + ${{ env.PROXY_SRC }}/*.js \ |
| 45 | + ${{ env.PROXY_SRC }}/Dockerfile \ |
| 46 | + ${{ env.PROXY_SRC }}/package.json \ |
| 47 | + root@${{ env.PLAYGROUND_IP }}:${{ env.PROXY_DEST }}/ |
| 48 | +
|
| 49 | + - name: Rebuild and restart proxy |
| 50 | + run: | |
| 51 | + ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no "root@${{ env.PLAYGROUND_IP }}" bash << 'REMOTE' |
| 52 | + set -e |
| 53 | + cd /opt/playground |
| 54 | + echo "Building proxy image..." |
| 55 | + docker compose -f docker-compose.yml build --no-cache sandbox-proxy |
| 56 | + echo "Restarting sandbox-proxy..." |
| 57 | + docker compose -f docker-compose.yml up -d --no-deps sandbox-proxy |
| 58 | + echo "Waiting for health..." |
| 59 | + sleep 8 |
| 60 | + HEALTH=$(curl -sf http://localhost:3100/health 2>/dev/null) || { echo "Health check failed"; exit 1; } |
| 61 | + echo "Proxy healthy: $HEALTH" |
| 62 | + REMOTE |
| 63 | +
|
| 64 | + - name: Notify Telegram on success |
| 65 | + if: success() |
| 66 | + env: |
| 67 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 68 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 69 | + run: | |
| 70 | + MSG="✅ [Platform] Playground proxy deployed — $(git log -1 --format='%s')" |
| 71 | + curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ |
| 72 | + -d "chat_id=${TELEGRAM_CHAT_ID}&text=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1]))" "$MSG")" > /dev/null |
| 73 | +
|
| 74 | + - name: Notify Telegram on failure |
| 75 | + if: failure() |
| 76 | + env: |
| 77 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 78 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 79 | + run: | |
| 80 | + MSG="❌ [Platform] Playground proxy deploy FAILED — $(git log -1 --format='%s'). Check: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 81 | + curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ |
| 82 | + -d "chat_id=${TELEGRAM_CHAT_ID}&text=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1]))" "$MSG")" > /dev/null |
0 commit comments