name: Deploy Control on: push: branches: - main workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Tailscale uses: tailscale/github-action@v3 with: oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} tags: tag:ci use-cache: "true" - name: Configure SSH run: | mkdir -p ~/.ssh echo "StrictHostKeyChecking no" >> ~/.ssh/config - name: Deploy to server run: | ssh control@terebithia << 'EOF' cd /var/lib/control/app git fetch --all git reset --hard origin/main bun install sudo /run/current-system/sw/bin/systemctl restart control.service EOF - name: Health check run: | HEALTH_URL="https://control.dunkirk.sh/health" MAX_RETRIES=6 RETRY_DELAY=5 for i in $(seq 1 $MAX_RETRIES); do echo "Health check attempt $i/$MAX_RETRIES..." RESPONSE=$(curl -s -w "\n%{http_code}" "$HEALTH_URL" || echo "000") HTTP_CODE=$(echo "$RESPONSE" | tail -n1) BODY=$(echo "$RESPONSE" | head -n-1) if [ "$HTTP_CODE" = "200" ]; then # Validate response contains "status":"ok" if echo "$BODY" | grep -q '"status":"ok"'; then echo "✅ Service is healthy (HTTP $HTTP_CODE)" echo "Response: $BODY" exit 0 else echo "❌ Health check returned 200 but invalid body" echo "Response: $BODY" fi else echo "❌ Health check failed with HTTP $HTTP_CODE" echo "Response: $BODY" fi if [ $i -lt $MAX_RETRIES ]; then echo "Retrying in ${RETRY_DELAY}s..." sleep $RETRY_DELAY fi done echo "❌ Health check failed after $MAX_RETRIES attempts" exit 1