refacotr: 重构部署实现,不每次都重新构建镜像,只在第一次构建,后面只将编译产物放入挂载目录重启容器

This commit is contained in:
ah--desktop
2026-07-12 17:13:45 +08:00
parent 7a2498cef2
commit b9a75af67c
13 changed files with 523 additions and 130 deletions
+34 -7
View File
@@ -4,12 +4,15 @@ import { input, password as pwPrompt, select } from '@inquirer/prompts';
import { loadConfig, saveConfig, updateServiceServerConfig, getServiceConfig, getSshKeyPath, syncServerKeyAuth } from './config.js';
import {
buildAndDeployServices,
buildServicesOnly,
deployArtifactsOnly,
checkRemoteDocker,
restartService,
serviceLogs,
serviceStatus,
stopService,
} from './deploy/index.js';
import { getArtifactsRoot } from './config.js';
import { ensureKeyPair, setupSSHKey, testConnection } from './ssh.js';
import { printBanner, printBox, printError, printInfo, printSuccess } from './ui/render.js';
import { ENV_LABELS, SERVICE_LABELS } from './types.js';
@@ -147,23 +150,47 @@ async function deployMenu() {
const env = config.currentEnv;
printBox('当前环境', `${ENV_LABELS[env]}\n${showServiceHosts(config)}`, 'yellow');
const deployMode = await select({
message: '部署方式',
choices: [
{ name: '自动部署(编译 + 上传 + 重启)', value: 'auto' },
{ name: '仅编译产物(不上传,输出到 artifacts/)', value: 'buildOnly' },
{ name: '上传产物并重启(从 artifacts/,不编译)', value: 'uploadOnly' },
{ name: '取消', value: 'cancel' },
],
});
if (deployMode === 'cancel') return;
const services = await selectServices();
printBox('待部署服务', services.map((s) => `${SERVICE_LABELS[s]} → ${config.services[s][env].server.host}`).join('\n'), 'cyan');
if (deployMode === 'buildOnly') {
printInfo(`产物目录: ${getArtifactsRoot()}`);
}
const ok = await select({
message: '确认部署?',
choices: [{ name: '开始部署', value: 'go' }, { name: '取消', value: 'cancel' }],
message: '确认执行?',
choices: [{ name: '开始', value: 'go' }, { name: '取消', value: 'cancel' }],
});
if (ok === 'cancel') return;
const onPassword = async (s: Service) => {
const cfg = config.services[s][env];
return await pwPrompt({ message: `输入 ${cfg.server.host} 的 SSH 密码`, mask: true });
};
try {
console.clear();
await buildAndDeployServices(services, async (s) => {
const cfg = config.services[s][env];
return await pwPrompt({ message: `输入 ${cfg.server.host} 的 SSH 密码`, mask: true });
});
if (deployMode === 'auto') {
await buildAndDeployServices(services, onPassword);
} else if (deployMode === 'buildOnly') {
await buildServicesOnly(services);
printSuccess(`编译完成,产物位于 ${getArtifactsRoot()}`);
} else {
await deployArtifactsOnly(services, onPassword);
}
} catch (e: any) {
printError(`部署失败: ${e.message}`);
printError(`操作失败: ${e.message}`);
}
}