Skip to content

通过 tag 发布镜像 #15

通过 tag 发布镜像

通过 tag 发布镜像 #15

Workflow file for this run

name: Publish Multi-Architecture Docker Image
on:
push:
tags: # 仅在推送 Git Tag 时触发
- '*'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# 检出代码
- name: Checkout code
uses: actions/checkout@v3
# 提取 Git Tag
- name: Extract Git Tag
id: git_tag
run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV
# 设置 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 登录到 GitHub Packages
- name: Log in to GitHub Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 登录到 Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 构建并推送多架构镜像到 GitHub Packages 和 Docker Hub
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.tag }}
${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ env.tag }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386,linux/ppc64le,linux/s390x