支持开发环境局域网登录测试
This commit is contained in:
@@ -384,6 +384,8 @@ write_env_file() {
|
||||
{
|
||||
printf 'COMPOSE_PROJECT_NAME=%s\n' "$project_name"
|
||||
printf 'ENV=%s\n' "$runtime_env"
|
||||
printf 'VITE_RUNTIME_ENV=%s\n' "$runtime_env"
|
||||
printf 'VITE_ALLOW_INSECURE_DEV_LOGIN=%s\n' "$([[ "$runtime_env" == "development" ]] && printf 'true' || printf 'false')"
|
||||
printf 'JWT_SECRET_KEY=%s\n' "$jwt_secret"
|
||||
printf 'LOGIN_RSA_KEY_ID=%s\n' "$login_key_id"
|
||||
printf 'LOGIN_RSA_PRIVATE_KEY=%s\n' "$rsa_private_key"
|
||||
@@ -393,6 +395,33 @@ write_env_file() {
|
||||
ok ".env 写入完成"
|
||||
}
|
||||
|
||||
upsert_env_value() {
|
||||
local key="$1" value="$2"
|
||||
local temp_file
|
||||
temp_file="$(mktemp "$ROOT_DIR/.env.tmp.XXXXXX")"
|
||||
if [[ -f "$ENV_FILE" && -n "$(read_env_value "$key" || true)" ]]; then
|
||||
awk -v key="$key" -v value="$value" '
|
||||
BEGIN { prefix = key "=" }
|
||||
index($0, prefix) == 1 { print key "=" value; next }
|
||||
{ print }
|
||||
' "$ENV_FILE" > "$temp_file"
|
||||
else
|
||||
[[ -f "$ENV_FILE" ]] && cat "$ENV_FILE" > "$temp_file"
|
||||
printf '%s=%s\n' "$key" "$value" >> "$temp_file"
|
||||
fi
|
||||
mv "$temp_file" "$ENV_FILE"
|
||||
}
|
||||
|
||||
sync_frontend_build_env() {
|
||||
local runtime_env="$1"
|
||||
local allow_insecure_dev_login="false"
|
||||
[[ "$runtime_env" == "development" ]] && allow_insecure_dev_login="true"
|
||||
|
||||
upsert_env_value VITE_RUNTIME_ENV "$runtime_env"
|
||||
upsert_env_value VITE_ALLOW_INSECURE_DEV_LOGIN "$allow_insecure_dev_login"
|
||||
ok "前端构建环境变量已同步"
|
||||
}
|
||||
|
||||
prepare_env_file() {
|
||||
step "准备环境配置文件"
|
||||
local project_name="$1" runtime_env="$2" login_key_id="$3"
|
||||
@@ -568,6 +597,7 @@ main() {
|
||||
check_dependencies
|
||||
confirm_install "$EFFECTIVE_PROJECT_NAME" "$EFFECTIVE_RUNTIME_ENV"
|
||||
prepare_env_file "$project_name" "$runtime_env" "$login_key_id"
|
||||
sync_frontend_build_env "$runtime_env"
|
||||
run_compose_config
|
||||
run_backend_init
|
||||
run_build_and_start
|
||||
|
||||
Reference in New Issue
Block a user