Skip to content

Commit

Permalink
ci(publish): use publish-multi-platform reusable workflow (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarcoatl authored Sep 1, 2024
1 parent c36aaa3 commit 71ed0a1
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
157 changes: 157 additions & 0 deletions .github/workflows/publish-multi-platform.yml
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 }}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
publish:
uses: coatl-dev/workflows/.github/workflows/docker-publish-multi-platform.yml@v4
uses: ./.github/workflows/publish-multi-platform.yml
strategy:
matrix:
variant: [jython, python]
Expand Down

0 comments on commit 71ed0a1

Please sign in to comment.