Files
PolyHermes/.github/workflows/docker-build.yml
T
WrBug 60dbfbcfde refactor: 将部署和删除功能分离到独立的 workflow 文件
- 创建 docker-build.yml:专门负责构建和推送 Docker 镜像
- 创建 docker-delete.yml:专门负责删除 Docker 镜像标签
- 简化 docker-build.yml,移除删除逻辑
- 更新文档,说明两个独立的 workflow 文件及其职责
2025-12-07 17:26:04 +08:00

68 lines
2.4 KiB
YAML
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.
name: Build and Push Docker Image
on:
release:
types:
- published # 当通过 GitHub Releases 页面创建 release 时触发
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }} # 使用 release 对应的 tag
- name: Extract version from release
id: extract_version
run: |
# 从 release tag 中提取版本号(例如 v1.0.0 -> 1.0.0
TAG_NAME="${{ github.event.release.tag_name }}"
if [ -z "$TAG_NAME" ]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
fi
# 验证版本号格式:v数字.数字.数字[-后缀](例如 v1.0.0, v2.10.102, v1.0.0-beta
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
echo "错误: 版本号格式不正确,应为 v数字.数字.数字 或 v数字.数字.数字-后缀 (例如: v1.0.0, v1.0.0-beta)"
exit 1
fi
VERSION=${TAG_NAME#v} # 移除 v 前缀
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "TAG=$TAG_NAME" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
echo "Full tag: $TAG_NAME"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# 启用多架构构建支持
platforms: linux/amd64,linux/arm64
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
# 多架构构建:支持 amd64 和 arm64
platforms: linux/amd64,linux/arm64
tags: |
wrbug/polyhermes:${{ steps.extract_version.outputs.TAG }}
wrbug/polyhermes:latest
build-args: |
VERSION=${{ steps.extract_version.outputs.VERSION }}
GIT_TAG=${{ steps.extract_version.outputs.TAG }}
GITHUB_REPO_URL=https://github.com/WrBug/PolyHermes
cache-from: type=registry,ref=wrbug/polyhermes:latest
cache-to: type=inline