包含 s-file 后端、React 前端、MeshSafe 安全检测对接,以及内外网两套 compose/nginx/配置(仅前端 28180/28280 对外发布,其余端口不暴露)。 说明:deploy/config/application-iw.yml 与 application-ow.yml 按维护者 明确要求原样入库,其中含本机 Docker 用的库口令、RabbitMQ 口令与 JWT 密钥;上生产前需替换。
94 lines
5.1 KiB
Markdown
94 lines
5.1 KiB
Markdown
# s-file 本机 docker 部署说明(内网侧 + 外网侧两套)
|
||
|
||
> 环境:Windows + Docker Desktop 4.54,MeshSafe 复用本机已运行的 `meshsafe-nginx:44380`
|
||
> 编排文件:`deploy/docker-compose.yml`
|
||
|
||
## 1. 访问入口
|
||
|
||
| 侧 | 地址 | 前端包 | 后端 `file.transfer.location` |
|
||
|---|---|---|---|
|
||
| 内网 | http://本机IP:28180 | `VITE_IS_INSIDE=true` | `1` |
|
||
| 外网 | http://本机IP:28280 | `VITE_IS_INSIDE=false` | `2` |
|
||
|
||
只有这两个 80 端口映射到宿主机(`0.0.0.0`,便于局域网真机联调)。后端 8080、PostgreSQL、Redis、RabbitMQ 全部只在容器网络内通信,**不映射宿主机端口**;nginx 通过 `location /api/ → http://app-xx:8080/` 反代并去掉 `/api` 前缀。
|
||
|
||
## 2. 容器与网段
|
||
|
||
| 内网侧 | 外网侧 | 说明 |
|
||
|---|---|---|
|
||
| `sfile-iw-web` | `sfile-ow-web` | nginx:alpine(本机已有) |
|
||
| `sfile-iw-app` | `sfile-ow-app` | sfile-app:local(eclipse-temurin:8-jre-jammy + s-file.jar) |
|
||
| `sfile-iw-pg` | `sfile-ow-pg` | postgres:latest(本机已有,18.3) |
|
||
| `sfile-iw-redis` | `sfile-ow-redis` | redis:latest(本机已有) |
|
||
| `sfile-iw-mq` | `sfile-ow-mq` | rabbitmq:3-management-alpine(本机已有) |
|
||
| 网络 `sfile_iw_net` 172.25.18.0/24 | 网络 `sfile_ow_net` 172.25.28.0/24 | 两侧物理隔离,仅通过摆渡目录互通 |
|
||
|
||
app 容器固定 IP(`172.25.18.10` / `172.25.28.10`),对应雪花 workerId `1` / `2`,两侧必须不同;改网段时同步改 `deploy/config/application-*.yml` 里的 `[code.snowflake.workid.<ip>]` 与 compose 的 `CODE_SNOWFLAKE_WORKID_*` 环境变量。
|
||
|
||
## 3. 摆渡目录(模拟光闸)
|
||
|
||
宿主机根目录:`D:/zcodedata/sfile/`(可用 `.env` 的 `SFILE_DATA` 覆盖)
|
||
|
||
| 目录 | 内网侧挂载 | 外网侧挂载 |
|
||
|---|---|---|
|
||
| `gate/iw2ow` | `/data/transfer/send` | `/data/transfer/receive` |
|
||
| `gate/ow2iw` | `/data/transfer/receive` | `/data/transfer/send` |
|
||
| `iw/upload`、`ow/upload` | 各自 `/data/upload` | 网盘物理文件,两侧独立 |
|
||
|
||
内网「我的发送」写入 `gate/iw2ow`,外网侧 `TransferFileMonitorJob` 扫描自己的 receive 目录解包入库并触发 MeshSafe 送检,反方向同理。
|
||
|
||
## 4. MeshSafe 对接
|
||
|
||
`deploy/config/application-iw.yml` / `application-ow.yml`:
|
||
|
||
```yaml
|
||
meshsafe:
|
||
enabled: true
|
||
base-url: http://host.docker.internal:44380 # 本机 meshsafe-nginx
|
||
client-id: test-client # 需在 MeshSafe .env 的 MESHSAFE_API_CLIENTS 白名单内
|
||
secret: test-secret
|
||
fail-open: true # 本地联调优先可用性;安全优先部署改 false
|
||
```
|
||
|
||
compose 给 app 容器加了 `extra_hosts: host.docker.internal:host-gateway`。上线前把两侧 channel 区分(`sfile-iw` / `sfile-ow`)并保持 MeshSafe 策略 `engine_failure_mode: fail_closed`。
|
||
|
||
## 5. 构建与启动
|
||
|
||
```bash
|
||
# 1) 后端 jar(需 JDK8 + Maven,本机已装在 D:/dev/jdk8、D:/dev/maven-tmp)
|
||
cd backend
|
||
JAVA_HOME=D:/dev/jdk8/jdk8u504-b01 mvn -s D:/dev/maven-conf/settings.xml clean package -DskipTests
|
||
|
||
# 2) 镜像
|
||
docker build -f deploy/docker/Dockerfile.app -t sfile-app:local backend/target
|
||
docker build -f deploy/docker/Dockerfile.web -t sfile-web:local frontend # 一次产出内网+外网两个站点
|
||
|
||
# 3) 启动(首次会执行 backend/db 的 PG 初始化脚本建 62 张表)
|
||
cd deploy && docker compose up -d
|
||
```
|
||
|
||
常用运维:
|
||
|
||
```bash
|
||
docker compose ps # 全部 10 个容器应为 healthy
|
||
docker compose restart app-iw app-ow # 改配置后重启后端
|
||
docker compose logs -f app-iw
|
||
docker compose down # 停止(保留数据卷与摆渡目录)
|
||
```
|
||
|
||
## 6. 已知取舍
|
||
|
||
- **spire.pdf 3.7.4**:公共仓库无此版本,本机用按 `PdfUtils.java` 引用签名手写的桩 jar(`~/.m2/repository/e-iceblue/spire.pdf/3.7.4/`)保证编译打包通过;**PDF 盖章功能运行时不可用**,正式环境需替换公司私服的真实 jar。
|
||
- **前端 `VITE_API_URL=/api`**:`.env.production` 原值为空,容器构建时用 `.env.production.local` 固化为 `/api`,与 nginx 反代规则和 vite dev 行为保持一致;改构建口径需同步改 `Dockerfile.web`。
|
||
- **postgres:latest 为 18.x**:数据目录挂载点已从 `/var/lib/postgresql/data` 改为 `/var/lib/postgresql`,挂错路径容器会反复重启。
|
||
- **配置与口令仅用于本地联调**:JWT secret、数据库/RabbitMQ 密码为占位值,勿带到生产。
|
||
- 数据库卷为命名卷(`sfile_sfile-pgdata-iw` / `-ow`);重新初始化需删卷后 `docker compose up -d`。
|
||
|
||
## 7. 验收清单
|
||
|
||
1. 两套登录页可访问(28180 / 28280),登录后内网侧菜单为「我的接收 / 我的发送」、外网侧相反;
|
||
2. 上传文件后「安全检测」列出现「检测中」→ 数秒内变「检测通过/不通过」(`docker exec sfile-iw-pg psql -U sfile -d s_file -c 'select * from x_file_security order by id desc limit 5;'`);
|
||
3. 检测不通过的文件分享/跨网传输被拒;文件夹部分不通过时确认后可只传通过项;
|
||
4. 内网发送到外网接收全链路走通,接收端解包后自动送检;
|
||
5. 管理端人工复核改判后文件恢复可分享/可传输。
|