Adds logto-entrypoint.sh that seeds DB, starts Logto, waits for health, runs bootstrap, then keeps Logto running. Eliminates the separate logto-bootstrap init container.
42 lines
1.2 KiB
Bash
42 lines
1.2 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "[entrypoint] Seeding Logto database..."
|
|
npm run cli db seed -- --swe 2>/dev/null || true
|
|
|
|
echo "[entrypoint] Starting Logto..."
|
|
npm start &
|
|
LOGTO_PID=$!
|
|
|
|
echo "[entrypoint] Waiting for Logto to be ready..."
|
|
for i in $(seq 1 120); do
|
|
if node -e "require('http').get('http://localhost:3001/oidc/.well-known/openid-configuration', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))" 2>/dev/null; then
|
|
echo "[entrypoint] Logto is ready."
|
|
break
|
|
fi
|
|
if [ "$i" -eq 120 ]; then
|
|
echo "[entrypoint] ERROR: Logto not ready after 120s"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Run bootstrap if not already done
|
|
BOOTSTRAP_FILE="/data/logto-bootstrap.json"
|
|
if [ -f "$BOOTSTRAP_FILE" ]; then
|
|
CACHED_SECRET=$(jq -r '.m2mClientSecret // empty' "$BOOTSTRAP_FILE" 2>/dev/null)
|
|
CACHED_SPA=$(jq -r '.spaClientId // empty' "$BOOTSTRAP_FILE" 2>/dev/null)
|
|
if [ -n "$CACHED_SECRET" ] && [ -n "$CACHED_SPA" ]; then
|
|
echo "[entrypoint] Bootstrap already complete."
|
|
else
|
|
echo "[entrypoint] Incomplete bootstrap found, re-running..."
|
|
/scripts/logto-bootstrap.sh
|
|
fi
|
|
else
|
|
echo "[entrypoint] Running bootstrap..."
|
|
/scripts/logto-bootstrap.sh
|
|
fi
|
|
|
|
echo "[entrypoint] Logto is running (PID $LOGTO_PID)."
|
|
wait $LOGTO_PID
|