Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
02a1ea1
1
Parent(s): 774e62c
Claude Code: Add explicit version pinning and port readiness check
Browse files- Pin fastapi==0.115.6 and uvicorn[standard]==0.34.0 in requirements.txt
- Add explicit port readiness check in entrypoint.sh (waits up to 30s)
- Already had /health endpoint returning {"status": "ok"}
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- entrypoint.sh +24 -2
- requirements.txt +5 -5
entrypoint.sh
CHANGED
|
@@ -42,8 +42,30 @@ echo "=========================================="
|
|
| 42 |
# Auto-restart loop: if uvicorn crashes, wait 2s and restart
|
| 43 |
while true; do
|
| 44 |
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Starting uvicorn on 0.0.0.0:${PORT:-7860}..." >&2
|
| 45 |
-
uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}" 2>&1 | tee >(cat >&2)
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] uvicorn exited with code: $EXIT_CODE"
|
| 49 |
|
|
|
|
| 42 |
# Auto-restart loop: if uvicorn crashes, wait 2s and restart
|
| 43 |
while true; do
|
| 44 |
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Starting uvicorn on 0.0.0.0:${PORT:-7860}..." >&2
|
| 45 |
+
uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}" 2>&1 | tee >(cat >&2) &
|
| 46 |
+
UVICORN_PID=$!
|
| 47 |
+
|
| 48 |
+
# Wait for uvicorn to start and port to be ready
|
| 49 |
+
PORT=${PORT:-7860}
|
| 50 |
+
MAX_WAIT=30
|
| 51 |
+
WAIT_COUNT=0
|
| 52 |
+
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
|
| 53 |
+
if nc -z localhost $PORT 2>/dev/null || curl -s http://localhost:$PORT/health > /dev/null 2>&1; then
|
| 54 |
+
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] ✓ Port $PORT is ready!" >&2
|
| 55 |
+
break
|
| 56 |
+
fi
|
| 57 |
+
WAIT_COUNT=$((WAIT_COUNT + 1))
|
| 58 |
+
sleep 1
|
| 59 |
+
done
|
| 60 |
+
|
| 61 |
+
if [ $WAIT_COUNT -eq $MAX_WAIT ]; then
|
| 62 |
+
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] ✗ ERROR: Port $PORT did not become ready after $MAX_WAIT seconds!" >&2
|
| 63 |
+
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Startup failure detected. Check logs above for errors." >&2
|
| 64 |
+
fi
|
| 65 |
+
|
| 66 |
+
# Wait for uvicorn process
|
| 67 |
+
wait $UVICORN_PID
|
| 68 |
+
EXIT_CODE=$?
|
| 69 |
|
| 70 |
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] uvicorn exited with code: $EXIT_CODE"
|
| 71 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
fastapi
|
| 2 |
-
uvicorn
|
| 3 |
-
huggingface_hub
|
| 4 |
-
psutil
|
| 5 |
-
python-json-logger
|
|
|
|
| 1 |
+
fastapi==0.115.6
|
| 2 |
+
uvicorn[standard]==0.34.0
|
| 3 |
+
huggingface_hub==0.29.1
|
| 4 |
+
psutil==6.1.1
|
| 5 |
+
python-json-logger==3.2.1
|