mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-03 05:41:52 +09:00
* Add GHCR package cleanup workflow * Add job summaries to CI workflows * Add create-release workflow; update release-docker * Improve auto-cs-fix workflow: caching and summary * Use GHCR build-cache image and mirror manifests * Remove prepare-application-assets action * Standardize workflow step names and cache image
226 lines
7.4 KiB
YAML
226 lines
7.4 KiB
YAML
name: Multi-platform Docker Build
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
target:
|
|
required: true
|
|
type: string
|
|
build-args:
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
cache-scope:
|
|
required: true
|
|
type: string
|
|
meta-images:
|
|
required: true
|
|
type: string
|
|
meta-tags:
|
|
required: true
|
|
type: string
|
|
meta-flavor:
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
extract-release-tree:
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
release-tree-artifact-name:
|
|
required: false
|
|
type: string
|
|
default: 'release-tree'
|
|
secrets:
|
|
DOCKERHUB_USERNAME:
|
|
required: true
|
|
DOCKERHUB_TOKEN:
|
|
required: true
|
|
outputs:
|
|
release-tree-artifact:
|
|
value: ${{ jobs.build.outputs.release-tree-artifact }}
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
build:
|
|
name: 'Build (${{ matrix.platform }})'
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- platform: linux/amd64
|
|
runner: ubuntu-24.04
|
|
suffix: amd64
|
|
- platform: linux/arm64
|
|
runner: ubuntu-24.04-arm
|
|
suffix: arm64
|
|
fail-fast: false
|
|
outputs:
|
|
release-tree-artifact: ${{ steps.release-tree-output.outputs.artifact-name || '' }}
|
|
steps:
|
|
- name: 'Checkout Repository'
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: 'Set Registry Cache Image'
|
|
run: echo "CACHE_IMAGE=ghcr.io/${GITHUB_REPOSITORY@L}-build-cache" >> "${GITHUB_ENV}"
|
|
|
|
- name: 'Set Release Tree Artifact Output'
|
|
id: release-tree-output
|
|
if: inputs.extract-release-tree
|
|
run: echo "artifact-name=${{ inputs.release-tree-artifact-name }}" >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: 'Login to Docker Hub'
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: 'Login to GitHub Container Registry'
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 'Set up Docker Buildx'
|
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
|
|
|
|
- name: 'Docker Metadata'
|
|
id: meta
|
|
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
|
|
with:
|
|
images: ${{ inputs.meta-images }}
|
|
tags: ${{ inputs.meta-tags }}
|
|
flavor: ${{ inputs.meta-flavor }}
|
|
|
|
- name: 'Build and Push by Digest'
|
|
id: build
|
|
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7
|
|
with:
|
|
build-args: ${{ inputs.build-args }}
|
|
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:${{ inputs.cache-scope }}
|
|
cache-to: type=registry,ref=${{ env.CACHE_IMAGE }}:${{ inputs.cache-scope }},mode=max
|
|
context: .
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
outputs: type=image,name=docker.io/${{ inputs.meta-images }},name-canonical=true,push=true,push-by-digest=true
|
|
provenance: false
|
|
target: ${{ inputs.target }}
|
|
|
|
- name: 'Extract Release Tree'
|
|
if: inputs.extract-release-tree && matrix.platform == 'linux/amd64'
|
|
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7
|
|
with:
|
|
build-args: ${{ inputs.build-args }}
|
|
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:${{ inputs.cache-scope }}
|
|
context: .
|
|
outputs: type=local,dest=./release-tree
|
|
target: release-artifact
|
|
|
|
- name: 'Create Release Tree Archive'
|
|
if: inputs.extract-release-tree && matrix.platform == 'linux/amd64'
|
|
run: tar -cf /tmp/build.tar -C ./release-tree ./
|
|
|
|
- name: 'Upload Release Tree'
|
|
if: inputs.extract-release-tree && matrix.platform == 'linux/amd64'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
if-no-files-found: 'error'
|
|
name: ${{ inputs.release-tree-artifact-name }}
|
|
path: /tmp/build.tar
|
|
retention-days: 1
|
|
|
|
- name: 'Export Digest'
|
|
run: |
|
|
mkdir -p /tmp/digests
|
|
digest="${{ steps.build.outputs.digest }}"
|
|
touch "/tmp/digests/${digest#sha256:}"
|
|
|
|
- name: 'Upload Digest'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
if-no-files-found: 'error'
|
|
name: digest-${{ matrix.suffix }}
|
|
path: /tmp/digests/*
|
|
retention-days: 1
|
|
|
|
merge:
|
|
name: 'Merge Multi-Platform Manifest'
|
|
needs: [ build ]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: 'Login to Docker Hub'
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: 'Login to GitHub Container Registry'
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: 'Set up Docker Buildx'
|
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
|
|
|
|
- name: 'Docker Metadata'
|
|
id: meta
|
|
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
|
|
with:
|
|
images: ${{ inputs.meta-images }}
|
|
tags: ${{ inputs.meta-tags }}
|
|
flavor: ${{ inputs.meta-flavor }}
|
|
|
|
- name: 'Download Digests'
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
path: /tmp/digests
|
|
pattern: digest-*
|
|
merge-multiple: true
|
|
|
|
- name: 'Create Manifest List and Push'
|
|
working-directory: /tmp/digests
|
|
run: |
|
|
mapfile -t metadata_tags < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON")
|
|
tag_args=()
|
|
for tag in "${metadata_tags[@]}"; do
|
|
tag_args+=(-t "$tag")
|
|
done
|
|
|
|
digest_args=()
|
|
for digest in *; do
|
|
digest_args+=("docker.io/${{ inputs.meta-images }}@sha256:${digest}")
|
|
done
|
|
|
|
docker buildx imagetools create "${tag_args[@]}" "${digest_args[@]}"
|
|
|
|
- name: 'Mirror Manifest List to GHCR'
|
|
run: |
|
|
mapfile -t docker_tags < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON")
|
|
ghcr_tag_args=()
|
|
for tag in "${docker_tags[@]}"; do
|
|
ghcr_tag_args+=(-t "ghcr.io/${tag#docker.io/}")
|
|
done
|
|
|
|
docker buildx imagetools create \
|
|
"${ghcr_tag_args[@]}" \
|
|
"docker.io/${{ inputs.meta-images }}:${{ steps.meta.outputs.version }}"
|
|
|
|
- name: 'Inspect Image'
|
|
run: |
|
|
docker buildx imagetools inspect \
|
|
'docker.io/${{ inputs.meta-images }}:${{ steps.meta.outputs.version }}'
|
|
|
|
- name: 'Inspect GHCR Image'
|
|
run: |
|
|
docker buildx imagetools inspect \
|
|
'ghcr.io/${{ inputs.meta-images }}:${{ steps.meta.outputs.version }}'
|