ci(docker): publish ghcr latest and release tags only

This commit is contained in:
rbetree
2026-02-19 18:58:42 +08:00
parent eea801bef3
commit ebf7ebf14a
2 changed files with 79 additions and 3 deletions

57
.github/workflows/docker-ghcr.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: Docker Publish (GHCR)
on:
push:
branches: [main]
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: read
packages: write
concurrency:
group: docker-ghcr-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max