feat: 调整部署脚本

This commit is contained in:
2026-07-28 17:05:22 +08:00
parent 1edf3d560c
commit fe45e31165
14 changed files with 255 additions and 118 deletions
+60 -13
View File
@@ -14,12 +14,14 @@ export function getSshKeyPath(): string {
return SSH_KEY_PATH;
}
function defaultServiceConfig(host: string, port: number, extractDir?: string): ServiceEnvConfig {
const deployPath = extractDir || '/opt/ecom-dmb';
/** 远程统一根目录名:{deployPath}/ecom-dmb/{service}/{env} */
export const REMOTE_APP_ROOT = 'ecom-dmb';
function defaultServiceConfig(host: string, port: number, options?: { staticDeploy?: boolean }): ServiceEnvConfig {
return {
server: { host, port: 22, username: 'root', deployPath, authType: 'password' },
server: { host, port: 22, username: 'root', deployPath: '/opt', authType: 'password' },
port,
...(extractDir ? { extractDir } : {}),
...(options?.staticDeploy ? { staticDeploy: true } : {}),
};
}
@@ -28,9 +30,9 @@ function defaultConfig(): DeployConfig {
currentEnv: 'test',
services: {
frontend: {
test: defaultServiceConfig('192.168.1.100', 80, '/var/www/ecom-frontend'),
pre: defaultServiceConfig('192.168.1.101', 80, '/var/www/ecom-frontend'),
prod: defaultServiceConfig('frontend.prod.com', 80, '/var/www/ecom-frontend'),
test: defaultServiceConfig('192.168.1.100', 80, { staticDeploy: true }),
pre: defaultServiceConfig('192.168.1.101', 80, { staticDeploy: true }),
prod: defaultServiceConfig('frontend.prod.com', 80, { staticDeploy: true }),
},
backend: {
test: { ...defaultServiceConfig('192.168.1.100', 8101), springProfile: 'test', dbUrl: '', redisUrl: '' },
@@ -100,14 +102,59 @@ export function getArtifactDir(service: Service): string {
return join(ARTIFACTS_ROOT, service);
}
/** 远程服务目录(含 Dockerfile、data 挂载点) */
export function getRemoteServiceDir(cfg: ServiceEnvConfig, service: Service): string {
return `${cfg.server.deployPath}/${service}`;
/** 规范化部署根目录(去掉末尾斜杠) */
export function normalizeDeployRoot(deployPath: string): string {
return deployPath.replace(/\/+$/, '') || '/';
}
/** 远程挂载目录,容器内映射为 /data */
export function getRemoteDataDir(cfg: ServiceEnvConfig, service: Service): string {
return `${getRemoteServiceDir(cfg, service)}/data`;
/**
* 远程环境部署目录(后端 / 授权):
* {deployPath}/ecom-dmb/{service}/{env}
* 例:/opt/ecom-dmb/backend/test
*/
export function resolveEnvDeployDir(cfg: ServiceEnvConfig, service: Service, env: Environment): string {
return `${normalizeDeployRoot(cfg.server.deployPath)}/${REMOTE_APP_ROOT}/${service}/${env}`;
}
/**
* 前端静态部署目录(按环境后缀区分,不走 service 子路径):
* {deployPath}/ecom-dmb-{env}/index
* 例:/opt/ecom-dmb-test/index
*/
export function resolveFrontendDeployDir(cfg: ServiceEnvConfig, env: Environment): string {
return `${normalizeDeployRoot(cfg.server.deployPath)}/${REMOTE_APP_ROOT}-${env}`;
}
export function resolveFrontendIndexDir(cfg: ServiceEnvConfig, env: Environment): string {
return `${resolveFrontendDeployDir(cfg, env)}/index`;
}
/** 展示用:解析服务实际部署路径 */
export function resolveServiceDeployPath(cfg: ServiceEnvConfig, service: Service, env: Environment): string {
if (service === 'frontend') {
return resolveFrontendIndexDir(cfg, env);
}
return resolveEnvDeployDir(cfg, service, env);
}
/** 远程服务目录(含 Dockerfile、compose、data),等价于环境部署目录 */
export function getRemoteServiceDir(cfg: ServiceEnvConfig, service: Service, env: Environment): string {
return resolveEnvDeployDir(cfg, service, env);
}
/** 远程业务产物目录(宿主 app/,挂载到容器 /app) */
export function getRemoteAppDir(cfg: ServiceEnvConfig, service: Service, env: Environment): string {
return `${resolveEnvDeployDir(cfg, service, env)}/app`;
}
/** @deprecated 使用 getRemoteAppDir */
export function getRemoteDataDir(cfg: ServiceEnvConfig, service: Service, env: Environment): string {
return getRemoteAppDir(cfg, service, env);
}
/** 是否仅静态部署(不走 Docker),兼容旧字段 extractDir */
export function isStaticDeploy(cfg: ServiceEnvConfig): boolean {
return cfg.staticDeploy === true || Boolean(cfg.extractDir);
}
/** 与 application-{profile}.yml 中 server.port 保持一致 */