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
@@ -6,6 +6,10 @@ DATA_ROOT=./data
|
||||
SITE_DOMAIN=www.gsrea.org.cn
|
||||
SITE_NAMES="www.gsrea.org.cn gsrea.org.cn"
|
||||
FILES_DOMAIN=files.gsrea.org.cn
|
||||
AI_DOMAIN=ai.gsrea.org.cn
|
||||
EDU_DOMAIN=edu.gsrea.org.cn
|
||||
EDU_H5_DOMAIN=h5.gsrea.org.cn
|
||||
EDU_ADMIN_DOMAIN=edu-admin.gsrea.org.cn
|
||||
SITE_ORIGIN=https://www.gsrea.org.cn
|
||||
CORS_ORIGINS=https://www.gsrea.org.cn,https://gsrea.org.cn
|
||||
MINIO_PUBLIC_SECURE=true
|
||||
@@ -15,11 +19,16 @@ MYSQL_DATABASE=gsfdc
|
||||
MYSQL_USER=gsfdc
|
||||
MYSQL_PASSWORD=change-me
|
||||
MYSQL_ROOT_PASSWORD=change-me
|
||||
PLAYEDU_DB_PASSWORD=change-me
|
||||
PLAYEDU_JWT_KEY=change-me
|
||||
REDIS_PASSWORD=change-me
|
||||
MINIO_ROOT_USER=gsfdc
|
||||
MINIO_ROOT_PASSWORD=change-me
|
||||
JWT_SECRET=change-me
|
||||
FIELD_AES_KEY=change-me
|
||||
DIFY_SSO_SECRET=change-me
|
||||
DIFY_PUBLIC_URL=https://ai.gsrea.org.cn
|
||||
DIFY_VALUATION_API_KEY=
|
||||
|
||||
# 可选。没有就留空,不要为了填表去抄开发环境。
|
||||
GAODE_KEY=
|
||||
|
||||
+38
-15
@@ -1,19 +1,34 @@
|
||||
# 房地产协会站点部署
|
||||
|
||||
4 核 8G 上只跑这一套:门户、管理后台、Python 接口、MySQL、Redis、MinIO。教育平台和 Dify 不在这里面。
|
||||
同一台 4 核 8G 上跑协会站点、继续教育(PlayEdu)和 Dify。对外只开 80 和 443。数据库、Redis、MinIO、Dify、PlayEdu 都不映射到宿主机。
|
||||
|
||||
对外只开 80 和 443。数据库、Redis、MinIO 不映射到宿主机。
|
||||
协会站点的 MySQL 同时给继续教育用,不再单独起第二台数据库。Dify 仍用自己的 PostgreSQL 和 Redis。协作用的 Dify WebSocket 进程不启动,省下大约 500M;对话和工作流走 API 与 worker。
|
||||
|
||||
内存上限是天花板,平时占用低于这个数。加上系统本身,平时大约 5G,短时高峰靠 2G swap 托住。
|
||||
|
||||
| 容器 | 内存上限 | 作用 |
|
||||
| --- | --- | --- |
|
||||
| mysql | 1400M | 缓冲池 256M,单站点够用 |
|
||||
| server | 768M | 1 个 uvicorn 进程,避免启动时两进程同时建表 |
|
||||
| portal | 640M | Nuxt |
|
||||
| minio | 384M | 公开桶和私有桶 |
|
||||
| redis | 192M | 最大 128M |
|
||||
| web | 128M | Nginx、后台静态文件、反向代理 |
|
||||
| mysql | 1024M | 协会库和继续教育库,缓冲池 192M |
|
||||
| server | 512M | 1 个 uvicorn 进程 |
|
||||
| portal | 512M | Nuxt |
|
||||
| playedu | 512M | 继续教育,Java 堆按容器上限的 60% |
|
||||
| minio | 256M | 公开桶和私有桶 |
|
||||
| redis | 128M | 协会站点缓存,最大 64M |
|
||||
| web | 64M | 入口 Nginx |
|
||||
| dify-api | 768M | Dify 接口 |
|
||||
| dify-worker | 640M | 工作流和知识库任务,1 个进程 |
|
||||
| dify-worker-beat | 576M | 定时任务 |
|
||||
| dify-web | 256M | 控制台 |
|
||||
| dify-plugin | 256M | 插件 |
|
||||
| dify-agent | 256M | Agent |
|
||||
| dify-postgres | 320M | shared_buffers 64M |
|
||||
| weaviate | 192M | 向量库 |
|
||||
| dify-redis | 96M | Dify 自己的 Redis |
|
||||
| sandbox / local-sandbox | 各 128M | 代码沙箱 |
|
||||
| squid × 2 | 各 48M | 出站代理 |
|
||||
| dify-nginx | 48M | 只在内网给入口反代 |
|
||||
|
||||
上传限制 32M,和后台默认 10M 的业务上限留出余量。日志单文件 10M,保留 3 份。每天 03:15 备份数据库,保留 14 天。
|
||||
协会站点上传限制 32M。Dify 控制台 100M。继续教育课件 200M。日志单文件 10M,保留 3 份。每天 03:15 备份协会库、继续教育库和 Dify 的 PostgreSQL,保留 14 天。Weaviate 的数据在数据盘目录里,不在这份 SQL 里。
|
||||
|
||||
## 地址
|
||||
|
||||
@@ -21,12 +36,20 @@
|
||||
- 后台:`https://www.gsrea.org.cn/admin/#/login`
|
||||
- 接口:`https://www.gsrea.org.cn/api/site/health`
|
||||
- 公开附件:`https://files.gsrea.org.cn/gsfdc-public/...`
|
||||
- Dify 控制台:`https://ai.gsrea.org.cn/`
|
||||
- 继续教育电脑端:`https://edu.gsrea.org.cn/`
|
||||
- 继续教育手机端:`https://h5.gsrea.org.cn/`
|
||||
- 继续教育管理端:`https://edu-admin.gsrea.org.cn/`
|
||||
|
||||
域名以 `.env` 为准。后台接口用相对路径,换域名不用重新打包后台。
|
||||
|
||||
Dify 控制台用官方 1.19.0 镜像,并打开嵌入。本机那份带界面改动的镜像是 arm64,不能拿到这台服务器上跑。管理端免登补丁以只读文件挂进去。估价应用的 API Key 要在控制台建好应用后,写进 `.env` 的 `DIFY_VALUATION_API_KEY`,再重启 `server`。
|
||||
|
||||
继续教育第一次打开管理端时,按页面完成安装。安装口令不要用仓库示例里的默认值。
|
||||
|
||||
## 本机产物
|
||||
|
||||
`deploy/build-images.sh` 打出 linux/amd64 镜像,并打进 MySQL、Redis、MinIO。离线包在 `deploy/dist/gsfdc-bundle-<标签>.tar`。
|
||||
`deploy/build-images.sh` 打出协会站点的 linux/amd64 镜像。`deploy/prepare-extra-images.sh` 再拉取 Dify、PostgreSQL、Weaviate,并打出继续教育镜像。离线包在 `deploy/dist/gsfdc-bundle-<标签>.tar`。
|
||||
|
||||
## 服务器上
|
||||
|
||||
@@ -34,12 +57,12 @@
|
||||
2. `bash bootstrap-host.sh`。它安装 Docker、2G swap、只放行 80/443。看到未挂载的数据盘时先 `lsblk`,确认是空盘再格式化并挂到 `/data`。脚本不会自己格式化。
|
||||
3. 有证书就把 `fullchain.pem` 和 `privkey.pem` 放进 `certs/`。没有证书时先用 HTTP 把站跑起来,内容导入前再切到最终的 https 附件地址。
|
||||
4. 数据盘就绪时:`DATA_ROOT=/data/gsfdc ./init-env.sh`。然后 `./up.sh --yes`。
|
||||
5. `./create-admin.sh`。口令在 `secrets/initial-admin.txt`。
|
||||
6. `./check.sh`。
|
||||
5. `./create-admin.sh`。协会后台口令在 `secrets/initial-admin.txt`。Dify 初次口令在 `secrets/dify-init-password.txt`。
|
||||
6. `./check.sh`。继续教育的 Java 大约要一两分钟才开始听端口。
|
||||
7. `bash install-backup-cron.sh`。
|
||||
|
||||
`.env` 里的 `FIELD_AES_KEY` 只能生成一次。换掉之后,已经加密的手机号和身份证解不开。
|
||||
`.env` 里的 `FIELD_AES_KEY` 只能生成一次。换掉之后,已经加密的手机号和身份证解不开。`dify/docker/.env` 同样只生成一次,换掉之后已有的 Dify 数据对不上。
|
||||
|
||||
DNS 需要三条 A 记录:`www`、根域名、`files`,都指向这台机器。改解析前可以用临时 Host 头在服务器上自测。
|
||||
DNS 需要这些 A 记录,都指向这台机器:`www`、根域名、`files`、`ai`、`edu`、`h5`、`edu-admin`。改解析前可以用临时 Host 头在服务器上自测。
|
||||
|
||||
证书申请在域名已经指过来之后执行 `./issue-cert.sh`。申请前在 `.env` 填写 `CERTBOT_EMAIL`。证书放到位后,把 `SITE_ORIGIN`、`CORS_ORIGINS`、`MINIO_BASE_URL` 改成 https,`MINIO_PUBLIC_SECURE` 改为 true,再 `./render-nginx.sh && docker compose up -d`。已经写进数据库的附件地址不会跟着变,所以正式内容放在 https 确定之后再导入。
|
||||
证书申请在域名已经指过来之后执行 `./issue-cert.sh`。申请前在 `.env` 填写 `CERTBOT_EMAIL`。证书放到位后,把 `.env` 里的 `SITE_ORIGIN`、`CORS_ORIGINS`、`MINIO_BASE_URL`、`DIFY_PUBLIC_URL` 改成 https,`MINIO_PUBLIC_SECURE` 改为 true;把 `dify/docker/.env` 里的 `CONSOLE_WEB_URL`、`APP_WEB_URL`、`GSREA_SSO_CONSOLE_WEB_URL` 改成 https,`NEXT_PUBLIC_SOCKET_URL` 改成 wss。然后 `./render-nginx.sh && ./up.sh --yes`。已经写进数据库的附件地址不会跟着变,所以正式内容放在 https 确定之后再导入。
|
||||
+15
-2
@@ -16,6 +16,19 @@ docker compose exec -T mysql mysqldump \
|
||||
-uroot -p"${MYSQL_ROOT_PASSWORD}" \
|
||||
--single-transaction \
|
||||
--default-character-set=utf8mb4 \
|
||||
"${MYSQL_DATABASE}" | gzip -1 > "$target"
|
||||
find "${DATA_ROOT}/backups" -name 'gsfdc-*.sql.gz' -mtime +14 -delete
|
||||
--databases "${MYSQL_DATABASE}" playedu | gzip -1 > "$target"
|
||||
if docker compose -p dify \
|
||||
--env-file dify/docker/.env \
|
||||
-f dify/docker/docker-compose.yaml \
|
||||
-f dify/docker/docker-compose.gsfdc.yml \
|
||||
ps --status running --services 2>/dev/null | grep -qx db_postgres; then
|
||||
dify_target="${DATA_ROOT}/backups/dify-${stamp}.sql.gz"
|
||||
docker compose -p dify \
|
||||
--env-file dify/docker/.env \
|
||||
-f dify/docker/docker-compose.yaml \
|
||||
-f dify/docker/docker-compose.gsfdc.yml \
|
||||
exec -T db_postgres pg_dump -U postgres --no-owner dify | gzip -1 > "$dify_target"
|
||||
echo "已备份 Dify $dify_target"
|
||||
fi
|
||||
find "${DATA_ROOT}/backups" \( -name 'gsfdc-*.sql.gz' -o -name 'dify-*.sql.gz' \) -mtime +14 -delete
|
||||
echo "已备份数据库 $target"
|
||||
@@ -29,5 +29,17 @@ if curl -fsS -H "Host: ${SITE_DOMAIN}" http://127.0.0.1/api/site/health; then
|
||||
else
|
||||
code=1
|
||||
fi
|
||||
echo -n "继续教育 "
|
||||
if curl -fsS -o /dev/null -w "%{http_code}\n" -H "Host: ${EDU_DOMAIN}" http://127.0.0.1/; then
|
||||
true
|
||||
else
|
||||
code=1
|
||||
fi
|
||||
echo -n "Dify "
|
||||
if curl -fsS -o /dev/null -w "%{http_code}\n" -H "Host: ${AI_DOMAIN}" http://127.0.0.1/; then
|
||||
true
|
||||
else
|
||||
code=1
|
||||
fi
|
||||
docker compose ps
|
||||
exit "$code"
|
||||
@@ -0,0 +1,146 @@
|
||||
# 和协会站点挤在同一台 4 核 8G 上时使用。
|
||||
# 不映射宿主机端口,控制台从协会站点的 Nginx 反代进来。
|
||||
# 镜像用 -amd64 标签,避免覆盖本机 arm64 演示镜像。
|
||||
|
||||
x-log: &log
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
|
||||
services:
|
||||
init_permissions:
|
||||
image: busybox:1.36-amd64
|
||||
|
||||
api:
|
||||
image: langgenius/dify-api:1.19.0-amd64
|
||||
logging: *log
|
||||
environment:
|
||||
GSREA_SSO_SECRET: ${GSREA_SSO_SECRET:-}
|
||||
GSREA_SSO_CONSOLE_WEB_URL: ${GSREA_SSO_CONSOLE_WEB_URL:-}
|
||||
HOSTED_FETCH_APP_TEMPLATES_MODE: db
|
||||
HOSTED_FETCH_PIPELINE_TEMPLATES_MODE: database
|
||||
volumes:
|
||||
- ../api/controllers/console/auth/gsrea_sso.py:/app/api/controllers/console/auth/gsrea_sso.py:ro
|
||||
- ../api/controllers/console/__init__.py:/app/api/controllers/console/__init__.py:ro
|
||||
- ../api/services/recommended_app_catalog_gateway.py:/app/api/services/recommended_app_catalog_gateway.py:ro
|
||||
- ../api/services/rag_pipeline/rag_pipeline.py:/app/api/services/rag_pipeline/rag_pipeline.py:ro
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 768M
|
||||
|
||||
worker:
|
||||
image: langgenius/dify-api:1.19.0-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 640M
|
||||
|
||||
worker_beat:
|
||||
image: langgenius/dify-api:1.19.0-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 576M
|
||||
|
||||
web:
|
||||
image: langgenius/dify-web:1.19.0-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 256M
|
||||
|
||||
db_postgres:
|
||||
image: postgres:15-alpine-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 320M
|
||||
|
||||
redis:
|
||||
image: redis:6-alpine-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 96M
|
||||
|
||||
sandbox:
|
||||
image: langgenius/dify-sandbox:0.2.15-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 128M
|
||||
|
||||
local_sandbox:
|
||||
image: langgenius/dify-agent-local-sandbox:1.19.0-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 128M
|
||||
|
||||
plugin_daemon:
|
||||
image: langgenius/dify-plugin-daemon:0.6.14-amd64
|
||||
logging: *log
|
||||
ports: !reset []
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 256M
|
||||
|
||||
agent_backend:
|
||||
image: langgenius/dify-agent-backend:1.19.0-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 256M
|
||||
|
||||
agent_ssrf_proxy:
|
||||
image: ubuntu/squid:latest-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 48M
|
||||
|
||||
ssrf_proxy:
|
||||
image: ubuntu/squid:latest-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 48M
|
||||
|
||||
nginx:
|
||||
image: nginx:1.27-amd64
|
||||
container_name: dify-nginx
|
||||
logging: *log
|
||||
ports: !reset []
|
||||
networks:
|
||||
- default
|
||||
- gsfdc
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 48M
|
||||
|
||||
weaviate:
|
||||
image: weaviate:1.39.13-amd64
|
||||
logging: *log
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 192M
|
||||
|
||||
networks:
|
||||
gsfdc:
|
||||
external: true
|
||||
name: gsfdc
|
||||
@@ -18,6 +18,7 @@ services:
|
||||
MYSQL_USER: ${MYSQL_USER}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
||||
PLAYEDU_DB_PASSWORD: ${PLAYEDU_DB_PASSWORD}
|
||||
TZ: Asia/Shanghai
|
||||
command:
|
||||
- --character-set-server=utf8mb4
|
||||
@@ -25,7 +26,8 @@ services:
|
||||
volumes:
|
||||
- ${DATA_ROOT}/mysql:/var/lib/mysql
|
||||
- ./mysql/my.cnf:/etc/mysql/conf.d/gsfdc.cnf:ro
|
||||
shm_size: 256m
|
||||
- ./mysql/init:/docker-entrypoint-initdb.d:ro
|
||||
shm_size: 128m
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p\"$$MYSQL_ROOT_PASSWORD\" --silent"]
|
||||
interval: 10s
|
||||
@@ -35,7 +37,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 1400M
|
||||
memory: 1024M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
@@ -50,7 +52,7 @@ services:
|
||||
- --appendonly
|
||||
- "yes"
|
||||
- --maxmemory
|
||||
- 128mb
|
||||
- 64mb
|
||||
- --maxmemory-policy
|
||||
- allkeys-lru
|
||||
- --requirepass
|
||||
@@ -68,7 +70,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 192M
|
||||
memory: 128M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
@@ -88,7 +90,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 384M
|
||||
memory: 256M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
@@ -125,6 +127,10 @@ services:
|
||||
CORS_ORIGINS: ${CORS_ORIGINS}
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
FIELD_AES_KEY: ${FIELD_AES_KEY}
|
||||
DIFY_PUBLIC_URL: ${DIFY_PUBLIC_URL}
|
||||
DIFY_API_BASE: http://dify-nginx/v1
|
||||
DIFY_SSO_SECRET: ${DIFY_SSO_SECRET}
|
||||
DIFY_VALUATION_API_KEY: ${DIFY_VALUATION_API_KEY:-}
|
||||
UVICORN_WORKERS: "1"
|
||||
TZ: Asia/Shanghai
|
||||
depends_on:
|
||||
@@ -143,7 +149,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 768M
|
||||
memory: 512M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
@@ -159,7 +165,7 @@ services:
|
||||
NITRO_HOST: 0.0.0.0
|
||||
NITRO_PORT: "3000"
|
||||
NODE_ENV: production
|
||||
NODE_OPTIONS: --max-old-space-size=384
|
||||
NODE_OPTIONS: --max-old-space-size=320
|
||||
NUXT_API_BASE: http://server:8000/api/site
|
||||
NUXT_PUBLIC_API_BASE: /api/site
|
||||
TZ: Asia/Shanghai
|
||||
@@ -175,7 +181,7 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 640M
|
||||
memory: 512M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
@@ -206,7 +212,41 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 128M
|
||||
memory: 64M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
playedu:
|
||||
image: gsfdc-playedu:${IMAGE_TAG}
|
||||
container_name: gsfdc-playedu
|
||||
restart: unless-stopped
|
||||
init: true
|
||||
logging: *logging
|
||||
environment:
|
||||
DB_HOST: mysql
|
||||
DB_PORT: "3306"
|
||||
DB_NAME: playedu
|
||||
DB_USER: playedu
|
||||
DB_PASS: ${PLAYEDU_DB_PASSWORD}
|
||||
DB_POOL_MIN_IDLE: "1"
|
||||
DB_POOL_MAX_SIZE: "4"
|
||||
SA_TOKEN_IS_CONCURRENT: "false"
|
||||
SA_TOKEN_JWT_SECRET_KEY: ${PLAYEDU_JWT_KEY}
|
||||
DEMO_MODE: "false"
|
||||
TZ: Asia/Shanghai
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "bash -c 'echo > /dev/tcp/127.0.0.1/9898'"]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 90s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
networks:
|
||||
- gsfdc
|
||||
|
||||
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
# 生成 Dify 自己的 .env。不读取、不复制本机演示目录里的密钥。
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
if [[ ! -f .env ]]; then
|
||||
echo "缺少 .env,先执行 ./init-env.sh"
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p dify/docker secrets
|
||||
if [[ -f dify/docker/.env ]]; then
|
||||
echo "dify/docker/.env 已存在,保持不变"
|
||||
exit 0
|
||||
fi
|
||||
umask 077
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source .env
|
||||
set +a
|
||||
python3 - <<'PY'
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
def q(value: str) -> str:
|
||||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
|
||||
public = os.environ["DIFY_PUBLIC_URL"].strip().rstrip("/")
|
||||
scheme = "wss" if public.startswith("https://") else "ws"
|
||||
host = public.split("://", 1)[1]
|
||||
db_password = secrets.token_hex(24)
|
||||
redis_password = secrets.token_hex(24)
|
||||
sandbox_key = secrets.token_urlsafe(32)
|
||||
plugin_key = secrets.token_urlsafe(32)
|
||||
inner_key = secrets.token_urlsafe(32)
|
||||
secret_key = secrets.token_hex(32)
|
||||
init_password = "Aa" + secrets.token_hex(12)
|
||||
agent_token = secrets.token_hex(32)
|
||||
agent_secret = secrets.token_hex(32)
|
||||
|
||||
lines = [
|
||||
"COMPOSE_PROFILES=weaviate,postgresql",
|
||||
"VECTOR_STORE=weaviate",
|
||||
"NGINX_HTTPS_ENABLED=false",
|
||||
"NGINX_WORKER_PROCESSES=1",
|
||||
"NGINX_SOCKET_IO_UPSTREAM=api:5001",
|
||||
"NGINX_CLIENT_MAX_BODY_SIZE=100M",
|
||||
"SERVER_WORKER_AMOUNT=1",
|
||||
"CELERY_WORKER_AMOUNT=1",
|
||||
"ALLOW_EMBED=true",
|
||||
f"CONSOLE_WEB_URL={q(public)}",
|
||||
f"APP_WEB_URL={q(public)}",
|
||||
f"NEXT_PUBLIC_SOCKET_URL={q(f'{scheme}://{host}')}",
|
||||
f"GSREA_SSO_SECRET={q(os.environ['DIFY_SSO_SECRET'].strip())}",
|
||||
f"GSREA_SSO_CONSOLE_WEB_URL={q(public)}",
|
||||
f"DB_PASSWORD={q(db_password)}",
|
||||
f"POSTGRES_PASSWORD={q(db_password)}",
|
||||
"POSTGRES_MAX_CONNECTIONS=40",
|
||||
"POSTGRES_SHARED_BUFFERS=64MB",
|
||||
"POSTGRES_WORK_MEM=2MB",
|
||||
"POSTGRES_MAINTENANCE_WORK_MEM=32MB",
|
||||
"POSTGRES_EFFECTIVE_CACHE_SIZE=256MB",
|
||||
f"REDIS_PASSWORD={q(redis_password)}",
|
||||
f"SECRET_KEY={q(secret_key)}",
|
||||
f"INIT_PASSWORD={q(init_password)}",
|
||||
f"SANDBOX_API_KEY={q(sandbox_key)}",
|
||||
f"CODE_EXECUTION_API_KEY={q(sandbox_key)}",
|
||||
f"PLUGIN_DAEMON_KEY={q(plugin_key)}",
|
||||
f"PLUGIN_DIFY_INNER_API_KEY={q(inner_key)}",
|
||||
f"DIFY_AGENT_LOCAL_SANDBOX_AUTH_TOKEN={q(agent_token)}",
|
||||
f"DIFY_AGENT_SERVER_SECRET_KEY={q(agent_secret)}",
|
||||
"EXPOSE_NGINX_PORT=127.0.0.1:18080",
|
||||
"EXPOSE_NGINX_SSL_PORT=127.0.0.1:18443",
|
||||
"EXPOSE_PLUGIN_DEBUGGING_PORT=127.0.0.1:15003",
|
||||
]
|
||||
target = Path("dify/docker/.env")
|
||||
target.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
os.chmod(target, 0o600)
|
||||
note = Path("secrets/dify-init-password.txt")
|
||||
note.write_text(init_password + "\n", encoding="utf-8")
|
||||
os.chmod(note, 0o600)
|
||||
print("已生成 dify/docker/.env 。初次登录口令在 secrets/dify-init-password.txt")
|
||||
PY
|
||||
+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
|
||||
@@ -15,7 +15,7 @@ if [[ -z "${CERTBOT_EMAIL:-}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p certs certbot
|
||||
domains=(-d "$SITE_DOMAIN" -d "$FILES_DOMAIN")
|
||||
domains=(-d "$SITE_DOMAIN" -d "$FILES_DOMAIN" -d "$AI_DOMAIN" -d "$EDU_DOMAIN" -d "$EDU_H5_DOMAIN" -d "$EDU_ADMIN_DOMAIN")
|
||||
apex="${SITE_DOMAIN#www.}"
|
||||
if [[ "$apex" != "$SITE_DOMAIN" ]]; then
|
||||
domains+=(-d "$apex")
|
||||
@@ -26,4 +26,4 @@ docker run --rm \
|
||||
certbot/certbot certonly --webroot -w /var/www/certbot \
|
||||
--email "$CERTBOT_EMAIL" --agree-tos --no-eff-email \
|
||||
"${domains[@]}"
|
||||
echo "证书已写入 certs/live/${SITE_DOMAIN}/ 。接着修改 .env 里的站点地址为 https,再执行 ./render-nginx.sh && docker compose up -d"
|
||||
echo "证书已写入 certs/live/${SITE_DOMAIN}/ 。接着把 .env 里的站点地址和 DIFY_PUBLIC_URL 改成 https,dify/docker/.env 里的 CONSOLE_WEB_URL、APP_WEB_URL、GSREA_SSO_CONSOLE_WEB_URL 改成 https,NEXT_PUBLIC_SOCKET_URL 改成 wss,再执行 ./render-nginx.sh && ./up.sh --yes"
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
# 只在数据目录第一次初始化时执行。协会库和继续教育库共用这一台 MySQL。
|
||||
set -eu
|
||||
mysql --protocol=socket -uroot -p"${MYSQL_ROOT_PASSWORD}" <<SQL
|
||||
CREATE DATABASE IF NOT EXISTS playedu CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
CREATE USER IF NOT EXISTS 'playedu'@'%' IDENTIFIED BY '${PLAYEDU_DB_PASSWORD}';
|
||||
ALTER USER 'playedu'@'%' IDENTIFIED BY '${PLAYEDU_DB_PASSWORD}';
|
||||
GRANT ALL PRIVILEGES ON playedu.* TO 'playedu'@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
SQL
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
[mysqld]
|
||||
character-set-server = utf8mb4
|
||||
collation-server = utf8mb4_unicode_ci
|
||||
innodb_buffer_pool_size = 256M
|
||||
innodb_buffer_pool_size = 192M
|
||||
innodb_log_buffer_size = 16M
|
||||
max_connections = 80
|
||||
max_connections = 60
|
||||
performance_schema = OFF
|
||||
table_open_cache = 400
|
||||
skip-name-resolve
|
||||
|
||||
@@ -6,6 +6,11 @@ gzip_min_length 1024;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
|
||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
"" close;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${SITE_NAMES};
|
||||
@@ -77,3 +82,101 @@ server {
|
||||
proxy_buffering off;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${AI_DOMAIN};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
default_type "text/plain";
|
||||
}
|
||||
|
||||
client_max_body_size 100m;
|
||||
|
||||
location / {
|
||||
set $dify_backend dify-nginx;
|
||||
proxy_pass http://$dify_backend:80;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${EDU_DOMAIN};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
default_type "text/plain";
|
||||
}
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_backend playedu;
|
||||
proxy_pass http://$edu_backend:9800;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${EDU_H5_DOMAIN};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
default_type "text/plain";
|
||||
}
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_h5_backend playedu;
|
||||
proxy_pass http://$edu_h5_backend:9801;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${EDU_ADMIN_DOMAIN};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
default_type "text/plain";
|
||||
}
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_admin_backend playedu;
|
||||
proxy_pass http://$edu_admin_backend:9900;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,18 @@ gzip_comp_level 5;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
|
||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
"" close;
|
||||
}
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${SITE_NAMES} ${FILES_DOMAIN};
|
||||
server_name ${SITE_NAMES} ${FILES_DOMAIN} ${AI_DOMAIN} ${EDU_DOMAIN} ${EDU_H5_DOMAIN} ${EDU_ADMIN_DOMAIN};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
@@ -89,3 +94,89 @@ server {
|
||||
proxy_buffering off;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name ${AI_DOMAIN};
|
||||
ssl_certificate ${CERT_FULL};
|
||||
ssl_certificate_key ${CERT_KEY};
|
||||
|
||||
client_max_body_size 100m;
|
||||
|
||||
location / {
|
||||
set $dify_backend dify-nginx;
|
||||
proxy_pass http://$dify_backend:80;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name ${EDU_DOMAIN};
|
||||
ssl_certificate ${CERT_FULL};
|
||||
ssl_certificate_key ${CERT_KEY};
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_backend playedu;
|
||||
proxy_pass http://$edu_backend:9800;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name ${EDU_H5_DOMAIN};
|
||||
ssl_certificate ${CERT_FULL};
|
||||
ssl_certificate_key ${CERT_KEY};
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_h5_backend playedu;
|
||||
proxy_pass http://$edu_h5_backend:9801;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name ${EDU_ADMIN_DOMAIN};
|
||||
ssl_certificate ${CERT_FULL};
|
||||
ssl_certificate_key ${CERT_KEY};
|
||||
|
||||
client_max_body_size 200m;
|
||||
|
||||
location / {
|
||||
set $edu_admin_backend playedu;
|
||||
proxy_pass http://$edu_admin_backend:9900;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
@@ -8,23 +8,60 @@ fi
|
||||
OUT="$ROOT/deploy/dist"
|
||||
STAGE="$OUT/gsfdc-bundle"
|
||||
rm -rf "$STAGE"
|
||||
mkdir -p "$STAGE/nginx" "$STAGE/mysql" "$STAGE/certs" "$STAGE/certbot"
|
||||
mkdir -p "$STAGE/nginx" "$STAGE/mysql/init" "$STAGE/certs" "$STAGE/certbot"
|
||||
|
||||
cp "$ROOT/deploy/docker-compose.yml" "$ROOT/deploy/.env.example" "$STAGE/"
|
||||
cp "$ROOT/deploy/IMAGE_TAG" "$STAGE/" 2>/dev/null || echo "$TAG" > "$STAGE/IMAGE_TAG"
|
||||
cp "$ROOT/deploy/"*.sh "$STAGE/"
|
||||
cp "$ROOT/deploy/nginx/"*.template "$STAGE/nginx/"
|
||||
cp "$ROOT/deploy/mysql/my.cnf" "$STAGE/mysql/"
|
||||
mkdir -p "$STAGE/mysql/init"
|
||||
cp "$ROOT/deploy/mysql/init/02-playedu.sh" "$STAGE/mysql/init/"
|
||||
cp "$ROOT/deploy/README.md" "$STAGE/" 2>/dev/null || true
|
||||
|
||||
echo "打包镜像(含 MySQL、Redis、MinIO)"
|
||||
echo "放入 Dify 编排和免登补丁,不带本机数据和密钥"
|
||||
mkdir -p "$STAGE/dify/api/controllers/console/auth" \
|
||||
"$STAGE/dify/api/services/rag_pipeline"
|
||||
rsync -a \
|
||||
--exclude volumes \
|
||||
--exclude tests \
|
||||
--exclude certbot \
|
||||
--exclude '*.png' \
|
||||
--exclude .env \
|
||||
--exclude .gsrea_sso_secret \
|
||||
--exclude docker-compose.override.yaml \
|
||||
"$ROOT/demo-dify/dify/docker/" "$STAGE/dify/docker/"
|
||||
cp "$ROOT/deploy/dify/docker-compose.gsfdc.yml" "$STAGE/dify/docker/docker-compose.gsfdc.yml"
|
||||
cp "$ROOT/demo-dify/dify/api/controllers/console/auth/gsrea_sso.py" \
|
||||
"$STAGE/dify/api/controllers/console/auth/"
|
||||
cp "$ROOT/demo-dify/dify/api/controllers/console/__init__.py" \
|
||||
"$STAGE/dify/api/controllers/console/"
|
||||
cp "$ROOT/demo-dify/dify/api/services/recommended_app_catalog_gateway.py" \
|
||||
"$STAGE/dify/api/services/"
|
||||
cp "$ROOT/demo-dify/dify/api/services/rag_pipeline/rag_pipeline.py" \
|
||||
"$STAGE/dify/api/services/rag_pipeline/"
|
||||
|
||||
echo "打包镜像(协会站点、继续教育、Dify)"
|
||||
docker save \
|
||||
"gsfdc-server:${TAG}" \
|
||||
"gsfdc-portal:${TAG}" \
|
||||
"gsfdc-web:${TAG}" \
|
||||
"gsfdc-playedu:${TAG}" \
|
||||
mysql:8.0 \
|
||||
redis:7.4-alpine \
|
||||
minio/minio:latest \
|
||||
langgenius/dify-api:1.19.0-amd64 \
|
||||
langgenius/dify-web:1.19.0-amd64 \
|
||||
langgenius/dify-plugin-daemon:0.6.14-amd64 \
|
||||
langgenius/dify-sandbox:0.2.15-amd64 \
|
||||
langgenius/dify-agent-backend:1.19.0-amd64 \
|
||||
langgenius/dify-agent-local-sandbox:1.19.0-amd64 \
|
||||
postgres:15-alpine-amd64 \
|
||||
redis:6-alpine-amd64 \
|
||||
nginx:1.27-amd64 \
|
||||
busybox:1.36-amd64 \
|
||||
ubuntu/squid:latest-amd64 \
|
||||
weaviate:1.39.13-amd64 \
|
||||
| gzip -1 > "$STAGE/images.tar.gz"
|
||||
|
||||
tar -C "$OUT" -cf "$OUT/gsfdc-bundle-${TAG}.tar" gsfdc-bundle
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
FROM eclipse-temurin:17-jre-jammy-amd64
|
||||
|
||||
RUN sed -i \
|
||||
-e 's|http://archive.ubuntu.com|http://mirrors.aliyun.com|g' \
|
||||
-e 's|http://security.ubuntu.com|http://mirrors.aliyun.com|g' \
|
||||
/etc/apt/sources.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends nginx curl \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
COPY nginx.conf /etc/nginx/sites-enabled/default
|
||||
COPY app.jar /app/api/app.jar
|
||||
COPY pc /app/pc
|
||||
COPY h5 /app/h5
|
||||
COPY admin /app/admin
|
||||
|
||||
ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:InitialRAMPercentage=20 -XX:MaxRAMPercentage=60"
|
||||
EXPOSE 9898 9800 9801 9900
|
||||
|
||||
CMD ["sh", "-c", "nginx && exec java -jar /app/api/app.jar"]
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
# 拉取并展开教育平台、Dify 的 linux/amd64 镜像。不改本机 arm64 标签。
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
ROOT="$(cd .. && pwd)"
|
||||
python3 pull-extra.py
|
||||
|
||||
materialize() {
|
||||
echo "展开 $1"
|
||||
docker buildx build --platform linux/amd64 --provenance=false --sbom=false --load -t "$1" - <<EOF
|
||||
FROM $1
|
||||
EOF
|
||||
}
|
||||
|
||||
for image in \
|
||||
langgenius/dify-api:1.19.0-amd64 \
|
||||
langgenius/dify-web:1.19.0-amd64 \
|
||||
langgenius/dify-plugin-daemon:0.6.14-amd64 \
|
||||
langgenius/dify-sandbox:0.2.15-amd64 \
|
||||
langgenius/dify-agent-backend:1.19.0-amd64 \
|
||||
langgenius/dify-agent-local-sandbox:1.19.0-amd64 \
|
||||
postgres:15-alpine-amd64 \
|
||||
redis:6-alpine-amd64 \
|
||||
nginx:1.27-amd64 \
|
||||
busybox:1.36-amd64 \
|
||||
ubuntu/squid:latest-amd64 \
|
||||
weaviate:1.39.13-amd64 \
|
||||
eclipse-temurin:17-jre-jammy-amd64
|
||||
do
|
||||
materialize "$image"
|
||||
arch="$(docker image inspect -f '{{.Architecture}}' "$image")"
|
||||
if [[ "$arch" != "amd64" ]]; then
|
||||
echo "$image 架构是 $arch"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
TAG="20261123"
|
||||
if [[ -f IMAGE_TAG ]]; then
|
||||
TAG="$(tr -d '[:space:]' < IMAGE_TAG)"
|
||||
fi
|
||||
STAGE="playedu/stage"
|
||||
rm -rf "$STAGE"
|
||||
mkdir -p "$STAGE/pc" "$STAGE/h5" "$STAGE/admin"
|
||||
cp playedu/Dockerfile "$STAGE/Dockerfile"
|
||||
cp "$ROOT/demo-playedu/playedu/docker/nginx/conf/nginx.conf" "$STAGE/nginx.conf"
|
||||
cp "$ROOT/demo-playedu/playedu/playedu-api/playedu-api/target/playedu-api.jar" "$STAGE/app.jar"
|
||||
cp -R "$ROOT/demo-playedu/playedu/playedu-pc/dist/." "$STAGE/pc/"
|
||||
cp -R "$ROOT/demo-playedu/playedu/playedu-h5/dist/." "$STAGE/h5/"
|
||||
cp -R "$ROOT/demo-playedu/playedu/playedu-admin/dist/." "$STAGE/admin/"
|
||||
docker buildx build --platform linux/amd64 --provenance=false --sbom=false --load \
|
||||
-t "gsfdc-playedu:${TAG}" "$STAGE"
|
||||
arch="$(docker image inspect -f '{{.Architecture}}' "gsfdc-playedu:${TAG}")"
|
||||
if [[ "$arch" != "amd64" ]]; then
|
||||
echo "playedu 架构是 $arch"
|
||||
exit 1
|
||||
fi
|
||||
echo "EXTRA_IMAGES_READY"
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env python3
|
||||
"""拉取教育平台和 Dify 要用的 linux/amd64 镜像。
|
||||
|
||||
打成独立的 -amd64 标签,不改本机正在使用的 arm64 标签。
|
||||
"""
|
||||
import json
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
SOCK = "/Users/zlwu/.docker/run/docker.sock"
|
||||
# 每个目标先试前面的镜像源。拉到的是清单时,后面再用 buildx 展开成真实层。
|
||||
IMAGES = [
|
||||
(
|
||||
[("docker.1ms.run/langgenius/dify-api", "1.19.0")],
|
||||
"langgenius/dify-api:1.19.0-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/langgenius/dify-web", "1.19.0")],
|
||||
"langgenius/dify-web:1.19.0-amd64",
|
||||
),
|
||||
(
|
||||
[
|
||||
("docker.1ms.run/langgenius/dify-plugin-daemon", "0.6.14"),
|
||||
("docker.1ms.run/langgenius/dify-plugin-daemon", "0.6.14-local"),
|
||||
],
|
||||
"langgenius/dify-plugin-daemon:0.6.14-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/langgenius/dify-sandbox", "0.2.15")],
|
||||
"langgenius/dify-sandbox:0.2.15-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/langgenius/dify-agent-backend", "1.19.0")],
|
||||
"langgenius/dify-agent-backend:1.19.0-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/langgenius/dify-agent-local-sandbox", "1.19.0")],
|
||||
"langgenius/dify-agent-local-sandbox:1.19.0-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/library/postgres", "15-alpine")],
|
||||
"postgres:15-alpine-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/library/redis", "6-alpine")],
|
||||
"redis:6-alpine-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/library/nginx", "1.27")],
|
||||
"nginx:1.27-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/library/busybox", "1.36")],
|
||||
"busybox:1.36-amd64",
|
||||
),
|
||||
(
|
||||
[
|
||||
("docker.1ms.run/ubuntu/squid", "latest"),
|
||||
("docker.1panel.live/ubuntu/squid", "latest"),
|
||||
],
|
||||
"ubuntu/squid:latest-amd64",
|
||||
),
|
||||
(
|
||||
[
|
||||
("docker.1ms.run/semitechnologies/weaviate", "1.39.13"),
|
||||
("docker.1panel.live/semitechnologies/weaviate", "1.39.13"),
|
||||
],
|
||||
"weaviate:1.39.13-amd64",
|
||||
),
|
||||
(
|
||||
[("docker.1ms.run/library/eclipse-temurin", "17-jre-jammy")],
|
||||
"eclipse-temurin:17-jre-jammy-amd64",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def request(method: str, path: str) -> bytes:
|
||||
header = (
|
||||
f"{method} {path} HTTP/1.1\r\n"
|
||||
"Host: localhost\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n"
|
||||
).encode()
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.settimeout(3600)
|
||||
sock.connect(SOCK)
|
||||
sock.sendall(header)
|
||||
chunks = []
|
||||
while True:
|
||||
try:
|
||||
data = sock.recv(65536)
|
||||
except socket.timeout:
|
||||
raise SystemExit(f"引擎没有在时限内完成 {path}")
|
||||
if not data:
|
||||
break
|
||||
chunks.append(data)
|
||||
sock.close()
|
||||
raw = b"".join(chunks)
|
||||
head, _, payload = raw.partition(b"\r\n\r\n")
|
||||
status = head.split(b" ", 2)[1]
|
||||
if status not in (b"200", b"201"):
|
||||
raise SystemExit(f"{path} -> {status.decode()} {payload[:400]!r}")
|
||||
return payload
|
||||
|
||||
|
||||
def stream(path: str) -> None:
|
||||
header = (
|
||||
f"POST {path} HTTP/1.1\r\n"
|
||||
"Host: localhost\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n"
|
||||
).encode()
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.settimeout(3600)
|
||||
sock.connect(SOCK)
|
||||
sock.sendall(header)
|
||||
buffer = b""
|
||||
header_done = False
|
||||
error = None
|
||||
last = ""
|
||||
while True:
|
||||
try:
|
||||
data = sock.recv(65536)
|
||||
except socket.timeout:
|
||||
sock.close()
|
||||
raise SystemExit(f"引擎没有在时限内完成 {path}")
|
||||
if not data:
|
||||
break
|
||||
buffer += data
|
||||
if not header_done:
|
||||
if b"\r\n\r\n" not in buffer:
|
||||
continue
|
||||
head, buffer = buffer.split(b"\r\n\r\n", 1)
|
||||
status = head.split(b" ", 2)[1]
|
||||
if status not in (b"200", b"201"):
|
||||
sock.close()
|
||||
raise SystemExit(f"{path} -> {status.decode()} {buffer[:400]!r}")
|
||||
header_done = True
|
||||
while b"\n" in buffer:
|
||||
line, buffer = buffer.split(b"\n", 1)
|
||||
line = line.strip()
|
||||
if not line.startswith(b"{"):
|
||||
continue
|
||||
try:
|
||||
item = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
if "error" in item:
|
||||
error = item["error"]
|
||||
status_text = item.get("status") or ""
|
||||
if status_text and status_text != last:
|
||||
last = status_text
|
||||
print(f" {status_text}", flush=True)
|
||||
sock.close()
|
||||
if error:
|
||||
raise SystemExit(error)
|
||||
|
||||
|
||||
def pull_one(source: str, tag: str, official: str) -> None:
|
||||
query = urllib.parse.urlencode(
|
||||
{"fromImage": source, "tag": tag, "platform": "linux/amd64"}
|
||||
)
|
||||
print(f"拉取 {source}:{tag}", flush=True)
|
||||
stream(f"/v1.47/images/create?{query}")
|
||||
source_ref = f"{source}:{tag}"
|
||||
repo, official_tag = official.rsplit(":", 1)
|
||||
tag_query = urllib.parse.urlencode({"repo": repo, "tag": official_tag})
|
||||
encoded = urllib.parse.quote(source_ref, safe="")
|
||||
request("POST", f"/v1.47/images/{encoded}/tag?{tag_query}")
|
||||
print(f"已标记 {official}", flush=True)
|
||||
|
||||
|
||||
def already_amd64(official: str) -> bool:
|
||||
try:
|
||||
data = json.loads(
|
||||
subprocess.check_output(
|
||||
["docker", "image", "inspect", official], stderr=subprocess.DEVNULL
|
||||
)
|
||||
)[0]
|
||||
except (subprocess.CalledProcessError, IndexError, json.JSONDecodeError):
|
||||
return False
|
||||
return data.get("Architecture") == "amd64" and int(data.get("Size") or 0) > 1_000_000
|
||||
|
||||
|
||||
def main() -> None:
|
||||
for candidates, official in IMAGES:
|
||||
if already_amd64(official):
|
||||
print(f"已有 amd64 镜像,跳过 {official}", flush=True)
|
||||
continue
|
||||
last_error = None
|
||||
for source, tag in candidates:
|
||||
try:
|
||||
pull_one(source, tag, official)
|
||||
last_error = None
|
||||
break
|
||||
except SystemExit as exc:
|
||||
last_error = exc
|
||||
print(f" 失败,换下一个源: {exc}", flush=True)
|
||||
if last_error is not None:
|
||||
raise last_error
|
||||
print("EXTRA_IMAGES_OK", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except BrokenPipeError:
|
||||
sys.exit(1)
|
||||
@@ -39,6 +39,10 @@ text = src.read_text(encoding="utf-8")
|
||||
values = {
|
||||
"SITE_NAMES": names,
|
||||
"FILES_DOMAIN": files,
|
||||
"AI_DOMAIN": os.environ["AI_DOMAIN"].strip(),
|
||||
"EDU_DOMAIN": os.environ["EDU_DOMAIN"].strip(),
|
||||
"EDU_H5_DOMAIN": os.environ["EDU_H5_DOMAIN"].strip(),
|
||||
"EDU_ADMIN_DOMAIN": os.environ["EDU_ADMIN_DOMAIN"].strip(),
|
||||
"CERT_FULL": cert_full,
|
||||
"CERT_KEY": cert_key,
|
||||
}
|
||||
|
||||
+35
-5
@@ -1,15 +1,45 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
created=0
|
||||
if [[ ! -f .env ]]; then
|
||||
./init-env.sh
|
||||
created=1
|
||||
existed=0
|
||||
if [[ -f .env ]]; then
|
||||
existed=1
|
||||
fi
|
||||
./init-env.sh
|
||||
./init-dify-env.sh
|
||||
./render-nginx.sh
|
||||
if [[ "$created" == 1 && "${1:-}" != "--yes" ]]; then
|
||||
if [[ "$existed" == 0 && "${1:-}" != "--yes" ]]; then
|
||||
echo "请先核对 .env 里的域名。确认后执行 ./up.sh --yes"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source .env
|
||||
set +a
|
||||
|
||||
docker compose --env-file .env up -d
|
||||
|
||||
mkdir -p "${DATA_ROOT}/dify" dify/docker
|
||||
data_dir="$(cd "${DATA_ROOT}/dify" && pwd)"
|
||||
if [[ -e dify/docker/volumes && ! -L dify/docker/volumes ]]; then
|
||||
echo "dify/docker/volumes 已是目录,继续使用里面的数据"
|
||||
else
|
||||
ln -sfn "$data_dir" dify/docker/volumes
|
||||
fi
|
||||
|
||||
(
|
||||
unset REDIS_PASSWORD
|
||||
docker compose -p dify \
|
||||
--env-file dify/docker/.env \
|
||||
-f dify/docker/docker-compose.yaml \
|
||||
-f dify/docker/docker-compose.gsfdc.yml \
|
||||
up -d
|
||||
)
|
||||
|
||||
docker compose ps
|
||||
docker compose -p dify \
|
||||
--env-file dify/docker/.env \
|
||||
-f dify/docker/docker-compose.yaml \
|
||||
-f dify/docker/docker-compose.gsfdc.yml \
|
||||
ps
|
||||
Reference in new issue
Block a user