chore add core rust project files and diesel migrations
Track required workspace crates, scripts, and historical diesel migrations so the repository contains the complete runnable backend baseline. Made-with: Cursor
This commit is contained in:
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
# 启动 docker-compose.authcore-e2e.yml → 迁移与 UC 种子数据 → 构建并启动 htyuc → 运行 ts_e2e_authcore_http(--ignored)。
|
||||
# 依赖:docker、psql、diesel_cli、cargo;AuthCore 默认路径为仓库上一级的 AuthCore。
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
AUTHCORE="${AUTHCORE_ROOT:-$ROOT/../AuthCore}"
|
||||
COMPOSE_FILE="$ROOT/docker-compose.authcore-e2e.yml"
|
||||
|
||||
export TS_DATABASE_URL="${TS_DATABASE_URL:-postgres://htyts_e2e:htyts_e2e@127.0.0.1:15432/htyts_e2e}"
|
||||
export UC_DB_URL="${UC_DB_URL:-postgres://htyuc:htyuc@127.0.0.1:15433/htyuc_test}"
|
||||
export REDIS_HOST="${REDIS_HOST:-127.0.0.1}"
|
||||
export REDIS_PORT="${REDIS_PORT:-16379}"
|
||||
export HTYUC_URL="${HTYUC_URL:-http://127.0.0.1:18080}"
|
||||
export UC_PORT="${UC_PORT:-18080}"
|
||||
export JWT_KEY="${JWT_KEY:-test_jwt_key_for_testing_only_1234567890}"
|
||||
export TOKEN_VERIFY="${TOKEN_VERIFY:-true}"
|
||||
export AUTH_CHECKING="${AUTH_CHECKING:-true}"
|
||||
export TS_DOMAIN="${TS_DOMAIN:-e2e.test.local}"
|
||||
export POOL_SIZE="${POOL_SIZE:-8}"
|
||||
export ZOMBIE_MIN="${ZOMBIE_MIN:-10}"
|
||||
export EXPIRATION_DAYS="${EXPIRATION_DAYS:-7}"
|
||||
export SKIP_POST_LOGIN="${SKIP_POST_LOGIN:-true}"
|
||||
export SKIP_REGISTRATION="${SKIP_REGISTRATION:-true}"
|
||||
export LOGGER_LEVEL="${LOGGER_LEVEL:-INFO}"
|
||||
|
||||
if [[ ! -f "$AUTHCORE/Cargo.toml" ]]; then
|
||||
echo "AuthCore not found at $AUTHCORE; set AUTHCORE_ROOT" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$ROOT"
|
||||
docker compose -f "$COMPOSE_FILE" up -d --wait
|
||||
|
||||
command -v diesel >/dev/null 2>&1 || {
|
||||
echo "diesel_cli not found; install: cargo install diesel_cli --no-default-features --features postgres --locked" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "==> htyts_models diesel migration"
|
||||
(cd "$ROOT/htyts_models" && DATABASE_URL="$TS_DATABASE_URL" diesel migration run)
|
||||
|
||||
echo "==> htyuc_models diesel"
|
||||
(cd "$AUTHCORE/htyuc_models" && DATABASE_URL="$UC_DB_URL" diesel setup && diesel migration run)
|
||||
|
||||
echo "==> UC init_test_data.sql"
|
||||
PGPASSWORD=htyuc psql -h 127.0.0.1 -p 15433 -U htyuc -d htyuc_test -f "$AUTHCORE/htyuc/tests/fixtures/init_test_data.sql"
|
||||
|
||||
echo "==> cargo build htyuc (release)"
|
||||
# 避免 IDE/CI 注入的 CARGO_TARGET_DIR 使可执行文件不在 $AUTHCORE/target/release
|
||||
(cd "$AUTHCORE" && env -u CARGO_TARGET_DIR cargo build --release -p htyuc)
|
||||
|
||||
HTYUC_BIN="$AUTHCORE/target/release/htyuc"
|
||||
if [[ ! -x "$HTYUC_BIN" ]]; then
|
||||
echo "missing $HTYUC_BIN (after env -u CARGO_TARGET_DIR build)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "${HTYUC_PID:-}" ]] && kill -0 "$HTYUC_PID" 2>/dev/null; then
|
||||
kill "$HTYUC_PID" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "==> start htyuc (port $UC_PORT)"
|
||||
nohup env UC_DB_URL="$UC_DB_URL" REDIS_HOST="$REDIS_HOST" REDIS_PORT="$REDIS_PORT" \
|
||||
JWT_KEY="$JWT_KEY" UC_PORT="$UC_PORT" POOL_SIZE=5 EXPIRATION_DAYS="$EXPIRATION_DAYS" \
|
||||
SKIP_POST_LOGIN="$SKIP_POST_LOGIN" SKIP_REGISTRATION="$SKIP_REGISTRATION" \
|
||||
LOGGER_LEVEL="$LOGGER_LEVEL" \
|
||||
"$HTYUC_BIN" > /tmp/htyuc-authcore-e2e.log 2>&1 &
|
||||
HTYUC_PID=$!
|
||||
|
||||
for _ in $(seq 1 90); do
|
||||
if curl -fsS "http://127.0.0.1:${UC_PORT}/api/v1/uc/index" >/dev/null 2>&1; then
|
||||
echo "==> htyuc ready"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
if ! curl -fsS "http://127.0.0.1:${UC_PORT}/api/v1/uc/index" >/dev/null 2>&1; then
|
||||
echo "htyuc did not become ready; log:" >&2
|
||||
tail -80 /tmp/htyuc-authcore-e2e.log >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> cargo test ts_e2e_authcore_http"
|
||||
cd "$ROOT"
|
||||
cargo test -p htyts --test ts_e2e_authcore_http -- --ignored --test-threads=1 --nocapture
|
||||
Reference in New Issue
Block a user