Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ name: Build and Push Docker Image

on:
release:
types: [ published ] # 发布 release 时触发
workflow_dispatch: # 手动触发
types: [published]
workflow_dispatch:
inputs:
branch:
description: '要构建的分支'
required: true
default: 'dev'
type: choice
options:
- dev
- main
tag:
description: '镜像标签'
required: true
default: 'dev'
type: string

env:
REGISTRY: docker.io
Expand All @@ -19,12 +33,13 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || 'main' }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand All @@ -36,22 +51,23 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}} # v0.0.1
type=raw,value=latest,enable={{is_default_branch}} # latest
type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Update Docker Hub README
if: github.event_name != 'pull_request'
if: github.event_name == 'release'
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand Down
Loading