1
0
forked from baron/baron-sso
Files
baron-sso/scripts/setup_test2.sh
ai-cell-a100-1 7ecb19e397 fc
2026-04-24 15:22:45 +09:00

101 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="$ROOT_DIR/.env.test2"
AUTH_CONFIG_TEST2="$ROOT_DIR/.generated/auth-config.test2.env"
echo "Creating clean $ENV_FILE..."
if [[ -f "$ROOT_DIR/.env.sample" ]]; then
grep -vE "PORT|URL|CALLBACK|ALLOWED_RETURN" "$ROOT_DIR/.env.sample" > "$ENV_FILE"
else
touch "$ENV_FILE"
fi
cat >> "$ENV_FILE" <<EOF
APP_ENV=development
DB_PORT=25432
CLICKHOUSE_PORT_HTTP=28123
CLICKHOUSE_PORT_NATIVE=29000
BACKEND_PORT=23000
ADMINFRONT_PORT=25173
DEVFRONT_PORT=25174
USERFRONT_PORT=25000
REDIS_PORT=26399
OATHKEEPER_PROXY_PORT=24467
USERFRONT_URL=https://ssob.hmac.kr
ADMINFRONT_URL=https://adminb.hmac.kr
DEVFRONT_URL=https://devb.hmac.kr
ADMINFRONT_CALLBACK_URLS=https://adminb.hmac.kr/auth/callback
DEVFRONT_CALLBACK_URLS=https://devb.hmac.kr/auth/callback
KRATOS_UI_URL=https://ssob.hmac.kr/auth
KRATOS_BROWSER_URL=https://ssob.hmac.kr/auth
# Explicitly define for auth_config.sh
HYDRA_PUBLIC_URL=https://ssob.hmac.kr/oidc
OATHKEEPER_PUBLIC_URL=https://ssob.hmac.kr
EOF
if [[ -f "$ROOT_DIR/.env" ]]; then
grep -E "SECRET|KEY|PASSWORD|ID|SENDER|SES|AWS|ADMIN_EMAIL|ADMIN_PASSWORD" "$ROOT_DIR/.env" >> "$ENV_FILE" || true
fi
# Ensure mandatory secrets exist for test2
grep -q "COOKIE_SECRET=" "$ENV_FILE" || echo "COOKIE_SECRET=test2_cookie_secret_12345678" >> "$ENV_FILE"
grep -q "JWT_SECRET=" "$ENV_FILE" || echo "JWT_SECRET=test2_jwt_secret_12345678" >> "$ENV_FILE"
echo "Generating auth config for test2..."
(
if [[ -f "$ROOT_DIR/.env" ]]; then mv "$ROOT_DIR/.env" "$ROOT_DIR/.env.tmp"; fi
cp "$ENV_FILE" "$ROOT_DIR/.env"
bash "$ROOT_DIR/scripts/auth_config.sh" build
cp "$ROOT_DIR/.generated/auth-config.env" "$AUTH_CONFIG_TEST2"
rm "$ROOT_DIR/.env"
if [[ -f "$ROOT_DIR/.env.tmp" ]]; then mv "$ROOT_DIR/.env.tmp" "$ROOT_DIR/.env"; fi
)
echo "Starting test2 stack..."
docker compose -p test2 down --remove-orphans || true
# Export variables for docker-compose substitution
export DB_PORT=25432
export CLICKHOUSE_PORT_HTTP=28123
export CLICKHOUSE_PORT_NATIVE=29000
export BACKEND_PORT=23000
export ADMINFRONT_PORT=25173
export DEVFRONT_PORT=25174
export USERFRONT_PORT=25000
export REDIS_PORT=26399
export OATHKEEPER_PROXY_PORT=24467
# Load generated auth config variables
if [[ -f "$AUTH_CONFIG_TEST2" ]]; then
export $(grep -v '^#' "$AUTH_CONFIG_TEST2" | xargs)
fi
# 1. Start DBs first
docker compose -p test2 -f compose.infra.test2.yaml -f compose.ory.test2.yaml up -d postgres postgres_ory redis
echo "Waiting for DBs to be healthy..."
sleep 15
# 2. Force create databases
echo "Creating databases if they don't exist..."
docker exec test2-postgres-1 psql -U baron -d postgres -c "CREATE DATABASE baron_sso;" || echo "DB baron_sso might already exist"
docker exec test2-postgres_ory-1 psql -U ory -d postgres -c "CREATE DATABASE ory_kratos;" || echo "DB ory_kratos might already exist"
docker exec test2-postgres_ory-1 psql -U ory -d postgres -c "CREATE DATABASE ory_hydra;" || echo "DB ory_hydra might already exist"
docker exec test2-postgres_ory-1 psql -U ory -d postgres -c "CREATE DATABASE ory_keto;" || echo "DB ory_keto might already exist"
# 3. Start everything else
docker compose -p test2 \
-f compose.infra.test2.yaml \
-f compose.ory.test2.yaml \
-f docker-compose.test2.yaml \
up -d --build
echo "test2 stack is up!"
echo "UserFront: http://localhost:25000"
echo "AdminFront: http://localhost:25173"
echo "DevFront: http://localhost:25174"