Files
iam-front/deploy/validate-env.sh
2026-02-11 16:30:54 +08:00

54 lines
1.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
# 路径修正validate-env.sh 在 deploy/ 目录下,而 .env 在项目根目录
# 项目根目录 = deploy/../ = ../
ENV_FILE="../.env"
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found at $(readlink -f "$ENV_FILE")"
echo "Please copy .env.example to .env and configure it."
exit 1
fi
echo "Validating iam-front .env configuration..."
# Helper to read env var
get_env() {
local key=$1
local val
val=$(grep "^${key}=" "$ENV_FILE" | cut -d= -f2- | tr -d '"' | tr -d "'")
echo "$val"
}
# 1. 检查必要变量
REQUIRED_VARS=(
"IAM_SERVICE_BASE_URL"
"CAPTCHA_SECRET"
)
for var in "${REQUIRED_VARS[@]}"; do
val=$(get_env "$var")
if [ -z "$val" ]; then
echo "Error: $var is required in .env"
exit 1
fi
done
# 2. 检查 Docker 模式下 localhost
DEPLOY_TARGET="${DEPLOY_TARGET:-}"
if [ "$DEPLOY_TARGET" == "docker" ]; then
IAM_URL=$(get_env "IAM_SERVICE_BASE_URL")
if [[ "$IAM_URL" == *"localhost"* ]] || [[ "$IAM_URL" == *"127.0.0.1"* ]]; then
echo "Error: IAM_SERVICE_BASE_URL contains localhost/127.0.0.1"
echo "In Docker, this refers to the container itself."
echo "Please use the host IP or docker-compose service name (if in same network)."
exit 1
fi
fi
echo "iam-front .env validation OK"