build(ci): 优化 Docker 构建流程并添加多平台支持

- 在 Dockerfile 中添加构建参数和标签信息用于缓存破坏
- 使用 --chown 确保正确的文件权限并验证构建产物
- 添加构建产物时间戳检查以确保最新性
- 获取并使用版本号进行镜像标签管理
- 添加清理冲突镜像标签的步骤
- 配置多平台构建支持(linux/amd64,linux/arm64)
- 添加版本标签和构建参数传递
- 配置构建缓存和镜像推送功能
This commit is contained in:
coolxitech
2026-01-08 17:55:40 +08:00
parent e4c4cdd63c
commit 9634dcb023
2 changed files with 70 additions and 1 deletions

View File

@@ -3,6 +3,16 @@
FROM nginx:alpine
# 添加构建参数用于缓存破坏
ARG BUILD_DATE
ARG VERSION
ARG COMMIT_SHA
# 添加标签信息
LABEL build.date="${BUILD_DATE}" \
build.version="${VERSION}" \
build.commit="${COMMIT_SHA}"
# 复制 nginx 配置文件
COPY nginx.conf /etc/nginx/conf.d/default.conf
@@ -11,7 +21,12 @@ RUN rm -rf /usr/share/nginx/html/*
# 复制构建产物到 nginx 静态文件目录
# 这里的 docs 目录是在 GitHub Actions 中构建生成的
COPY docs /usr/share/nginx/html
# 使用 --chown 确保正确的文件权限
COPY --chown=nginx:nginx docs /usr/share/nginx/html
# 验证构建产物
RUN ls -la /usr/share/nginx/html/ && \
test -f /usr/share/nginx/html/index.html || (echo "构建产物验证失败" && exit 1)
# 暴露端口
EXPOSE 80