Files
wrong-notebook/.github/workflows/build-docker.yml
margrop 3a70f83bd9 ci: 升级 GitHub Actions 至 Node 24 运行时版本
checkout、setup-node、cache、upload/download-artifact、setup-java、
docker 系列与 action-gh-release 升级到最新大版本(仍按提交 SHA 固定);
发布不足两周的 docker/login-action 取 v4.6.0;
gradle/actions 停在 v5.0.2,避免 v6 缓存组件的商业许可条款。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 20:01:11 +08:00

131 lines
4.1 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Manual Docker Build & Publish
on:
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag (default: latest)'
required: false
default: 'latest'
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-arch:
name: Build (${{ matrix.arch }})
# 只在 GitHub 上运行;Gitea 读取 main 时会回退到本目录,需跳过
if: github.server_url == 'https://github.com'
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
platform: linux/amd64
os: ubuntu-24.04
- arch: arm64
platform: linux/arm64
os: ubuntu-24.04-arm
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # 需要标签来得出版本号
- name: Resolve version from tags
id: version
run: echo "version=$(git describe --tags --match 'v[0-9]*' 2>/dev/null || true)" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to the Container registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image by digest
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
platforms: ${{ matrix.platform }}
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
APP_REVISION=${{ github.sha }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=docker-${{ matrix.arch }}
cache-to: type=gha,scope=docker-${{ matrix.arch }},mode=max
- name: Export digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
mkdir -p /tmp/digests
touch "/tmp/digests/${DIGEST#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: docker-digest-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
build-and-push:
name: Merge & Publish Manifest
runs-on: ubuntu-24.04
needs: build-and-push-arch
if: github.server_url == 'https://github.com'
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: /tmp/digests
pattern: docker-digest-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to the Container registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest list and push
working-directory: /tmp/digests
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
TAG: ${{ inputs.tag }}
run: |
sources=()
for digest in *; do
sources+=("${IMAGE}@sha256:${digest}")
done
docker buildx imagetools create -t "${IMAGE}:${TAG}" "${sources[@]}"
- name: Inspect image
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
TAG: ${{ inputs.tag }}
run: |
docker buildx imagetools inspect "${IMAGE}:${TAG}"