gongxiangp2/scripts/README.md

134 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 脚本说明
## 核心部署脚本
### `deploy-local-build.ps1` ⭐
**本地构建部署脚本** - 本地构建镜像后部署(推荐使用)
- 本地构建 Docker 镜像(需要本地安装 Docker Desktop)
- 保存镜像为 tar 文件
- 上传镜像到服务器
- 服务器加载镜像并启动容器
- 自动清理本地和服务器 Docker 资源
- 支持部署到影子系统(端口 5320)或正式系统(端口 4320)
**重要提示:**
- ⚠️ **文件位置**:此脚本位于**项目根目录**(`E:\AI Code\gongxiangp2\deploy-local-build.ps1`),**不在** `scripts` 目录
- ⚠️ **前置要求**:需要本地安装 Docker Desktop 和 WSL 2
- ⚠️ **部署流程**:本地构建 → 保存镜像 → 上传服务器 → 加载镜像 → 启动容器
**使用方式:**
```powershell
# 在项目根目录执行
# 部署到影子系统(端口 5320)
.\deploy-local-build.ps1 -Target shadow
# 部署到正式系统(端口 4320)
.\deploy-local-build.ps1 -Target production
# 跳过本地构建,直接部署已有镜像
.\deploy-local-build.ps1 -Target shadow -SkipBuild
# 构建镜像时禁用缓存(确保彻底更新)
.\deploy-local-build.ps1 -Target production -NoCache
# 跳过自动清理步骤
.\deploy-local-build.ps1 -Target shadow -SkipCleanup
# 显示帮助
.\deploy-local-build.ps1 -Help
```
**参数说明:**
- `-Target`: 部署目标,`shadow`(影子系统,端口5320)或 `production`(正式系统,端口4320)
- `-ServerIP`: 服务器 IP(默认:192.168.58.20)
- `-ServerUser`: 服务器用户(默认:root)
- `-ImageName`: 镜像名称(默认:youyidian-3d-material)
- `-ImageTag`: 镜像标签(默认:latest)
- `-SkipBuild`: 跳过本地构建,直接部署已有镜像
- `-NoCache`: 构建镜像时禁用缓存(默认使用缓存以提高速度)
- `-SkipCleanup`: 跳过自动清理步骤
### `deploy-git-build.ps1`
**Git 工作流部署脚本** - 服务器端构建部署
- 本地提交代码到 Git
- 服务器从 Git 拉取代码
- 服务器端构建 Docker 镜像
- 自动部署新容器
- 支持清理旧镜像(保留最新4个)
**重要提示:**
- ⚠️ **文件位置**:此脚本位于**项目根目录**(`d:\gongxiangp2\deploy-git-build.ps1`),**不在** `scripts` 目录
- ⚠️ **部署流程**:本地提交 → Git推送 → 服务器拉取 → 服务器构建 → 部署
**使用方式:**
```powershell
# 在项目根目录执行(d:\gongxiangp2\)
# 部署到正式系统(端口 4320,自动提交并推送代码)
.\deploy-git-build.ps1 -Target production
# 部署到影子系统(端口 5320)
.\deploy-git-build.ps1 -Target shadow
# 指定提交信息
.\deploy-git-build.ps1 -Target production -CommitMessage "修复BUG"
# 仅提交不推送(用于本地测试)
.\deploy-git-build.ps1 -Target shadow -SkipPush
# 跳过提交,直接推送已有提交
.\deploy-git-build.ps1 -Target production -SkipCommit
# 构建镜像时禁用缓存
.\deploy-git-build.ps1 -Target production -NoCache
# 跳过构建产物清理
.\deploy-git-build.ps1 -Target production -SkipCleanup
# 显示帮助
.\deploy-git-build.ps1 -Help
```
**参数说明:**
- `-Target`: 部署目标,`shadow`(影子系统,端口5320)或 `production`(正式系统,端口4320)
- `-CommitMessage`: 提交信息(如果为空,将自动生成)
- `-SkipCommit`: 跳过Git提交(直接推送到远程)
- `-SkipPush`: 跳过Git推送(仅提交,不推送)
- `-NoCache`: 构建镜像时禁用缓存
- `-SkipCleanup`: 跳过构建产物清理
## 基础镜像管理
### `save-base-images.ps1`
下载并保存基础镜像到本地缓存
```powershell
.\save-base-images.ps1
```
### `load-base-images.ps1`
从本地加载基础镜像(部署脚本会自动调用)
```powershell
.\load-base-images.ps1
```
### `save-npm-packages.ps1`(可选)
缓存 npm 包到本地(网络不稳定时使用)
```powershell
.\save-npm-packages.ps1
```
## 数据库迁移脚本
### `execute-migration.ps1`
在生产库上执行数据库迁移(Windows PowerShell)
```powershell
.\execute-migration.ps1
```
### `execute-migration.sh`
在生产库上执行数据库迁移(Linux/Mac)
```bash
chmod +x execute-migration.sh
./execute-migration.sh
```