mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:09:19 +08:00
feat: 调整部署脚本
This commit is contained in:
@@ -2,8 +2,37 @@
|
|||||||
|
|
||||||
部署采用 **运行时镜像 + 目录挂载** 模式:
|
部署采用 **运行时镜像 + 目录挂载** 模式:
|
||||||
|
|
||||||
- **首次部署**:在服务器构建一次运行时镜像(仅 JRE/Node 环境,不含业务代码),启动容器并挂载 `data/` 目录。
|
- **首次部署**:在服务器构建一次运行时镜像(仅 JRE/Node 环境,不含业务代码),启动容器并挂载 `app/` 目录。
|
||||||
- **后续更新**:只需上传编译产物到 `data/`,然后 **重启容器**,无需重新 `docker build`。
|
- **后续更新**:只需上传编译产物到 `app/`,然后 **重启容器**,无需重新 `docker build`。
|
||||||
|
|
||||||
|
## 远程目录结构
|
||||||
|
|
||||||
|
`deployPath` 为部署根目录。
|
||||||
|
|
||||||
|
**后端 / 授权(Docker)**:
|
||||||
|
|
||||||
|
```
|
||||||
|
{deployPath}/ecom-dmb/{service}/{env}/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── Dockerfile
|
||||||
|
└── app/
|
||||||
|
```
|
||||||
|
|
||||||
|
**前端(静态,用目录名区分环境)**:
|
||||||
|
|
||||||
|
```
|
||||||
|
{deployPath}/ecom-dmb-{env}/index/
|
||||||
|
```
|
||||||
|
|
||||||
|
示例(根目录 `/opt`,test):
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/ecom-dmb/backend/test/app/app.jar
|
||||||
|
/opt/ecom-dmb-test/index/ # 前端站点根
|
||||||
|
/opt/ecom-dmb/license/test/app/
|
||||||
|
```
|
||||||
|
|
||||||
|
Docker 资源名同样带环境后缀:`ecom-backend-test` / `ecom-backend-prod` 等。
|
||||||
|
|
||||||
本地编译产物统一放在 `ecom-deploy/artifacts/`(已 gitignore):
|
本地编译产物统一放在 `ecom-deploy/artifacts/`(已 gitignore):
|
||||||
|
|
||||||
@@ -65,35 +94,36 @@ pnpm install --prod --frozen-lockfile
|
|||||||
|
|
||||||
### 2. 上传到服务器
|
### 2. 上传到服务器
|
||||||
|
|
||||||
**后端**(以 test 环境为例,部署路径 `/opt/ecom-backend`):
|
**后端**(根目录 `/opt`,test 环境):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scp artifacts/backend/app.jar root@192.168.3.101:/opt/ecom-backend/backend/data/app.jar
|
scp artifacts/backend/app.jar user@192.168.3.101:/opt/ecom-dmb/backend/test/app/app.jar
|
||||||
```
|
```
|
||||||
|
|
||||||
**许可证**:
|
**许可证**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 打包上传
|
|
||||||
tar -czf license.tar.gz -C artifacts/license .
|
tar -czf license.tar.gz -C artifacts/license .
|
||||||
scp license.tar.gz root@host:/opt/ecom-license/license/
|
scp license.tar.gz user@host:/opt/ecom-dmb/license/test/
|
||||||
ssh root@host 'cd /opt/ecom-license/license && rm -rf data/* && mkdir -p data && tar -xzf upload.tar.gz -C data'
|
ssh user@host 'cd /opt/ecom-dmb/license/test && rm -rf app/* && mkdir -p app && tar -xzf license.tar.gz -C app && rm license.tar.gz'
|
||||||
```
|
```
|
||||||
|
|
||||||
**前端**(静态目录部署):
|
**前端**(静态目录,按环境后缀区分):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tar -czf frontend.tar.gz -C artifacts/frontend .
|
tar -czf frontend.tar.gz -C artifacts/frontend .
|
||||||
scp frontend.tar.gz root@host:/var/www/ecom-frontend/
|
scp frontend.tar.gz user@host:/opt/ecom-dmb-test/
|
||||||
# 在服务器解压到 frontend 子目录
|
ssh user@host 'cd /opt/ecom-dmb-test && rm -rf index && mkdir index && tar -xzf frontend.tar.gz -C index && rm frontend.tar.gz'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Nginx 站点根目录一般为 `/opt/ecom-dmb-{env}/index`(如 test → `/opt/ecom-dmb-test/index`)。
|
||||||
|
|
||||||
### 3. 重启容器
|
### 3. 重启容器
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 后端 test 环境
|
# 后端 test 环境
|
||||||
ssh root@192.168.3.101
|
ssh user@192.168.3.101
|
||||||
cd /opt/ecom-backend
|
cd /opt/ecom-dmb/backend/test
|
||||||
docker compose -p ecom-backend-test restart ecom-backend-test
|
docker compose -p ecom-backend-test restart ecom-backend-test
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -115,16 +145,15 @@ docker compose -p ecom-backend-test restart ecom-backend-test
|
|||||||
|
|
||||||
使用 TUI **自动部署** 或 **上传产物并重启** 即可自动完成:
|
使用 TUI **自动部署** 或 **上传产物并重启** 即可自动完成:
|
||||||
|
|
||||||
1. 上传产物到 `{deployPath}/{service}/data/`
|
1. 上传产物到 `{deployPath}/ecom-dmb/{service}/{env}/app/`
|
||||||
2. 构建运行时 Dockerfile 镜像
|
2. 构建运行时 Dockerfile 镜像
|
||||||
3. 生成 docker-compose.yml 并启动容器
|
3. 在同目录生成 docker-compose.yml 并启动容器
|
||||||
|
|
||||||
若需手动初始化后端运行时镜像:
|
若需手动初始化后端运行时镜像:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /opt/ecom-backend/backend
|
cd /opt/ecom-dmb/backend/test
|
||||||
docker build -t ecom-backend-test:latest .
|
docker build -t ecom-backend-test:latest .
|
||||||
cd /opt/ecom-backend
|
|
||||||
docker compose -p ecom-backend-test up -d ecom-backend-test
|
docker compose -p ecom-backend-test up -d ecom-backend-test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -3,38 +3,78 @@
|
|||||||
"services": {
|
"services": {
|
||||||
"frontend": {
|
"frontend": {
|
||||||
"test": {
|
"test": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.101",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt/1panel/www/sites",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"extractDir": "/var/www/ecom-frontend"
|
"staticDeploy": true
|
||||||
},
|
},
|
||||||
"pre": {
|
"pre": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.101",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt/1panel/www/sites",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"extractDir": "/var/www/ecom-frontend"
|
"staticDeploy": true
|
||||||
},
|
},
|
||||||
"prod": {
|
"prod": {
|
||||||
"server": { "host": "frontend.prod.com", "port": 22, "username": "root", "deployPath": "/var/www/ecom-frontend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "frontend.prod.com",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt/1panel/www/sites",
|
||||||
|
"authType": "password"
|
||||||
|
},
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"extractDir": "/var/www/ecom-frontend"
|
"staticDeploy": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"backend": {
|
"backend": {
|
||||||
"test": {
|
"test": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.101",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 8101,
|
"port": 8101,
|
||||||
"springProfile": "test",
|
"springProfile": "test",
|
||||||
"dbUrl": "",
|
"dbUrl": "",
|
||||||
"redisUrl": ""
|
"redisUrl": ""
|
||||||
},
|
},
|
||||||
"pre": {
|
"pre": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.101",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 8102,
|
"port": 8102,
|
||||||
"springProfile": "pre",
|
"springProfile": "pre",
|
||||||
"dbUrl": "",
|
"dbUrl": "",
|
||||||
"redisUrl": ""
|
"redisUrl": ""
|
||||||
},
|
},
|
||||||
"prod": {
|
"prod": {
|
||||||
"server": { "host": "backend.prod.com", "port": 22, "username": "root", "deployPath": "/opt/ecom-backend", "authType": "password" },
|
"server": {
|
||||||
|
"host": "backend.prod.com",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "password"
|
||||||
|
},
|
||||||
"port": 8103,
|
"port": 8103,
|
||||||
"springProfile": "prod",
|
"springProfile": "prod",
|
||||||
"dbUrl": "",
|
"dbUrl": "",
|
||||||
@@ -43,23 +83,43 @@
|
|||||||
},
|
},
|
||||||
"license": {
|
"license": {
|
||||||
"test": {
|
"test": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.100",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 3100,
|
"port": 3100,
|
||||||
"nodeEnv": "test",
|
"nodeEnv": "test",
|
||||||
"licenseDbUrl": ""
|
"licenseDbUrl": ""
|
||||||
},
|
},
|
||||||
"pre": {
|
"pre": {
|
||||||
"server": { "host": "192.168.3.100", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" },
|
"server": {
|
||||||
|
"host": "192.168.3.100",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "key",
|
||||||
|
"keyPath": "/home/qinghua/.ssh/ecom-deploy"
|
||||||
|
},
|
||||||
"port": 3100,
|
"port": 3100,
|
||||||
"nodeEnv": "pre",
|
"nodeEnv": "pre",
|
||||||
"licenseDbUrl": ""
|
"licenseDbUrl": ""
|
||||||
},
|
},
|
||||||
"prod": {
|
"prod": {
|
||||||
"server": { "host": "license.prod.com", "port": 22, "username": "root", "deployPath": "/opt/ecom-license", "authType": "password" },
|
"server": {
|
||||||
|
"host": "license.prod.com",
|
||||||
|
"port": 22,
|
||||||
|
"username": "root",
|
||||||
|
"deployPath": "/opt",
|
||||||
|
"authType": "password"
|
||||||
|
},
|
||||||
"port": 3100,
|
"port": 3100,
|
||||||
"nodeEnv": "prod",
|
"nodeEnv": "prod",
|
||||||
"licenseDbUrl": ""
|
"licenseDbUrl": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,24 +66,24 @@ export function assertArtifactsExist(service: Service): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 打包并上传目录到远程 data 目录 */
|
/** 打包并上传目录到远程 app 目录 */
|
||||||
export async function uploadArtifactDirectory(
|
export async function uploadArtifactDirectory(
|
||||||
conn: Client,
|
conn: Client,
|
||||||
localDir: string,
|
localDir: string,
|
||||||
remoteDataDir: string,
|
remoteAppDir: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await ensureRemoteDir(conn, remoteDataDir);
|
await ensureRemoteDir(conn, remoteAppDir);
|
||||||
const parentDir = remoteDataDir.replace(/\/data\/?$/, '');
|
const parentDir = remoteAppDir.replace(/\/app\/?$/, '');
|
||||||
const tmpTar = getLocalTempPath(`ecom-upload-${Date.now()}.tar.gz`);
|
const tmpTar = getLocalTempPath(`ecom-upload-${Date.now()}.tar.gz`);
|
||||||
const remoteTar = `${parentDir}/upload.tar.gz`;
|
const remoteTar = `${parentDir}/upload.tar.gz`;
|
||||||
|
|
||||||
printInfo(`上传产物到 ${remoteDataDir} ...`);
|
printInfo(`上传产物到 ${remoteAppDir} ...`);
|
||||||
createTarGz(localDir, tmpTar);
|
createTarGz(localDir, tmpTar);
|
||||||
await uploadFile(conn, tmpTar, remoteTar);
|
await uploadFile(conn, tmpTar, remoteTar);
|
||||||
|
|
||||||
const { code, stderr } = await execRemote(
|
const { code, stderr } = await execRemote(
|
||||||
conn,
|
conn,
|
||||||
`mkdir -p "${remoteDataDir}" && rm -rf "${remoteDataDir}"/* && tar -xzf "${remoteTar}" -C "${remoteDataDir}" && rm -f "${remoteTar}"`,
|
`mkdir -p "${remoteAppDir}" && rm -rf "${remoteAppDir}"/* && tar -xzf "${remoteTar}" -C "${remoteAppDir}" && rm -f "${remoteTar}"`,
|
||||||
);
|
);
|
||||||
if (code !== 0) throw new Error(`远程解压失败: ${stderr}`);
|
if (code !== 0) throw new Error(`远程解压失败: ${stderr}`);
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-13
@@ -14,12 +14,14 @@ export function getSshKeyPath(): string {
|
|||||||
return SSH_KEY_PATH;
|
return SSH_KEY_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultServiceConfig(host: string, port: number, extractDir?: string): ServiceEnvConfig {
|
/** 远程统一根目录名:{deployPath}/ecom-dmb/{service}/{env} */
|
||||||
const deployPath = extractDir || '/opt/ecom-dmb';
|
export const REMOTE_APP_ROOT = 'ecom-dmb';
|
||||||
|
|
||||||
|
function defaultServiceConfig(host: string, port: number, options?: { staticDeploy?: boolean }): ServiceEnvConfig {
|
||||||
return {
|
return {
|
||||||
server: { host, port: 22, username: 'root', deployPath, authType: 'password' },
|
server: { host, port: 22, username: 'root', deployPath: '/opt', authType: 'password' },
|
||||||
port,
|
port,
|
||||||
...(extractDir ? { extractDir } : {}),
|
...(options?.staticDeploy ? { staticDeploy: true } : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,9 +30,9 @@ function defaultConfig(): DeployConfig {
|
|||||||
currentEnv: 'test',
|
currentEnv: 'test',
|
||||||
services: {
|
services: {
|
||||||
frontend: {
|
frontend: {
|
||||||
test: defaultServiceConfig('192.168.1.100', 80, '/var/www/ecom-frontend'),
|
test: defaultServiceConfig('192.168.1.100', 80, { staticDeploy: true }),
|
||||||
pre: defaultServiceConfig('192.168.1.101', 80, '/var/www/ecom-frontend'),
|
pre: defaultServiceConfig('192.168.1.101', 80, { staticDeploy: true }),
|
||||||
prod: defaultServiceConfig('frontend.prod.com', 80, '/var/www/ecom-frontend'),
|
prod: defaultServiceConfig('frontend.prod.com', 80, { staticDeploy: true }),
|
||||||
},
|
},
|
||||||
backend: {
|
backend: {
|
||||||
test: { ...defaultServiceConfig('192.168.1.100', 8101), springProfile: 'test', dbUrl: '', redisUrl: '' },
|
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);
|
return join(ARTIFACTS_ROOT, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 远程服务目录(含 Dockerfile、data 挂载点) */
|
/** 规范化部署根目录(去掉末尾斜杠) */
|
||||||
export function getRemoteServiceDir(cfg: ServiceEnvConfig, service: Service): string {
|
export function normalizeDeployRoot(deployPath: string): string {
|
||||||
return `${cfg.server.deployPath}/${service}`;
|
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 保持一致 */
|
/** 与 application-{profile}.yml 中 server.port 保持一致 */
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { join } from 'path';
|
|||||||
|
|
||||||
import { Client } from 'ssh2';
|
import { Client } from 'ssh2';
|
||||||
import { syncBackendArtifact } from '../artifacts.js';
|
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 { findMainJar, resolveMavenCommand } from '../platform.js';
|
||||||
import { ensureRemoteDir, uploadFile } from '../ssh.js';
|
import { ensureRemoteDir, uploadFile } from '../ssh.js';
|
||||||
import { printInfo, printSuccess } from '../ui/render.js';
|
import { printInfo, printSuccess } from '../ui/render.js';
|
||||||
@@ -32,10 +32,10 @@ export async function build(_cfg: ServiceEnvConfig): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 上传 artifacts/backend 到远程挂载目录 */
|
/** 上传 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 artifactDir = getArtifactDir('backend');
|
||||||
const remoteDataDir = getRemoteDataDir(cfg, 'backend');
|
const remoteAppDir = getRemoteAppDir(cfg, 'backend', env);
|
||||||
await ensureRemoteDir(conn, remoteDataDir);
|
await ensureRemoteDir(conn, remoteAppDir);
|
||||||
await uploadFile(conn, join(artifactDir, 'app.jar'), `${remoteDataDir}/app.jar`);
|
await uploadFile(conn, join(artifactDir, 'app.jar'), `${remoteAppDir}/app.jar`);
|
||||||
printSuccess(`后端产物已上传到 ${remoteDataDir}`);
|
printSuccess(`后端产物已上传到 ${remoteAppDir}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { join } from 'path';
|
|||||||
|
|
||||||
import { Client } from 'ssh2';
|
import { Client } from 'ssh2';
|
||||||
import { syncFrontendArtifacts } from '../artifacts.js';
|
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 { createTarGz, getLocalTempPath } from '../platform.js';
|
||||||
import { execRemote, uploadFile, ensureRemoteDir } from '../ssh.js';
|
import { execRemote, uploadFile, ensureRemoteDir } from '../ssh.js';
|
||||||
import { printInfo, printSuccess } from '../ui/render.js';
|
import { printInfo, printSuccess } from '../ui/render.js';
|
||||||
@@ -28,34 +28,24 @@ export async function build(): Promise<string> {
|
|||||||
return artifactDir;
|
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');
|
const buildDir = getArtifactDir('frontend');
|
||||||
|
const siteDir = resolveFrontendDeployDir(cfg, env);
|
||||||
if (cfg.extractDir) {
|
const indexDir = resolveFrontendIndexDir(cfg, env);
|
||||||
await ensureRemoteDir(conn, cfg.extractDir);
|
await ensureRemoteDir(conn, siteDir);
|
||||||
|
|
||||||
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 tmpTar = getLocalTempPath('ecom-frontend-build.tar.gz');
|
const tmpTar = getLocalTempPath('ecom-frontend-build.tar.gz');
|
||||||
createTarGz(buildDir, tmpTar);
|
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}`);
|
if (code !== 0) throw new Error(`解压失败: ${stderr}`);
|
||||||
|
printSuccess(`前端文件已部署到 ${indexDir}`);
|
||||||
printSuccess(`前端文件已部署到 ${serviceDir}`);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
composeDown,
|
composeDown,
|
||||||
} from '../docker.js';
|
} from '../docker.js';
|
||||||
import { assertArtifactsExist, ensureArtifactsDirs } from '../artifacts.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 { printError, printInfo, printSuccess } from '../ui/render.js';
|
||||||
import type { Environment, Service, ServiceEnvConfig } from '../types.js';
|
import type { Environment, Service, ServiceEnvConfig } from '../types.js';
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ export async function deployArtifactsOnly(
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cfg.extractDir) {
|
if (isStaticDeploy(cfg)) {
|
||||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||||
} else {
|
} else {
|
||||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||||
@@ -146,7 +146,7 @@ export async function buildAndDeployServices(
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cfg.extractDir) {
|
if (isStaticDeploy(cfg)) {
|
||||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||||
} else {
|
} else {
|
||||||
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
await deployService(conn, service, cfg, getArtifactDir(service), env);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { join } from 'path';
|
|||||||
|
|
||||||
import { Client } from 'ssh2';
|
import { Client } from 'ssh2';
|
||||||
import { syncLicenseArtifacts, uploadArtifactDirectory } from '../artifacts.js';
|
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 { copyBuildArtifacts, getLocalTempPath } from '../platform.js';
|
||||||
import { ensureRemoteDir } from '../ssh.js';
|
import { ensureRemoteDir } from '../ssh.js';
|
||||||
import { printInfo, printSuccess } from '../ui/render.js';
|
import { printInfo, printSuccess } from '../ui/render.js';
|
||||||
@@ -47,10 +47,10 @@ export async function build(): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 上传 artifacts/license 到远程挂载目录 */
|
/** 上传 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 artifactDir = getArtifactDir('license');
|
||||||
const remoteDataDir = getRemoteDataDir(cfg, 'license');
|
const remoteAppDir = getRemoteAppDir(cfg, 'license', env);
|
||||||
await ensureRemoteDir(conn, remoteDataDir);
|
await ensureRemoteDir(conn, remoteAppDir);
|
||||||
await uploadArtifactDirectory(conn, artifactDir, remoteDataDir);
|
await uploadArtifactDirectory(conn, artifactDir, remoteAppDir);
|
||||||
printSuccess(`许可证产物已上传到 ${remoteDataDir}`);
|
printSuccess(`许可证产物已上传到 ${remoteAppDir}`);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-15
@@ -8,6 +8,7 @@ import {
|
|||||||
getLicenseDeployDir,
|
getLicenseDeployDir,
|
||||||
getRemoteServiceDir,
|
getRemoteServiceDir,
|
||||||
resolveBackendPort,
|
resolveBackendPort,
|
||||||
|
resolveEnvDeployDir,
|
||||||
resolveSpringProfile,
|
resolveSpringProfile,
|
||||||
} from './config.js';
|
} from './config.js';
|
||||||
import { getLocalTempPath } from './platform.js';
|
import { getLocalTempPath } from './platform.js';
|
||||||
@@ -15,10 +16,11 @@ import { execRemote, ensureRemoteDir, uploadFile } from './ssh.js';
|
|||||||
import { printInfo, printSuccess } from './ui/render.js';
|
import { printInfo, printSuccess } from './ui/render.js';
|
||||||
import type { Environment, Service, ServiceEnvConfig } from './types.js';
|
import type { Environment, Service, ServiceEnvConfig } from './types.js';
|
||||||
|
|
||||||
/** 远程 compose 命令前缀 */
|
/** 远程 compose 命令前缀(工作目录为环境部署目录) */
|
||||||
function composeCmd(cfg: ServiceEnvConfig, env: Environment, service: Service): string {
|
function composeCmd(cfg: ServiceEnvConfig, env: Environment, service: Service): string {
|
||||||
const { composeProject } = getDockerResourceNames(service, env);
|
const { composeProject } = getDockerResourceNames(service, env);
|
||||||
return `cd "${cfg.server.deployPath}" && docker compose -p ${composeProject}`;
|
const envDir = resolveEnvDeployDir(cfg, service, env);
|
||||||
|
return `cd "${envDir}" && docker compose -p ${composeProject}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 桥接模式端口 */
|
/** 桥接模式端口 */
|
||||||
@@ -30,11 +32,6 @@ function resolveBridgePorts(service: Service, cfg: ServiceEnvConfig, env: Enviro
|
|||||||
return { hostPort: cfg.port, containerPort: cfg.port };
|
return { hostPort: cfg.port, containerPort: cfg.port };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 挂载目录(相对 deployPath) */
|
|
||||||
function getVolumeMapping(service: Service): string {
|
|
||||||
return `./${service}/data:/data:ro`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateComposeFile(service: Service, cfg: ServiceEnvConfig, env: Environment): string {
|
export function generateComposeFile(service: Service, cfg: ServiceEnvConfig, env: Environment): string {
|
||||||
const { composeService, containerName, imageTag } = getDockerResourceNames(service, env);
|
const { composeService, containerName, imageTag } = getDockerResourceNames(service, env);
|
||||||
const { hostPort, containerPort } = resolveBridgePorts(service, cfg, env);
|
const { hostPort, containerPort } = resolveBridgePorts(service, cfg, env);
|
||||||
@@ -64,7 +61,7 @@ export function generateComposeFile(service: Service, cfg: ServiceEnvConfig, env
|
|||||||
ports:
|
ports:
|
||||||
- "${hostPort}:${containerPort}"
|
- "${hostPort}:${containerPort}"
|
||||||
volumes:
|
volumes:
|
||||||
- ${getVolumeMapping(service)}
|
- ./app:/app:ro
|
||||||
environment:
|
environment:
|
||||||
${envBlock}
|
${envBlock}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -90,13 +87,14 @@ function readRuntimeDockerfile(service: Service): string {
|
|||||||
return readFileSync(dockerfileSrc, 'utf8');
|
return readFileSync(dockerfileSrc, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 上传运行时 Dockerfile 到远程服务目录 */
|
/** 上传运行时 Dockerfile 到远程环境目录 */
|
||||||
export async function uploadRuntimeDockerfile(
|
export async function uploadRuntimeDockerfile(
|
||||||
conn: Client,
|
conn: Client,
|
||||||
service: Service,
|
service: Service,
|
||||||
cfg: ServiceEnvConfig,
|
cfg: ServiceEnvConfig,
|
||||||
|
env: Environment,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const serviceDir = getRemoteServiceDir(cfg, service);
|
const serviceDir = getRemoteServiceDir(cfg, service, env);
|
||||||
await ensureRemoteDir(conn, serviceDir);
|
await ensureRemoteDir(conn, serviceDir);
|
||||||
const tmp = getLocalTempPath(`ecom-${service}-Dockerfile`);
|
const tmp = getLocalTempPath(`ecom-${service}-Dockerfile`);
|
||||||
writeFileSync(tmp, readRuntimeDockerfile(service), 'utf8');
|
writeFileSync(tmp, readRuntimeDockerfile(service), 'utf8');
|
||||||
@@ -118,7 +116,7 @@ export async function remoteBuildRuntimeImage(
|
|||||||
env: Environment,
|
env: Environment,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { imageTag } = getDockerResourceNames(service, env);
|
const { imageTag } = getDockerResourceNames(service, env);
|
||||||
const serviceDir = getRemoteServiceDir(cfg, service);
|
const serviceDir = getRemoteServiceDir(cfg, service, env);
|
||||||
const { code, stdout, stderr } = await execRemote(
|
const { code, stdout, stderr } = await execRemote(
|
||||||
conn,
|
conn,
|
||||||
`cd "${serviceDir}" && docker build -t ${imageTag} . 2>&1`,
|
`cd "${serviceDir}" && docker build -t ${imageTag} . 2>&1`,
|
||||||
@@ -135,11 +133,11 @@ export async function uploadComposeFile(
|
|||||||
cfg: ServiceEnvConfig,
|
cfg: ServiceEnvConfig,
|
||||||
env: Environment,
|
env: Environment,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const deployPath = cfg.server.deployPath;
|
const envDir = resolveEnvDeployDir(cfg, service, env);
|
||||||
const tmpCompose = getLocalTempPath(`ecom-${service}-${env}-docker-compose.yml`);
|
const tmpCompose = getLocalTempPath(`ecom-${service}-${env}-docker-compose.yml`);
|
||||||
writeFileSync(tmpCompose, generateComposeFile(service, cfg, env), 'utf8');
|
writeFileSync(tmpCompose, generateComposeFile(service, cfg, env), 'utf8');
|
||||||
await ensureRemoteDir(conn, deployPath);
|
await ensureRemoteDir(conn, envDir);
|
||||||
await uploadFile(conn, tmpCompose, `${deployPath}/docker-compose.yml`);
|
await uploadFile(conn, tmpCompose, `${envDir}/docker-compose.yml`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 首次启动容器 */
|
/** 首次启动容器 */
|
||||||
@@ -188,7 +186,7 @@ export async function initServiceRuntime(
|
|||||||
env: Environment,
|
env: Environment,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
printInfo(`${service} 首次部署,初始化运行时镜像...`);
|
printInfo(`${service} 首次部署,初始化运行时镜像...`);
|
||||||
await uploadRuntimeDockerfile(conn, service, cfg);
|
await uploadRuntimeDockerfile(conn, service, cfg, env);
|
||||||
await uploadComposeFile(conn, service, cfg, env);
|
await uploadComposeFile(conn, service, cfg, env);
|
||||||
await remoteBuildRuntimeImage(conn, service, cfg, env);
|
await remoteBuildRuntimeImage(conn, service, cfg, env);
|
||||||
await composeUp(conn, cfg, service, env);
|
await composeUp(conn, cfg, service, env);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import { input, password as pwPrompt, select } from '@inquirer/prompts';
|
import { input, password as pwPrompt, select } from '@inquirer/prompts';
|
||||||
|
|
||||||
import { loadConfig, saveConfig, updateServiceServerConfig, getServiceConfig, getSshKeyPath, syncServerKeyAuth } from './config.js';
|
import { loadConfig, saveConfig, updateServiceServerConfig, getServiceConfig, getSshKeyPath, syncServerKeyAuth, resolveServiceDeployPath } from './config.js';
|
||||||
import {
|
import {
|
||||||
buildAndDeployServices,
|
buildAndDeployServices,
|
||||||
buildServicesOnly,
|
buildServicesOnly,
|
||||||
@@ -61,12 +61,14 @@ async function selectServices(): Promise<Service[]> {
|
|||||||
return [selected as Service];
|
return [selected as Service];
|
||||||
}
|
}
|
||||||
|
|
||||||
function showServiceHosts(config: { services: Record<string, Record<string, { server: { host: string; deployPath: string } }>>; currentEnv: string }): string {
|
function showServiceHosts(config: Awaited<ReturnType<typeof loadConfig>>): string {
|
||||||
const env = config.currentEnv;
|
const env = config.currentEnv;
|
||||||
const services: Service[] = ['frontend', 'backend', 'license'];
|
const services: Service[] = ['frontend', 'backend', 'license'];
|
||||||
return services.map((s) =>
|
return services.map((s) => {
|
||||||
` ${SERVICE_LABELS[s]}: ${config.services[s][env].server.host}:${config.services[s][env].server.deployPath}`
|
const cfg = config.services[s][env];
|
||||||
).join('\n');
|
const resolved = resolveServiceDeployPath(cfg, s, env);
|
||||||
|
return ` ${SERVICE_LABELS[s]}: ${cfg.server.host} → ${resolved}`;
|
||||||
|
}).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function configureService() {
|
async function configureService() {
|
||||||
@@ -80,7 +82,8 @@ async function configureService() {
|
|||||||
printBox(`${SERVICE_LABELS[service]} · ${ENV_LABELS[env]} 配置`, [
|
printBox(`${SERVICE_LABELS[service]} · ${ENV_LABELS[env]} 配置`, [
|
||||||
`服务器: ${srv.host}:${srv.port}`,
|
`服务器: ${srv.host}:${srv.port}`,
|
||||||
`用户: ${srv.username}`,
|
`用户: ${srv.username}`,
|
||||||
`部署目录: ${srv.deployPath}`,
|
`部署根目录: ${srv.deployPath}`,
|
||||||
|
`实际目录: ${resolveServiceDeployPath(cfg, service, env)}`,
|
||||||
`端口: ${cfg.port}`,
|
`端口: ${cfg.port}`,
|
||||||
`认证方式: ${srv.authType === 'key' ? '密钥' : '密码'}`,
|
`认证方式: ${srv.authType === 'key' ? '密钥' : '密码'}`,
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
@@ -92,7 +95,7 @@ async function configureService() {
|
|||||||
{ name: '修改端口', value: 'port' },
|
{ name: '修改端口', value: 'port' },
|
||||||
{ name: '修改服务端口', value: 'svcPort' },
|
{ name: '修改服务端口', value: 'svcPort' },
|
||||||
{ name: '修改用户名', value: 'username' },
|
{ name: '修改用户名', value: 'username' },
|
||||||
{ name: '修改部署目录', value: 'deployPath' },
|
{ name: '修改部署根目录', value: 'deployPath' },
|
||||||
{ name: '测试 SSH 连接', value: 'test' },
|
{ name: '测试 SSH 连接', value: 'test' },
|
||||||
{ name: '配置 SSH 密钥 (首次免密)', value: 'setupKey' },
|
{ name: '配置 SSH 密钥 (首次免密)', value: 'setupKey' },
|
||||||
{ name: '返回', value: 'back' },
|
{ name: '返回', value: 'back' },
|
||||||
@@ -122,7 +125,13 @@ async function configureService() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'deployPath': {
|
case 'deployPath': {
|
||||||
const d = await input({ message: '部署目录', default: srv.deployPath });
|
const hint = service === 'frontend'
|
||||||
|
? `部署根目录(实际为 根目录/ecom-dmb-${env}/index)`
|
||||||
|
: `部署根目录(实际为 根目录/ecom-dmb/${service}/${env})`;
|
||||||
|
const d = await input({
|
||||||
|
message: hint,
|
||||||
|
default: srv.deployPath,
|
||||||
|
});
|
||||||
await updateServiceServerConfig(service, env, { deployPath: d });
|
await updateServiceServerConfig(service, env, { deployPath: d });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface ServerConfig {
|
|||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
username: string;
|
username: string;
|
||||||
|
/** 部署根目录;实际路径为 {deployPath}/ecom-dmb/{service}/{env} */
|
||||||
deployPath: string;
|
deployPath: string;
|
||||||
authType: 'password' | 'key';
|
authType: 'password' | 'key';
|
||||||
keyPath?: string;
|
keyPath?: string;
|
||||||
@@ -19,6 +20,9 @@ export interface ServiceEnvConfig {
|
|||||||
dbUrl?: string;
|
dbUrl?: string;
|
||||||
redisUrl?: string;
|
redisUrl?: string;
|
||||||
licenseDbUrl?: string;
|
licenseDbUrl?: string;
|
||||||
|
/** 仅静态文件部署(不启动 Docker),前端常用 */
|
||||||
|
staticDeploy?: boolean;
|
||||||
|
/** @deprecated 改用 staticDeploy;若存在则仍视为静态部署 */
|
||||||
extractDir?: string;
|
extractDir?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# 运行时镜像:业务 JAR 通过 volume 挂载 /data/app.jar,更新部署无需重建镜像
|
# 运行时镜像:业务 JAR 通过 volume 挂载 /app/app.jar,更新部署无需重建镜像
|
||||||
ARG BASE_IMAGE=docker.m.daocloud.io/library/eclipse-temurin:17-jre-alpine
|
ARG BASE_IMAGE=docker.m.daocloud.io/library/eclipse-temurin:17-jre-alpine
|
||||||
FROM ${BASE_IMAGE}
|
FROM ${BASE_IMAGE}
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ RUN addgroup -S app && adduser -S app -G app
|
|||||||
USER app
|
USER app
|
||||||
# 实际端口由 Spring profile 决定(test:8101 / pre:8102 / prod:8103)
|
# 实际端口由 Spring profile 决定(test:8101 / pre:8102 / prod:8103)
|
||||||
EXPOSE 8101 8102 8103
|
EXPOSE 8101 8102 8103
|
||||||
ENTRYPOINT ["java", "-jar", "/data/app.jar"]
|
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ server:
|
|||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://192.168.3.100:3306/ecom_dmb_test?characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://192.168.3.100:3306/ecom_dmb_dev?characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
username: ecom_dmb_test
|
username: ecom_dmb_dev
|
||||||
password: ecom_dmb_test
|
password: ecom_dmb_dev
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.3.100
|
host: 192.168.3.100
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# 运行时镜像:业务代码通过 volume 挂载 /data,更新部署无需重建镜像
|
# 运行时镜像:业务代码通过 volume 挂载 /app,更新部署无需重建镜像
|
||||||
ARG BASE_IMAGE=docker.m.daocloud.io/library/node:22-alpine
|
ARG BASE_IMAGE=docker.m.daocloud.io/library/node:22-alpine
|
||||||
FROM ${BASE_IMAGE}
|
FROM ${BASE_IMAGE}
|
||||||
|
|
||||||
WORKDIR /data
|
WORKDIR /app
|
||||||
RUN addgroup -S app && adduser -S app -G app && corepack enable
|
RUN addgroup -S app && adduser -S app -G app && corepack enable
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
|
|||||||
Reference in New Issue
Block a user