Skip to content

Commit 484bdeb

Browse files
committed
fix: add startup diagnostics, switch to azure/webapps-deploy action
- Removed set -e to prevent silent failures - Added detailed startup diagnostics (Python path, imports, directory listing) - Tests critical imports before launching gunicorn to surface errors - Switched from az webapp deploy to azure/webapps-deploy@v3 action (more reliable, avoids 502 Kudu warmup issues)
1 parent 83af21f commit 484bdeb

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

.github/workflows/deploy-azure.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,12 @@ jobs:
8282
zip -r ../backend-deploy.zip .
8383
8484
- name: Deploy to Azure Web App
85-
run: |
86-
az webapp deploy \
87-
--resource-group ${{ env.AZURE_RESOURCE_GROUP }} \
88-
--name ${{ env.AZURE_WEBAPP_NAME }} \
89-
--src-path backend-deploy.zip \
90-
--type zip \
91-
--clean true \
92-
--restart true \
93-
--async false \
94-
--timeout 600
85+
uses: azure/webapps-deploy@v3
86+
with:
87+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
88+
package: backend-deploy.zip
89+
clean: true
90+
startup-command: startup.sh
9591

9692
- name: Test deployment
9793
run: |

startup.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
#!/bin/bash
22
# Azure App Service startup script
33
# Azure sets PORT env var automatically (default 8000)
4-
set -e
4+
5+
echo "=== API-Watch Startup ==="
6+
echo "PWD: $(pwd)"
7+
echo "Date: $(date)"
58

69
# Ensure we're in the deployment directory
710
cd /home/site/wwwroot
11+
echo "Working dir: $(pwd)"
12+
echo "Contents: $(ls -la)"
813

914
# Activate Oryx-created virtual environment (created during zip deployment)
1015
if [ -d "antenv" ]; then
1116
echo "Activating Oryx virtual environment (antenv)..."
1217
source antenv/bin/activate
18+
echo "Python: $(which python)"
19+
echo "Pip packages: $(pip list --format=columns 2>/dev/null | head -5)"
20+
else
21+
echo "WARNING: antenv directory not found!"
22+
echo "Checking for packages directory..."
1323
fi
1424

1525
# Add bundled packages to Python path (fallback if no antenv)
@@ -20,18 +30,33 @@ fi
2030

2131
# Fallback: install if neither antenv nor bundled packages have gunicorn
2232
if ! python -c "import gunicorn" 2>/dev/null; then
23-
echo "Installing Python dependencies (timeout 180s)..."
24-
timeout 180 pip install --no-cache-dir -r requirements.txt 2>&1 | tail -5 || echo "⚠️ pip install timed out or failed (non-fatal)"
33+
echo "gunicorn not found, installing dependencies..."
34+
pip install --no-cache-dir -r requirements.txt 2>&1 | tail -10 || echo "⚠️ pip install failed"
2535
fi
2636

37+
# Verify critical imports work
38+
echo "Testing critical imports..."
39+
python -c "
40+
import sys
41+
print(f'Python: {sys.executable}')
42+
try:
43+
import fastapi; print(f'fastapi: {fastapi.__version__}')
44+
except Exception as e: print(f'fastapi FAILED: {e}')
45+
try:
46+
import gunicorn; print(f'gunicorn: OK')
47+
except Exception as e: print(f'gunicorn FAILED: {e}')
48+
try:
49+
from src.api_server import app; print('src.api_server: OK')
50+
except Exception as e: print(f'src.api_server FAILED: {e}')
51+
" 2>&1 || echo "Import test failed"
52+
2753
# Run database migrations (safe to run repeatedly — no-ops if up to date)
2854
if [ -d "alembic" ]; then
2955
echo "Running database migrations..."
30-
python -m alembic upgrade head || echo "⚠️ Migrations skipped (non-fatal)"
56+
python -m alembic upgrade head 2>&1 || echo "⚠️ Migrations skipped (non-fatal)"
3157
fi
3258

3359
# Start with gunicorn + uvicorn workers for production performance
34-
# Azure sets PORT; default to 8000 if unset
3560
export PORT=${PORT:-8000}
3661
echo "Starting API-Watch on port $PORT..."
3762

0 commit comments

Comments
 (0)