The Management API requires the admin OIDC endpoint (ADMIN_ENDPOINT) to be reachable. Since bootstrap now runs inside the Logto container (not a separate container), Traefik may not have discovered the labels yet. Wait for the admin endpoint to be routable before running bootstrap. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
2.1 KiB
Bash
63 lines
2.1 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "[entrypoint] Seeding Logto database..."
|
|
npm run cli db seed -- --swe 2>/dev/null || true
|
|
|
|
echo "[entrypoint] Deploying database alterations..."
|
|
npm run cli db alteration deploy 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
|
|
|
|
# Wait for admin endpoint to be routable through Traefik
|
|
# The Management API needs ADMIN_ENDPOINT for admin tenant OIDC discovery.
|
|
# Since bootstrap runs inside this container (not a separate one), Traefik
|
|
# may not have discovered our labels yet — wait for it.
|
|
if [ -n "$ADMIN_ENDPOINT" ]; then
|
|
echo "[entrypoint] Waiting for admin endpoint ($ADMIN_ENDPOINT) to be routable..."
|
|
for i in $(seq 1 60); do
|
|
if curl -sfk "$ADMIN_ENDPOINT/oidc/.well-known/openid-configuration" >/dev/null 2>&1; then
|
|
echo "[entrypoint] Admin endpoint ready."
|
|
break
|
|
fi
|
|
if [ "$i" -eq 60 ]; then
|
|
echo "[entrypoint] WARNING: Admin endpoint not reachable after 60s, bootstrap may fail"
|
|
fi
|
|
sleep 1
|
|
done
|
|
fi
|
|
|
|
# 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
|