mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 06:29:20 +08:00
feat(部署): 优化部署目录
This commit is contained in:
@@ -3,10 +3,15 @@ import { existsSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
import { syncBackendArtifact } from '../artifacts.js';
|
||||
import { getArtifactDir, getBackendDir, getRemoteAppDir } from '../config.js';
|
||||
import { syncBackendArtifact, uploadDirectoryMerge } from '../artifacts.js';
|
||||
import {
|
||||
getArtifactDir,
|
||||
getBackendDir,
|
||||
getRemoteAppDir,
|
||||
resolveSpringProfile,
|
||||
} from '../config.js';
|
||||
import { findMainJar, resolveMavenCommand } from '../platform.js';
|
||||
import { ensureRemoteDir, uploadFile } from '../ssh.js';
|
||||
import { ensureRemoteDir, execRemote, uploadFile } from '../ssh.js';
|
||||
import { printInfo, printSuccess } from '../ui/render.js';
|
||||
import type { Environment, Service, ServiceEnvConfig } from '../types.js';
|
||||
|
||||
@@ -31,11 +36,52 @@ export async function build(_cfg: ServiceEnvConfig): Promise<string> {
|
||||
return artifactDir;
|
||||
}
|
||||
|
||||
/** 上传 artifacts/backend 到远程挂载目录 */
|
||||
/** 远程尚无文件时初始化环境 yml(app 根目录)与 config/ 下的 license 相关文件 */
|
||||
async function seedRemoteConfigIfMissing(
|
||||
conn: Client,
|
||||
cfg: ServiceEnvConfig,
|
||||
remoteAppDir: string,
|
||||
): Promise<void> {
|
||||
const profile = resolveSpringProfile(cfg.springProfile);
|
||||
const backendDir = getBackendDir();
|
||||
const envYml = `application-${profile}.yml`;
|
||||
const seeds: { local: string; remote: string }[] = [
|
||||
{
|
||||
local: join(backendDir, 'src/main/resources', envYml),
|
||||
remote: `${remoteAppDir}/${envYml}`,
|
||||
},
|
||||
{
|
||||
local: join(backendDir, 'src/main/resources/config/channel-pdd.yml'),
|
||||
remote: `${remoteAppDir}/config/channel-pdd.yml`,
|
||||
},
|
||||
];
|
||||
|
||||
await ensureRemoteDir(conn, `${remoteAppDir}/config`);
|
||||
for (const { local, remote } of seeds) {
|
||||
if (!existsSync(local)) continue;
|
||||
const { code } = await execRemote(conn, `test -f "${remote}"`);
|
||||
if (code === 0) continue;
|
||||
await uploadFile(conn, local, remote);
|
||||
printInfo(`已初始化配置(仅首次): ${remote}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** 上传 artifacts/backend 到远程 app/(jar + static;config/uploads 保留宿主机数据) */
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, env: Environment): Promise<void> {
|
||||
const artifactDir = getArtifactDir('backend');
|
||||
const remoteAppDir = getRemoteAppDir(cfg, 'backend', env);
|
||||
|
||||
await ensureRemoteDir(conn, remoteAppDir);
|
||||
await ensureRemoteDir(conn, `${remoteAppDir}/uploads`);
|
||||
await seedRemoteConfigIfMissing(conn, cfg, remoteAppDir);
|
||||
|
||||
await uploadFile(conn, join(artifactDir, 'app.jar'), `${remoteAppDir}/app.jar`);
|
||||
|
||||
const localStatic = join(artifactDir, 'static');
|
||||
if (existsSync(localStatic)) {
|
||||
printInfo('同步 static/ 到远程(合并,不删除 uploads/ 与宿主机配置)...');
|
||||
await uploadDirectoryMerge(conn, localStatic, `${remoteAppDir}/static`);
|
||||
}
|
||||
|
||||
printSuccess(`后端产物已上传到 ${remoteAppDir}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user