feat(deploy): 在同一台机器上接入继续教育和 Dify
4 核 8G 同时跑协会站点、PlayEdu 和估价智能体,并让门户专家页底色透出页面背景。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1b33361209
commit
a8e2e741d1
24 files changed
+1035
-85
No files matched your search
+95
-43
@@ -1,12 +1,7 @@
|
||||
#!/bin/bash
|
||||
# 只在还没有 .env 时生成。已有文件不覆盖,避免把字段加密密钥换掉。
|
||||
# 没有 .env 时生成。已有文件只补缺失项,不改已经写过的密钥。
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
if [[ -f .env ]]; then
|
||||
echo ".env 已存在,保持不变"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
umask 077
|
||||
python3 - <<'PY'
|
||||
import base64
|
||||
@@ -15,18 +10,51 @@ import secrets
|
||||
from pathlib import Path
|
||||
|
||||
root = Path(".")
|
||||
tag = os.environ.get("IMAGE_TAG", "").strip()
|
||||
path = root / ".env"
|
||||
|
||||
|
||||
def q(value: str) -> str:
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
|
||||
|
||||
def unquote(value: str) -> str:
|
||||
value = value.strip()
|
||||
if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
|
||||
return value[1:-1]
|
||||
return value
|
||||
|
||||
|
||||
def parse(text: str) -> dict[str, str]:
|
||||
found = {}
|
||||
for line in text.splitlines():
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, value = line.split("=", 1)
|
||||
found[key] = unquote(value)
|
||||
return found
|
||||
|
||||
|
||||
current = path.read_text(encoding="utf-8") if path.exists() else ""
|
||||
have = parse(current)
|
||||
|
||||
tag = os.environ.get("IMAGE_TAG", "").strip() or have.get("IMAGE_TAG", "")
|
||||
tag_file = root / "IMAGE_TAG"
|
||||
if not tag and tag_file.exists():
|
||||
tag = tag_file.read_text(encoding="utf-8").strip()
|
||||
if not tag:
|
||||
tag = "20261123"
|
||||
|
||||
site = os.environ.get("SITE_DOMAIN", "www.gsrea.org.cn").strip()
|
||||
site = os.environ.get("SITE_DOMAIN", "").strip() or have.get("SITE_DOMAIN", "www.gsrea.org.cn")
|
||||
apex = site[4:] if site.startswith("www.") else site
|
||||
names = os.environ.get("SITE_NAMES", f"{site} {apex}").strip()
|
||||
files = os.environ.get("FILES_DOMAIN", f"files.{apex}").strip()
|
||||
data_root = os.environ.get("DATA_ROOT", "./data").strip() or "./data"
|
||||
names = os.environ.get("SITE_NAMES", "").strip() or have.get("SITE_NAMES", f"{site} {apex}")
|
||||
files = os.environ.get("FILES_DOMAIN", "").strip() or have.get("FILES_DOMAIN", f"files.{apex}")
|
||||
ai = os.environ.get("AI_DOMAIN", "").strip() or have.get("AI_DOMAIN", f"ai.{apex}")
|
||||
edu = os.environ.get("EDU_DOMAIN", "").strip() or have.get("EDU_DOMAIN", f"edu.{apex}")
|
||||
edu_h5 = os.environ.get("EDU_H5_DOMAIN", "").strip() or have.get("EDU_H5_DOMAIN", f"h5.{apex}")
|
||||
edu_admin = os.environ.get("EDU_ADMIN_DOMAIN", "").strip() or have.get(
|
||||
"EDU_ADMIN_DOMAIN", f"edu-admin.{apex}"
|
||||
)
|
||||
data_root = os.environ.get("DATA_ROOT", "").strip() or have.get("DATA_ROOT", "./data") or "./data"
|
||||
|
||||
cert_ready = (root / "certs" / "fullchain.pem").is_file() or (
|
||||
root / "certs" / "live" / site / "fullchain.pem"
|
||||
@@ -37,41 +65,65 @@ cors = f"{scheme}://{site}"
|
||||
if apex != site:
|
||||
cors = f"{cors},{scheme}://{apex}"
|
||||
|
||||
def q(value: str) -> str:
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
wanted = {
|
||||
"IMAGE_TAG": tag,
|
||||
"DATA_ROOT": data_root,
|
||||
"SITE_DOMAIN": site,
|
||||
"SITE_NAMES": names,
|
||||
"FILES_DOMAIN": files,
|
||||
"AI_DOMAIN": ai,
|
||||
"EDU_DOMAIN": edu,
|
||||
"EDU_H5_DOMAIN": edu_h5,
|
||||
"EDU_ADMIN_DOMAIN": edu_admin,
|
||||
"SITE_ORIGIN": origin,
|
||||
"CORS_ORIGINS": cors,
|
||||
"MINIO_PUBLIC_SECURE": "true" if cert_ready else "false",
|
||||
"MINIO_BASE_URL": f"{scheme}://{files}/gsfdc-public",
|
||||
"DIFY_PUBLIC_URL": f"{scheme}://{ai}",
|
||||
"DIFY_VALUATION_API_KEY": "",
|
||||
"MYSQL_DATABASE": "gsfdc",
|
||||
"MYSQL_USER": "gsfdc",
|
||||
"MYSQL_PASSWORD": secrets.token_hex(24),
|
||||
"MYSQL_ROOT_PASSWORD": secrets.token_hex(24),
|
||||
"PLAYEDU_DB_PASSWORD": secrets.token_hex(24),
|
||||
"PLAYEDU_JWT_KEY": secrets.token_hex(24),
|
||||
"REDIS_PASSWORD": secrets.token_hex(24),
|
||||
"MINIO_ROOT_USER": "gsfdc",
|
||||
"MINIO_ROOT_PASSWORD": secrets.token_hex(24),
|
||||
"JWT_SECRET": secrets.token_hex(32),
|
||||
"FIELD_AES_KEY": base64.b64encode(secrets.token_bytes(32)).decode("ascii"),
|
||||
"DIFY_SSO_SECRET": secrets.token_urlsafe(48),
|
||||
"GAODE_KEY": "",
|
||||
"GAODE_SECURITY_JS_CODE": "",
|
||||
"SMTP_HOST": "",
|
||||
"SMTP_PORT": "465",
|
||||
"SMTP_USER": "",
|
||||
"SMTP_PASSWORD": "",
|
||||
"SMTP_SENDER": "",
|
||||
"SMTP_USE_SSL": "true",
|
||||
"CERTBOT_EMAIL": "",
|
||||
}
|
||||
|
||||
lines = [
|
||||
f"IMAGE_TAG={q(tag)}",
|
||||
f"DATA_ROOT={q(data_root)}",
|
||||
f"SITE_DOMAIN={q(site)}",
|
||||
f"SITE_NAMES={q(names)}",
|
||||
f"FILES_DOMAIN={q(files)}",
|
||||
f"SITE_ORIGIN={q(origin)}",
|
||||
f"CORS_ORIGINS={q(cors)}",
|
||||
f"MINIO_PUBLIC_SECURE={q('true' if cert_ready else 'false')}",
|
||||
f"MINIO_BASE_URL={q(f'{scheme}://{files}/gsfdc-public')}",
|
||||
"MYSQL_DATABASE=gsfdc",
|
||||
"MYSQL_USER=gsfdc",
|
||||
f"MYSQL_PASSWORD={q(secrets.token_hex(24))}",
|
||||
f"MYSQL_ROOT_PASSWORD={q(secrets.token_hex(24))}",
|
||||
f"REDIS_PASSWORD={q(secrets.token_hex(24))}",
|
||||
"MINIO_ROOT_USER=gsfdc",
|
||||
f"MINIO_ROOT_PASSWORD={q(secrets.token_hex(24))}",
|
||||
f"JWT_SECRET={q(secrets.token_hex(32))}",
|
||||
f"FIELD_AES_KEY={q(base64.b64encode(secrets.token_bytes(32)).decode('ascii'))}",
|
||||
"GAODE_KEY=",
|
||||
"GAODE_SECURITY_JS_CODE=",
|
||||
"SMTP_HOST=",
|
||||
"SMTP_PORT=465",
|
||||
"SMTP_USER=",
|
||||
"SMTP_PASSWORD=",
|
||||
"SMTP_SENDER=",
|
||||
"SMTP_USE_SSL=true",
|
||||
"CERTBOT_EMAIL=",
|
||||
]
|
||||
path = root / ".env"
|
||||
missing = [key for key in wanted if key not in have]
|
||||
if path.exists() and not missing:
|
||||
print(".env 已存在,保持不变")
|
||||
raise SystemExit(0)
|
||||
|
||||
lines = []
|
||||
if path.exists():
|
||||
lines.append(current if current.endswith("\n") else current + "\n")
|
||||
for key in missing:
|
||||
lines.append(f"{key}={q(wanted[key])}\n")
|
||||
path.write_text("".join(lines), encoding="utf-8")
|
||||
os.chmod(path, 0o600)
|
||||
print("已补上 .env 里缺少的项:" + ", ".join(missing))
|
||||
raise SystemExit(0)
|
||||
|
||||
for key in wanted:
|
||||
lines.append(f"{key}={q(wanted[key])}")
|
||||
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
os.chmod(path, 0o600)
|
||||
print(f"已生成 .env ,权限 600。站点 {origin} ,附件 {scheme}://{files}/")
|
||||
print(f"Dify {scheme}://{ai}/ ,继续教育 {scheme}://{edu}/")
|
||||
print("字段加密密钥只在这个文件里。不要重新生成,否则已加密的手机号和身份证无法解密。")
|
||||
PY
|
||||
Reference in new issue
Block a user