harb/containers/ponder-dev-entrypoint.sh

67 lines
2 KiB
Bash
Raw Normal View History

2025-09-24 10:57:22 +02:00
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=/workspace
CONTRACT_ENV=$ROOT_DIR/tmp/podman/contracts.env
PONDER_WORKDIR=$ROOT_DIR/services/ponder
while [[ ! -f "$CONTRACT_ENV" ]]; do
echo "[ponder-entrypoint] waiting for contracts env"
sleep 2
done
cd "$PONDER_WORKDIR"
# Wait for .env.local to be created by bootstrap
while [[ ! -f .env.local ]]; do
echo "[ponder-entrypoint] waiting for .env.local"
sleep 2
done
# Load contract deployment info
source "$CONTRACT_ENV"
START_BLOCK=$(grep START_BLOCK .env.local 2>/dev/null | cut -d= -f2 || echo "")
EXPECTED_SCHEMA="ponder_local_${START_BLOCK}"
# Check if schema changed (contract redeployment detected)
if [[ -n "$START_BLOCK" ]]; then
CURRENT_SCHEMA=$(grep DATABASE_SCHEMA .env.local 2>/dev/null | cut -d= -f2 || echo "")
if [[ -n "$CURRENT_SCHEMA" && "$CURRENT_SCHEMA" != "$EXPECTED_SCHEMA" ]]; then
echo "[ponder-entrypoint] Contract redeployment detected (schema changed: $CURRENT_SCHEMA -> $EXPECTED_SCHEMA)"
echo "[ponder-entrypoint] Resetting Ponder database..."
export PGPASSWORD=ponder_local
psql -h postgres -U ponder -d ponder_local -c \
"DROP SCHEMA IF EXISTS \"$CURRENT_SCHEMA\" CASCADE;" 2>/dev/null || true
echo "[ponder-entrypoint] Old schema dropped successfully"
fi
fi
REQUIRED_DIST="$ROOT_DIR/kraiken-lib/dist/index.js"
if [[ ! -f "$REQUIRED_DIST" ]]; then
echo "[ponder-entrypoint] ERROR: Run ./scripts/build-kraiken-lib.sh before starting containers" >&2
exit 1
fi
echo "[ponder-entrypoint] Installing dependencies..."
npm install --no-save --loglevel error 2>&1 || {
echo "[ponder-entrypoint] npm install failed, trying with --force"
npm install --force --no-save --loglevel error
}
2025-09-24 10:57:22 +02:00
# Load and export all environment variables from .env.local
if [[ -f .env.local ]]; then
echo "[ponder-entrypoint] Loading environment from .env.local"
set -a
source .env.local
set +a
fi
2025-09-24 10:57:22 +02:00
export CHOKIDAR_USEPOLLING=${CHOKIDAR_USEPOLLING:-1}
export HOST=0.0.0.0
export PORT=${PORT:-42069}
exec npm run dev