-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(publish): use publish-multi-platform reusable workflow (#15)
- Loading branch information
1 parent
c36aaa3
commit 71ed0a1
Showing
2 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
registry-image: | ||
description: >- | ||
Docker image to use as base name for tags. | ||
required: true | ||
type: string | ||
metadata-tags: | ||
description: >- | ||
List of tags as key-value pair attributes. | ||
required: false | ||
type: string | ||
registry-address: | ||
description: >- | ||
Server address of Docker registry. If not set then will default to Docker registry. | ||
required: false | ||
type: string | ||
default: docker.io | ||
registry-username: | ||
description: >- | ||
Username for authenticating to the Docker registry. | ||
required: true | ||
type: string | ||
build-platforms: | ||
description: >- | ||
List of target platforms for build. | ||
required: false | ||
type: string | ||
default: '["linux/amd64", "linux/arm64"]' | ||
build-file: | ||
description: >- | ||
Path to the Dockerfile. | ||
type: string | ||
required: false | ||
build-provenance: | ||
description: >- | ||
Generate provenance attestation for the build. | ||
required: false | ||
type: boolean | ||
default: false | ||
build-cache-key: | ||
description: >- | ||
An explicit key for a cache entry. | ||
required: false | ||
type: string | ||
default: coatl | ||
build-digest-key: | ||
description: >- | ||
Name of the build digest. | ||
required: false | ||
type: string | ||
default: coatl | ||
secrets: | ||
registry-password: | ||
description: >- | ||
Password or personal access token for authenticating the Docker registry. | ||
required: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: ${{ fromJSON(inputs.build-platforms) }} | ||
steps: | ||
- name: Prepare | ||
run: | | ||
platform=${{ matrix.platform }} | ||
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ inputs.registry-image }} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry-address }} | ||
username: ${{ inputs.registry-username }} | ||
password: ${{ secrets.registry-password }} | ||
|
||
- name: Build and push by digest | ||
id: build | ||
uses: docker/build-push-action@v6 | ||
with: | ||
cache-from: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }} | ||
cache-to: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }},mode=max | ||
file: ${{ inputs.build-file }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ inputs.registry-image }},push-by-digest=true,name-canonical=true,push=true | ||
platforms: ${{ matrix.platform }} | ||
provenance: ${{ inputs.build-provenance }} | ||
|
||
- 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@v4 | ||
with: | ||
name: digests-${{ inputs.build-digest-key }}-${{ env.PLATFORM_PAIR }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
merge: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-${{ inputs.build-digest-key }}-* | ||
merge-multiple: true | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ inputs.registry-image }} | ||
tags: | | ||
${{ inputs.metadata-tags }} | ||
- name: Login to Docker registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ inputs.registry-address }} | ||
username: ${{ inputs.registry-username }} | ||
password: ${{ secrets.registry-password }} | ||
|
||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ inputs.registry-image }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ inputs.registry-image }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters