refactor: 重构部署脚本为 dev/build_docker/remote/build 四脚本并统一单域名容器模型

This commit is contained in:
Nixevol
2026-07-09 09:42:21 +08:00
parent b498a49a9b
commit 1e0e1d6eb8
19 changed files with 1040 additions and 1514 deletions
-56
View File
@@ -15,42 +15,6 @@ import yaml
ROOT = Path(__file__).resolve().parent.parent
SCRIPTS = ROOT / "scripts"
IS_WINDOWS = os.name == "nt"
# 本地启动偏好记忆(数据源选择 + 手动输入的连接信息)。不纳入 git。
STATE_FILE = SCRIPTS / ".dev.local.json"
def load_state() -> dict:
"""读取本地启动偏好(不存在/损坏则返回空字典)。"""
try:
with open(STATE_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except (OSError, json.JSONDecodeError):
return {}
def save_state(state: dict) -> None:
try:
with open(STATE_FILE, "w", encoding="utf-8", newline="\n") as f:
json.dump(state, f, ensure_ascii=False, indent=2)
except OSError:
pass
def ask(prompt_text: str, default: str = "") -> str:
"""带默认值的输入:直接回车则采用默认值。"""
suffix = f"(默认 {default})" if default != "" else "(可留空)"
try:
val = input(f"{prompt_text}{suffix}: ").strip()
except EOFError:
return default
return val or default
def is_interactive() -> bool:
try:
return sys.stdin is not None and sys.stdin.isatty()
except Exception: # noqa: BLE001
return False
def load_config(path: Path | None = None) -> dict:
@@ -106,11 +70,9 @@ def build_env(cfg: dict) -> dict[str, str]:
"ADMIN_ORIGIN": f"http://localhost:{app['admin_port']}",
"CLIENT_ORIGIN": f"http://localhost:{app['client_port']}",
"DATABASE_URL": f'"{database_url}"',
"MYSQL_ROOT_PASSWORD": db["root_password"],
"MYSQL_DATABASE": db["name"],
"MYSQL_USER": db["user"],
"MYSQL_PASSWORD": db["password"],
"MYSQL_PORT": str(db["port"]),
"REDIS_HOST": rds["host"],
"REDIS_PORT": str(rds["port"]),
"REDIS_PASSWORD": rds.get("password", "") or "",
@@ -140,24 +102,6 @@ def build_env(cfg: dict) -> dict[str, str]:
return env
def build_full_stack_env(cfg: dict) -> dict[str, str]:
"""Build .env values for docker-compose.full.yml local full-stack runs."""
env = build_env(cfg)
env.update(
{
"NODE_ENV": "production",
# In the full-stack compose, Nginx is the public entrypoint:
# admin/API/short-link on :80, client on :8080.
"BASE_URL": "http://localhost",
"ADMIN_ORIGIN": "http://localhost",
"CLIENT_ORIGIN": "http://localhost:8080",
"TRACE_URL_TEMPLATE": "http://localhost:8080/#/trace/{code}",
"BACKUP_DIR": "/app/apps/api/backups",
}
)
return env
def write_env(env: dict[str, str], path: Path | None = None) -> None:
path = path or (ROOT / ".env")
lines = [f"{k}={v}" for k, v in env.items()]