#!/usr/bin/env bash set -euo pipefail # --- ENV defaults (overridden by stack/Portainer) --- REPO_URL="${REPO_URL:-https://git.example.com/owner/shaiwatcher.git}" REPO_BRANCH="${REPO_BRANCH:-main}" # 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] DATA_FILE: $DATA_FILE" echo "[Wrapper] PLAYWRIGHT_BROWSERS_PATH: $PLAYWRIGHT_BROWSERS_PATH" mkdir -p /data /app/runtime "$PLAYWRIGHT_BROWSERS_PATH" # --- fetch repo to /app/runtime/repo --- if [ ! -d /app/runtime/repo/.git ]; then echo "[Wrapper] Cloning repo..." git clone --depth=1 -b "$REPO_BRANCH" "$REPO_URL" /app/runtime/repo else echo "[Wrapper] Updating repo..." git -C /app/runtime/repo fetch origin "$REPO_BRANCH" --depth=1 git -C /app/runtime/repo reset --hard "origin/$REPO_BRANCH" fi cd /app/runtime/repo # --- Python deps (from repo) --- if [ -f requirements.txt ]; then echo "[Wrapper] Installing requirements..." pip install --no-cache-dir -r requirements.txt fi # --- Playwright browsers (idempotent) --- if python - <<'PY' >/dev/null 2>&1; then import importlib, sys sys.exit(0 if importlib.util.find_spec("playwright") else 1) PY 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 ..." python -m playwright install-deps chromium || true python -m playwright install chromium fi fi # ensure DATA_FILE propagates into the child export DATA_FILE echo "[Wrapper] Launching bot..." exec python -u bot.py