Files
common/README.md
T
2026-01-09 18:00:15 +08:00

55 lines
1.4 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.
# 通用构建推送脚本
`build_push.sh` 是一个通用的镜像编译和推送脚本,用于在 CI/CD 环境中构建和推送多架构 Docker 镜像到 SWR 注册表。
## 功能特性
- 支持多架构构建 (linux/amd64, linux/arm64)
- 支持 CI/CD 环境变量
- 自动处理标签(基于分支或标签)
- 支持 main 分支推送时添加 latest 标签
- 自动清理构建缓存及镜像
## 环境变量
以下环境变量需要在 CI/CD 环境中手动设置 (通过运行时的 Secrets 导入)
- `SWR_REGISTRY`: 镜像注册表地址
- `SWR_USERNAME`: 注册表用户名(从密钥获取)
- `SWR_PASSWORD`: 注册表密码(从密钥获取)
以下环境变量为 CI/CD 运行时自动设置:
- `CI_REPO_NAME`: 仓库名称
- `CI_COMMIT_TAG`: 提交标签(可选,用于标签推送)
- `CI_COMMIT_SHA`: 提交 SHA(用于默认标签)
- `CI_COMMIT_BRANCH`: 提交分支(用于确定是否推送 latest 标签)
## 使用方法
在 CI/CD 配置中,将脚本复制到项目中并执行:
```bash
# 基于 Git Submodule 更新脚本
git submodule update --init --recursive
# 执行构建推送
sh .ci/common/build_push.sh
```
## Git Submodule 集成
此脚本作为 Git Submodule 集成到项目中:
```bash
git submodule add https://git.colovu.com/docker/common.git .ci/common
```
## 错误处理
脚本会在以下情况退出:
- 必需的环境变量未设置
- 无法登录到镜像注册表
- 构建或推送失败