57 lines
1.8 KiB
Bash
57 lines
1.8 KiB
Bash
#!/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}"
|
|
SHAI_CONFIG="${SHAI_CONFIG:-/config/settings.conf}"
|
|
SHAI_DATA="${SHAI_DATA:-/data/data.json}"
|
|
|
|
echo "[Wrapper] Repo: $REPO_URL @ $REPO_BRANCH"
|
|
echo "[Wrapper] SHAI_CONFIG: $SHAI_CONFIG"
|
|
echo "[Wrapper] SHAI_DATA: $SHAI_DATA"
|
|
|
|
mkdir -p "$(dirname "$SHAI_CONFIG")" /data /app/runtime
|
|
touch "$SHAI_CONFIG"
|
|
|
|
# --- 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 ---
|
|
if [ -f requirements.txt ]; then
|
|
echo "[Wrapper] Installing requirements..."
|
|
pip install --no-cache-dir -r requirements.txt
|
|
fi
|
|
|
|
# --- 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
|
|
import importlib, sys
|
|
sys.exit(0 if importlib.util.find_spec("playwright") else 1)
|
|
PY
|
|
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
|
|
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 chromium
|
|
fi
|
|
fi
|
|
|
|
export SHAI_CONFIG SHAI_DATA
|
|
|
|
echo "[Wrapper] Launching bot..."
|
|
python -u bot.py
|