oms/tools/config/deploy.config.example.cjs
liufumingren 406e5f3b58 refactor(tools): 发布工具统一到 tools(前后端同时发布 + git 约束 + 共享配置)
- 新增 tools TypeScript 发布 CLI:deploy / deploy:backend / deploy:frontend / rollback / init
- 删除 backend/script 与 frontend/scripts 旧发布脚本,前后端 npm scripts 转发到 tools
- 发布配置独立为 tools/config/deploy.config.local.cjs(模板入库,真实配置与生产 env 不入库)
- 发布受限于 git:工作区有未提交改动默认中止(--allow-dirty 放行),版本记录含 commit/branch
- 后端配置集中到 <deployRoot>/shared-config,本地 env 发布时覆盖共享配置;端口由 EGG_PORT 注入
- 前端服务器端脚本迁至 tools/remote,失败时清理未上线版本目录
- .gitignore 改为忽略 tools 本地配置与临时发布包

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-30 23:04:54 +08:00

115 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* OMS 发布配置模板(此文件提交 git,供复制使用)
*
* 使用方式:
* cd tools && npm run init # 生成 deploy.config.local.cjs
* 然后填写 SSH / 目录等真实信息
* deploy.config.local.cjs 已被 .gitignore 排除,**不要提交**(内含服务器地址与私钥路径)。
*
* 发布模型(一次发布同时更新前后端):
* 后端:<deployRoot>/{v1,v2} 双实例蓝绿 + current.md + nginx-upstream.conf
* 前端:<basePath>/releases/<版本>/ 目录 + current 软链接原子切换
*
* <deployRoot>/shared-config/ 服务端共享配置(不入库):可放 config.*.js 与 .env;
* 每次发布复制到版本目录,覆盖包内同名文件
* <deployRoot>/.deploy/ 发布工作目录:incoming 上传包、backups 备份、state 版本记录
*
* Nginx 前置(仅首次,站点 api.oms.gztbyc.com):
* 把反向代理 `location /` 里的 `proxy_pass http://127.0.0.1:6090;` 换成
* `include /www/wwwroot/api.oms.gztbyc.com/nginx-upstream.conf;`
*/
module.exports = {
production: {
// ==================== SSH ====================
host: '__FILL_SSH_HOST__',
port: 22,
username: '__FILL_SSH_USERNAME__',
// 私钥:绝对路径、~/ 开头,或相对仓库根目录的路径
privateKeyPath: '__FILL_PRIVATE_KEY_PATH__',
sshOptions: [ 'StrictHostKeyChecking=accept-new' ],
// ==================== 发布约束(受限于 git)====================
// 工作区有未提交改动时禁止发布(可用 npm run deploy -- --allow-dirty 临时放行)
allowDirtyGit: false,
// 远端保留的版本记录条数 / 备份包个数
keepVersions: 30,
keepBackups: 5,
// ==================== 后端(Egg 双实例蓝绿)====================
backend: {
deployRoot: '/www/wwwroot/api.oms.gztbyc.com',
// 双实例端口;nginx-upstream.conf 指向当前活跃版本的端口
ports: { v1: 6090, v2: 6091 },
// 新实例启动后轮询 http://127.0.0.1:<端口><healthCheckPath>
healthCheckPath: '/',
healthCheckAttempts: 10,
healthCheckInterval: 2,
// 清理旧代码时保留的目录(位于版本目录内)
// 注意:.env 不保留,每次发布都从 shared-config 重新覆盖
sharedDirs: [ 'logs', 'run', 'node_modules' ],
// 发布包内容(相对 backend 根目录,`**` 表示该目录下全部内容)
deployIncludePaths: [
'.sequelizerc',
'app.js',
'app/**',
'config/**',
'database/**',
'package.json',
'package-lock.json',
],
deployExcludePaths: [
'.env',
'.env.*',
'uploads/**',
'logs/**',
'run/**',
'temp/**',
'test/**',
'swagger.json',
],
// 远端安装 / 启动命令;实例端口由发布脚本强制注入 EGG_PORT,无需写进 .env
installCommand: 'npm install --production',
startCommand: 'npm start',
// 启动前是否执行数据库迁移(npm run migration:up,需要 installCommand 安装 devDependencies)
runMigrations: false,
startTitlePrefix: 'oms',
// ===== 服务端共享配置(后端的配置共享出来)=====
// 不写该字段则默认 <deployRoot>/shared-config;设为 '' 表示不启用共享配置
// 共享目录内可放 config.*.js 与 envFile,发布时复制到版本目录并覆盖包内同名文件
envFile: '.env',
// 本机权威副本(相对仓库根目录,已 gitignore);存在时发布前上传,覆盖服务端共享 env
envFileLocalPath: 'tools/config/env.production.local',
uploadEnvFile: true,
// ===== Nginx =====
// 不写 nginxUpstreamFile 则默认 <deployRoot>/nginx-upstream.conf;设为 '' 表示不管理 upstream
// 切换 upstream 后执行的重载命令;设为 '' 则只写文件不重载
nginxReloadCommand: 'nginx -t && nginx -s reload',
},
// ==================== 前端(releases + current 软链)====================
frontend: {
// false 表示本次发布不动前端
enabled: true,
// 站点根目录,releases/ 与 current 都在其下
basePath: '/www/wwwroot/oms.gztbyc.com',
// 本机构建产物的目录(相对仓库根目录)
distDir: 'frontend/dist',
// 发布前本地构建命令(在 frontend/ 下执行)
buildCommand: 'npm run build',
// 服务器保留的最近版本数
keepReleases: 5,
// 发版后健康检查用的域名(本机 curl 带 Host 头访问 https://127.0.0.1/,仅提示)
siteHost: 'oms.gztbyc.com',
},
},
};