增加 GitHub Docker 镜像发布流程

通过 GitHub Actions 构建并发布 linux/amd64 镜像到 GHCR,补充镜像标签策略和服务器拉取部署说明。
This commit is contained in:
Christ committed 2026-07-23 16:10:25 +08:00
1 parent 6a9a684e5e
commit a5a8aa9b8b
3 files changed
+77 -3

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
name: 构建并发布 Docker 镜像
on:
push:
branches:
- dev
- main
tags:
- "v*"
workflow_dispatch:
permissions:
contents: read
packages: write
concurrency:
group: docker-publish-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
name: 发布 linux/amd64 镜像
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 配置 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录 GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 生成小写镜像名称
id: image
shell: bash
run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: 生成镜像标签
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
- name: 构建并推送镜像
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.debian13
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: mode=max
sbom: true