feat: 完善部署脚本

This commit is contained in:
ah--desktop
2026-07-08 23:44:05 +08:00
parent 8af2e9194b
commit 8aee7f407d
16 changed files with 325 additions and 109 deletions
+35 -7
View File
@@ -29,17 +29,17 @@ function defaultConfig(): DeployConfig {
frontend: {
test: defaultServiceConfig('192.168.1.100', 80, '/var/www/ecom-frontend'),
pre: defaultServiceConfig('192.168.1.101', 80, '/var/www/ecom-frontend'),
production: defaultServiceConfig('frontend.prod.com', 80, '/var/www/ecom-frontend'),
prod: defaultServiceConfig('frontend.prod.com', 80, '/var/www/ecom-frontend'),
},
backend: {
test: { ...defaultServiceConfig('192.168.1.100', 8080), springProfile: 'test', dbUrl: '', redisUrl: '' },
pre: { ...defaultServiceConfig('192.168.1.101', 8080), springProfile: 'pre', dbUrl: '', redisUrl: '' },
production: { ...defaultServiceConfig('backend.prod.com', 8080), springProfile: 'prod', dbUrl: '', redisUrl: '' },
test: { ...defaultServiceConfig('192.168.1.100', 8101), springProfile: 'test', dbUrl: '', redisUrl: '' },
pre: { ...defaultServiceConfig('192.168.1.101', 8102), springProfile: 'pre', dbUrl: '', redisUrl: '' },
prod: { ...defaultServiceConfig('backend.prod.com', 8103), springProfile: 'prod', dbUrl: '', redisUrl: '' },
},
license: {
test: { ...defaultServiceConfig('192.168.1.100', 3100), nodeEnv: 'test', licenseDbUrl: '' },
pre: { ...defaultServiceConfig('192.168.1.101', 3100), nodeEnv: 'pre', licenseDbUrl: '' },
production: { ...defaultServiceConfig('license.prod.com', 3100), nodeEnv: 'production', licenseDbUrl: '' },
prod: { ...defaultServiceConfig('license.prod.com', 3100), nodeEnv: 'prod', licenseDbUrl: '' },
},
},
};
@@ -90,12 +90,40 @@ export function getConfigPath(): string {
return CONFIG_PATH;
}
/** 部署环境 pre 对应 Spring profile staging */
/** 与 application-{profile}.yml 中 server.port 保持一致 */
export function resolveBackendPort(env: Environment): number {
switch (env) {
case 'test':
return 8101;
case 'pre':
return 8102;
case 'prod':
return 8103;
}
}
/** 部署环境 pre 对应 Spring profile pre(application-pre.yml) */
export function resolveSpringProfile(profile?: string): string {
if (profile === 'pre') return 'staging';
return profile || 'prod';
}
/** 部署环境后缀:test / pre / prod */
export function resolveEnvSuffix(env: Environment): string {
return env;
}
/** Docker 镜像、容器、Compose 服务/项目名(含环境后缀) */
export function getDockerResourceNames(service: Service, env: Environment) {
const suffix = resolveEnvSuffix(env);
const base = `ecom-${service}-${suffix}`;
return {
composeService: base,
containerName: base,
imageTag: `${base}:latest`,
composeProject: base,
};
}
/** 同一 host+username 的服务共享 SSH 密钥配置 */
export async function syncServerKeyAuth(
host: string,