58 lines
1.6 KiB
Bash
58 lines
1.6 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# Start HTTP→SOCKS5 proxy bridge if SOCKS5 upstream is configured
|
|
if [ -n "$SOCKS5_PROXY_HOST" ]; then
|
|
echo "[entrypoint] Starting proxy bridge (HTTP :8899 → SOCKS5 $SOCKS5_PROXY_HOST:${SOCKS5_PROXY_PORT:-1002})..."
|
|
if [ -z "$IAAI_PROXY_SERVER" ]; then
|
|
export IAAI_PROXY_SERVER="http://127.0.0.1:8899"
|
|
elif [ "$IAAI_PROXY_SERVER" = "http://localhost:8899" ]; then
|
|
export IAAI_PROXY_SERVER="http://127.0.0.1:8899"
|
|
fi
|
|
echo "[entrypoint] Using browser proxy: $IAAI_PROXY_SERVER"
|
|
python -m iaai_scraper.proxy_bridge &
|
|
BRIDGE_PID=$!
|
|
sleep 1
|
|
if ! kill -0 $BRIDGE_PID 2>/dev/null; then
|
|
echo "[entrypoint] ERROR: iaai_scraper.proxy_bridge failed to start"
|
|
exit 1
|
|
fi
|
|
echo "[entrypoint] Proxy bridge started (PID $BRIDGE_PID)"
|
|
fi
|
|
|
|
# Xvfb needed only for worker (Playwright) — not for API or beat
|
|
NEEDS_XVFB=false
|
|
case "$1" in
|
|
celery*|python*main*)
|
|
NEEDS_XVFB=true
|
|
;;
|
|
*)
|
|
# Check if any arg contains "worker"
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
*worker*) NEEDS_XVFB=true; break ;;
|
|
esac
|
|
done
|
|
;;
|
|
esac
|
|
|
|
if [ "$NEEDS_XVFB" = "true" ]; then
|
|
# IAAI blocks headless Chromium on Linux; run headed via Xvfb virtual display
|
|
export DISPLAY=:99
|
|
export IAAI_HEADLESS=false
|
|
Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp &
|
|
XVFB_PID=$!
|
|
sleep 0.5
|
|
echo "[entrypoint] Xvfb started (PID $XVFB_PID, DISPLAY=$DISPLAY)"
|
|
fi
|
|
|
|
# Run Alembic migrations (only for API service, skip for worker/beat)
|
|
case "$1" in
|
|
uvicorn*)
|
|
echo "[entrypoint] Running Alembic migrations..."
|
|
alembic upgrade head || echo "[entrypoint] WARNING: Alembic migration failed, continuing..."
|
|
;;
|
|
esac
|
|
|
|
exec "$@"
|