mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 06:29:27 +08:00
131 lines
4.1 KiB
YAML
131 lines
4.1 KiB
YAML
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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||
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@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
||
|
||
- name: Log in to the Container registry
|
||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.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@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.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@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||
with:
|
||
path: /tmp/digests
|
||
pattern: docker-digest-*
|
||
merge-multiple: true
|
||
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
||
|
||
- name: Log in to the Container registry
|
||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.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}"
|