gongxiangp2/scripts/README.md

105 lines
3.1 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.

# 脚本说明
> 更新时间:2026-05-07
> 部署相关脚本以 `scripts/git-incremental-deploy.ps1` 为当前默认口径。
详细说明:
- [部署规范](../docs/部署规范.md)
- [Git 增量部署方案](../docs/Git增量部署方案.md)
- [部署脚本安全说明](../docs/部署脚本安全说明.md)
## 1. 核心部署脚本
### `scripts/git-incremental-deploy.ps1` ⭐⭐⭐ 当前推荐
以 Git 仓库为唯一源码入口,构建机增量拉取源码并构建镜像,生产服务器只拉取镜像并替换容器。
特点:
- 不从本机上传源码压缩包。
- 构建机执行 `git fetch/reset`。
- Docker 构建继续复用缓存。
- 镜像按提交打标签,便于回滚。
- 生产机不构建源码,只拉镜像运行。
- 默认失败时尝试回滚旧镜像。
- 默认清理 Docker 无用镜像/容器,保留构建缓存。
运行前准备:
- 本机可用 PowerShell 5.1+。
- 本机已安装 PuTTY,`plink.exe` 和 `pscp.exe` 可用。
- 构建机密码通过 `BUILD_SERVER_PASSWORD` 或 `-BuildServerPassword` 提供。
- Git 认证通过 `GIT_DEPLOY_USERNAME` / `GIT_DEPLOY_PASSWORD` 或 `GIT_AUTH_HEADER` 提供。
预检:
```powershell
.\scripts\git-incremental-deploy.ps1 -DryRun
```
正式环境:
```powershell
.\scripts\git-incremental-deploy.ps1
```
影子环境:
```powershell
.\scripts\git-incremental-deploy.ps1 -Target shadow
```
部署指定提交:
```powershell
.\scripts\git-incremental-deploy.ps1 -Commit <commit-sha>
```
正式部署由维护人员执行,不要求普通用户手动运行。
## 2. 历史部署脚本
### `deploy-*.ps1` 本地历史脚本名
根目录 `deploy-*.ps1` 属于本地历史脚本名,受 `.gitignore` 保护,不作为仓库交付入口。
曾经出现过的旧链路包括:
- `deploy-remote-build.ps1`:本机打包源码并上传到构建机。
- `deploy-local-build.ps1`:本地构建部署。
- `deploy-public-build.ps1`:公网穿透部署。
这些名字只用于识别历史资料,不再作为当前推荐方式。
### `deploy-git-build.ps1` ⚠️ 已替代
旧 Git 工作流脚本已被 `scripts/git-incremental-deploy.ps1` 替代。后续 Git 增量部署只看新脚本。
## 3. 旧缓存脚本
下面这些脚本属于早期构建缓存方案,不是当前 Git 增量部署的默认前置步骤:
- `setup-build-cache.ps1`
- `build-base-image.ps1`
- `scripts/manage-build-cache.ps1`
只有在明确要维护旧缓存方案时才参考它们。当前常规部署优先使用构建机上的 Docker / Next 缓存,不再传播 `save-base-images.ps1`、`load-base-images.ps1`、`save-npm-packages.ps1` 这类已不存在的脚本名。
## 4. 数据库迁移脚本
### `scripts/execute-migration.ps1`
历史一次性迁移工具,只针对 `20251206000000_add_soft_delete_and_favorites` 这一个迁移,不是通用生产迁移入口。
高风险要求:
- 先确认该迁移在生产库尚未执行。
- 先确认生产库备份可用。
- 不在用户高峰期执行。
- 不把它当作普通部署流程的一部分。
### `scripts/execute-migration.sh`
Linux / macOS 版本的一次性迁移工具,适用范围同上。