将 checkout、setup-go、setup-node 和 upload-artifact 升级到官方当前版本,消除 GitHub Actions 对 Node.js 20 的弃用警告。 同步升级 Docker QEMU、Buildx、登录、元数据和镜像构建插件,并保持现有分支触发条件与 Docker 发布行为不变。
68 lines
1.7 KiB
YAML
68 lines
1.7 KiB
YAML
name: 构建并发布 Docker 镜像
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
concurrency:
|
|
group: docker-publish-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
publish:
|
|
name: 发布多架构镜像
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 QEMU
|
|
uses: docker/setup-qemu-action@v4
|
|
|
|
- name: 配置 Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: 登录 GitHub Container Registry
|
|
uses: docker/login-action@v4
|
|
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@v6
|
|
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@v7
|
|
with:
|
|
context: .
|
|
file: Dockerfile.debian13
|
|
platforms: linux/amd64,linux/arm64
|
|
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
|