mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 03:19:18 +08:00
feat: 调整部署脚本
This commit is contained in:
@@ -4,7 +4,7 @@ import { join } from 'path';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
import { syncBackendArtifact } from '../artifacts.js';
|
||||
import { getArtifactDir, getBackendDir, getRemoteDataDir } from '../config.js';
|
||||
import { getArtifactDir, getBackendDir, getRemoteAppDir } from '../config.js';
|
||||
import { findMainJar, resolveMavenCommand } from '../platform.js';
|
||||
import { ensureRemoteDir, uploadFile } from '../ssh.js';
|
||||
import { printInfo, printSuccess } from '../ui/render.js';
|
||||
@@ -32,10 +32,10 @@ export async function build(_cfg: ServiceEnvConfig): Promise<string> {
|
||||
}
|
||||
|
||||
/** 上传 artifacts/backend 到远程挂载目录 */
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, _env: Environment): Promise<void> {
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, env: Environment): Promise<void> {
|
||||
const artifactDir = getArtifactDir('backend');
|
||||
const remoteDataDir = getRemoteDataDir(cfg, 'backend');
|
||||
await ensureRemoteDir(conn, remoteDataDir);
|
||||
await uploadFile(conn, join(artifactDir, 'app.jar'), `${remoteDataDir}/app.jar`);
|
||||
printSuccess(`后端产物已上传到 ${remoteDataDir}`);
|
||||
const remoteAppDir = getRemoteAppDir(cfg, 'backend', env);
|
||||
await ensureRemoteDir(conn, remoteAppDir);
|
||||
await uploadFile(conn, join(artifactDir, 'app.jar'), `${remoteAppDir}/app.jar`);
|
||||
printSuccess(`后端产物已上传到 ${remoteAppDir}`);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { join } from 'path';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
import { syncFrontendArtifacts } from '../artifacts.js';
|
||||
import { getArtifactDir, getFrontendDir } from '../config.js';
|
||||
import { getArtifactDir, getFrontendDir, resolveFrontendDeployDir, resolveFrontendIndexDir } from '../config.js';
|
||||
import { createTarGz, getLocalTempPath } from '../platform.js';
|
||||
import { execRemote, uploadFile, ensureRemoteDir } from '../ssh.js';
|
||||
import { printInfo, printSuccess } from '../ui/render.js';
|
||||
@@ -28,34 +28,24 @@ export async function build(): Promise<string> {
|
||||
return artifactDir;
|
||||
}
|
||||
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, _env: Environment): Promise<void> {
|
||||
/**
|
||||
* 上传静态产物到 {deployPath}/ecom-dmb-{env}/index/
|
||||
* 例:/opt/ecom-dmb-test/index
|
||||
*/
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, env: Environment): Promise<void> {
|
||||
const buildDir = getArtifactDir('frontend');
|
||||
|
||||
if (cfg.extractDir) {
|
||||
await ensureRemoteDir(conn, cfg.extractDir);
|
||||
|
||||
const tmpTar = getLocalTempPath('ecom-frontend-build.tar.gz');
|
||||
createTarGz(buildDir, tmpTar);
|
||||
await uploadFile(conn, tmpTar, `${cfg.extractDir}/frontend.tar.gz`);
|
||||
|
||||
const { code, stderr } = await execRemote(
|
||||
conn,
|
||||
`cd "${cfg.extractDir}" && rm -rf frontend && mkdir frontend && tar -xzf frontend.tar.gz -C frontend && rm frontend.tar.gz`,
|
||||
);
|
||||
if (code !== 0) throw new Error(`解压失败: ${stderr}`);
|
||||
printSuccess(`前端文件已部署到 ${cfg.extractDir}/frontend`);
|
||||
return;
|
||||
}
|
||||
|
||||
const serviceDir = `${cfg.server.deployPath}/frontend`;
|
||||
await ensureRemoteDir(conn, serviceDir);
|
||||
const siteDir = resolveFrontendDeployDir(cfg, env);
|
||||
const indexDir = resolveFrontendIndexDir(cfg, env);
|
||||
await ensureRemoteDir(conn, siteDir);
|
||||
|
||||
const tmpTar = getLocalTempPath('ecom-frontend-build.tar.gz');
|
||||
createTarGz(buildDir, tmpTar);
|
||||
await uploadFile(conn, tmpTar, `${serviceDir}/build.tar.gz`);
|
||||
await uploadFile(conn, tmpTar, `${siteDir}/frontend.tar.gz`);
|
||||
|
||||
const { code, stderr } = await execRemote(conn, `cd "${serviceDir}" && tar -xzf build.tar.gz && rm build.tar.gz`);
|
||||
const { code, stderr } = await execRemote(
|
||||
conn,
|
||||
`cd "${siteDir}" && rm -rf index && mkdir index && tar -xzf frontend.tar.gz -C index && rm frontend.tar.gz`,
|
||||
);
|
||||
if (code !== 0) throw new Error(`解压失败: ${stderr}`);
|
||||
|
||||
printSuccess(`前端文件已部署到 ${serviceDir}`);
|
||||
printSuccess(`前端文件已部署到 ${indexDir}`);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
composeDown,
|
||||
} from '../docker.js';
|
||||
import { assertArtifactsExist, ensureArtifactsDirs } from '../artifacts.js';
|
||||
import { getArtifactDir, loadConfig, getServiceConfig, syncServerKeyAuth } from '../config.js';
|
||||
import { getArtifactDir, loadConfig, getServiceConfig, syncServerKeyAuth, isStaticDeploy } from '../config.js';
|
||||
import { printError, printInfo, printSuccess } from '../ui/render.js';
|
||||
import type { Environment, Service, ServiceEnvConfig } from '../types.js';
|
||||
|
||||
@@ -114,7 +114,7 @@ export async function deployArtifactsOnly(
|
||||
);
|
||||
|
||||
try {
|
||||
if (cfg.extractDir) {
|
||||
if (isStaticDeploy(cfg)) {
|
||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||
} else {
|
||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||
@@ -146,7 +146,7 @@ export async function buildAndDeployServices(
|
||||
);
|
||||
|
||||
try {
|
||||
if (cfg.extractDir) {
|
||||
if (isStaticDeploy(cfg)) {
|
||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||
} else {
|
||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { join } from 'path';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
import { syncLicenseArtifacts, uploadArtifactDirectory } from '../artifacts.js';
|
||||
import { getArtifactDir, getLicenseDir, getRemoteDataDir } from '../config.js';
|
||||
import { getArtifactDir, getLicenseDir, getRemoteAppDir } from '../config.js';
|
||||
import { copyBuildArtifacts, getLocalTempPath } from '../platform.js';
|
||||
import { ensureRemoteDir } from '../ssh.js';
|
||||
import { printInfo, printSuccess } from '../ui/render.js';
|
||||
@@ -47,10 +47,10 @@ export async function build(): Promise<string> {
|
||||
}
|
||||
|
||||
/** 上传 artifacts/license 到远程挂载目录 */
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, _env: Environment): Promise<void> {
|
||||
export async function deploy(conn: Client, cfg: ServiceEnvConfig, _buildDir: string, env: Environment): Promise<void> {
|
||||
const artifactDir = getArtifactDir('license');
|
||||
const remoteDataDir = getRemoteDataDir(cfg, 'license');
|
||||
await ensureRemoteDir(conn, remoteDataDir);
|
||||
await uploadArtifactDirectory(conn, artifactDir, remoteDataDir);
|
||||
printSuccess(`许可证产物已上传到 ${remoteDataDir}`);
|
||||
const remoteAppDir = getRemoteAppDir(cfg, 'license', env);
|
||||
await ensureRemoteDir(conn, remoteAppDir);
|
||||
await uploadArtifactDirectory(conn, artifactDir, remoteAppDir);
|
||||
printSuccess(`许可证产物已上传到 ${remoteAppDir}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user