Files
a-share-analysis/docs/deployment/docker-compose-production.md
T

1.9 KiB

Docker Compose 生产部署

生产 Compose 部署使用两个不可变镜像:Web 静态 Nginx 镜像,以及同时包含 API、Scheduler、Worker 三个入口的 Server 镜像。MySQL 5.7.42、Redis 与 RocketMQ 5.x 由运维独立管理,不进入应用 Compose 生命周期;其他 MySQL 5.7 补丁版本也不得替代发布验收。

构建与配置

构建期只能给 Web 注入公开变量,生产秘密不得使用 ARG、写入镜像或提交仓库:

docker build -f web/Dockerfile -t registry.example/a-share-web:<提交SHA> .
docker build -f server/Dockerfile -t registry.example/a-share-server:<提交SHA> .

把四份生产模板复制到服务器的 /etc/a-share-analysis/,由运维填写并设置最小权限。Web 配置在镜像构建期固化,因此 web.env 只作为发布参数记录,不挂载到容器;API、Scheduler、Worker 分别读取自己的外部 env 文件。所有镜像引用必须使用明确版本或内容摘要,禁止 latest。

发布与验证

export A_SHARE_WEB_IMAGE='registry.example/a-share-web@sha256:<摘要>'
export A_SHARE_SERVER_IMAGE='registry.example/a-share-server@sha256:<摘要>'
docker compose -f deploy/compose/production.yml.example config
docker compose -f deploy/compose/production.yml.example up -d
docker compose -f deploy/compose/production.yml.example ps
curl --fail http://127.0.0.1:3000/api/v1/health
curl --fail http://127.0.0.1:8080/

当前工程尚无业务表迁移;出现 TypeORM migration 后,发布必须在启动应用前用同一 Server 镜像执行迁移,且始终禁止 synchronize: true。RocketMQ Node 客户端在后续功能验证前保持关闭。

回退

保留上一组 Web/Server 内容摘要。失败时把两个镜像变量恢复到上一组,重新执行 config、up -d 和健康检查。外部 env、Redis、MySQL 数据与 RocketMQ CommitLog 不随应用镜像回退;禁止用删除数据目录的方式回退应用。