Update wrapper/docker-entrypoint.sh

This commit is contained in:
frarol96 2025-08-24 16:31:16 +00:00
parent 0ac94d7cfe
commit 842261d5d5

View File

@ -4,15 +4,16 @@ set -euo pipefail
# --- ENV defaults (overridden by stack/Portainer) --- # --- ENV defaults (overridden by stack/Portainer) ---
REPO_URL="${REPO_URL:-https://git.example.com/owner/shaiwatcher.git}" REPO_URL="${REPO_URL:-https://git.example.com/owner/shaiwatcher.git}"
REPO_BRANCH="${REPO_BRANCH:-main}" REPO_BRANCH="${REPO_BRANCH:-main}"
SHAI_CONFIG="${SHAI_CONFIG:-/config/settings.conf}"
SHAI_DATA="${SHAI_DATA:-/data/data.json}" # new names only; these are here just for echo and sanity
DATA_FILE="${DATA_FILE:-/data/data.json}"
PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/cache/pw-browsers}"
echo "[Wrapper] Repo: $REPO_URL @ $REPO_BRANCH" echo "[Wrapper] Repo: $REPO_URL @ $REPO_BRANCH"
echo "[Wrapper] SHAI_CONFIG: $SHAI_CONFIG" echo "[Wrapper] DATA_FILE: $DATA_FILE"
echo "[Wrapper] SHAI_DATA: $SHAI_DATA" echo "[Wrapper] PLAYWRIGHT_BROWSERS_PATH: $PLAYWRIGHT_BROWSERS_PATH"
mkdir -p "$(dirname "$SHAI_CONFIG")" /data /app/runtime mkdir -p /data /app/runtime "$PLAYWRIGHT_BROWSERS_PATH"
touch "$SHAI_CONFIG"
# --- fetch repo to /app/runtime/repo --- # --- fetch repo to /app/runtime/repo ---
if [ ! -d /app/runtime/repo/.git ]; then if [ ! -d /app/runtime/repo/.git ]; then
@ -26,31 +27,27 @@ fi
cd /app/runtime/repo cd /app/runtime/repo
# --- Python deps --- # --- Python deps (from repo) ---
if [ -f requirements.txt ]; then if [ -f requirements.txt ]; then
echo "[Wrapper] Installing requirements..." echo "[Wrapper] Installing requirements..."
pip install --no-cache-dir -r requirements.txt pip install --no-cache-dir -r requirements.txt
fi fi
# --- Playwright browsers (idempotent) --- # --- Playwright browsers (idempotent) ---
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/cache/pw-browsers}"
mkdir -p "$PLAYWRIGHT_BROWSERS_PATH"
if python - <<'PY' >/dev/null 2>&1; then if python - <<'PY' >/dev/null 2>&1; then
import importlib, sys import importlib, sys
sys.exit(0 if importlib.util.find_spec("playwright") else 1) sys.exit(0 if importlib.util.find_spec("playwright") else 1)
PY PY
then then
# only install if chromium binary not found under the cache path
if ! find "$PLAYWRIGHT_BROWSERS_PATH" -type f -path "*/chrome-linux/chrome" -print -quit | grep -q . ; then if ! find "$PLAYWRIGHT_BROWSERS_PATH" -type f -path "*/chrome-linux/chrome" -print -quit | grep -q . ; then
echo "[Wrapper] Preparing Playwright runtime in $PLAYWRIGHT_BROWSERS_PATH ..." echo "[Wrapper] Preparing Playwright runtime in $PLAYWRIGHT_BROWSERS_PATH ..."
# if libs were not baked at build time, this helps (it is no-op if already satisfied)
python -m playwright install-deps chromium || true python -m playwright install-deps chromium || true
python -m playwright install chromium python -m playwright install chromium
fi fi
fi fi
export SHAI_CONFIG SHAI_DATA # ensure DATA_FILE propagates into the child
export DATA_FILE
echo "[Wrapper] Launching bot..." echo "[Wrapper] Launching bot..."
python -u bot.py exec python -u bot.py