Skip to content

Commit 1da11ec

Browse files
committed
chore(workflows): update Docker publish workflow for multi-platform support
- Changed the runner from `anduro-runner` to `ubuntu-latest` for parralel jobs compatibility. - Added a strategy for multi-platform builds targeting `linux/amd64` and `linux/arm64`. - Set up QEMU for cross-platform builds and adjusted the build step to push images by digest. - Introduced a new merge job to create and push a multi-arch manifest after building images. - Removed the conditional installation of the cosign tool and streamlined the signing process for published images.
1 parent 17f6475 commit 1da11ec

File tree

1 file changed

+77
-24
lines changed

1 file changed

+77
-24
lines changed

.github/workflows/docker-publish.yml

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ env:
2626

2727
jobs:
2828
build:
29-
runs-on: anduro-runner
29+
runs-on: ubuntu-latest
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platform: [linux/amd64, linux/arm64]
3034
permissions:
3135
contents: read
3236
packages: write
@@ -38,18 +42,15 @@ jobs:
3842
- name: Checkout repository
3943
uses: actions/checkout@v4
4044

41-
# Install the cosign tool except on PR
42-
# https://github.com/sigstore/cosign-installer
43-
- name: Install cosign
44-
if: github.event_name != 'pull_request'
45-
uses: sigstore/cosign-installer@v3.5.0
46-
4745
# Set up BuildKit Docker container builder to be able to build
4846
# multi-platform images and export cache
4947
# https://github.com/docker/setup-buildx-action
5048
- name: Set up Docker Buildx
5149
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
5250

51+
- name: Set up QEMU
52+
uses: docker/setup-qemu-action@v3
53+
5354
# Login against a Docker registry except on PR
5455
# https://github.com/docker/login-action
5556
- name: Log into registry ${{ env.REGISTRY }}
@@ -68,32 +69,84 @@ jobs:
6869
with:
6970
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
7071

71-
# Build and push Docker image with Buildx (don't push on PR)
72+
# Build and push per-arch image by digest (don't push on PR)
7273
# https://github.com/docker/build-push-action
73-
- name: Build and push Docker image
74-
id: build-and-push
75-
uses: docker/build-push-action@v6 # v5.0.0
74+
- name: Build and push by digest (${{ matrix.platform }})
75+
id: build
76+
uses: docker/build-push-action@v6
7677
with:
7778
context: .
7879
file: ./etc/Dockerfile
7980
push: ${{ github.event_name != 'pull_request' }}
80-
tags: ${{ steps.meta.outputs.tags }}
81+
platforms: ${{ matrix.platform }}
8182
labels: ${{ steps.meta.outputs.labels }}
82-
platforms: linux/amd64,linux/arm64
8383
cache-from: type=gha
8484
cache-to: type=gha,mode=max
85+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true
86+
87+
- name: Export digest
88+
if: ${{ github.event_name != 'pull_request' }}
89+
run: |
90+
mkdir -p /tmp/digests
91+
digest="${{ steps.build.outputs.digest }}"
92+
touch "/tmp/digests/${digest#sha256:}"
8593
86-
# Sign the resulting Docker image digest except on PRs.
87-
# This will only write to the public Rekor transparency log when the Docker
88-
# repository is public to avoid leaking data. If you would like to publish
89-
# transparency data even for private images, pass --force to cosign below.
90-
# https://github.com/sigstore/cosign
91-
- name: Sign the published Docker image
94+
- name: Upload digest
9295
if: ${{ github.event_name != 'pull_request' }}
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: digests-${{ matrix.platform }}
99+
path: /tmp/digests/*
100+
101+
merge:
102+
if: ${{ github.event_name != 'pull_request' }}
103+
needs: build
104+
runs-on: anduro-runner
105+
permissions:
106+
contents: read
107+
packages: write
108+
id-token: write
109+
steps:
110+
- name: Set up Docker Buildx
111+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
112+
113+
- name: Log into registry ${{ env.REGISTRY }}
114+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
115+
with:
116+
registry: ${{ env.REGISTRY }}
117+
username: ${{ github.actor }}
118+
password: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Download digests
121+
uses: actions/download-artifact@v4
122+
with:
123+
pattern: digests-*
124+
path: /tmp/digests
125+
merge-multiple: true
126+
127+
# Extract metadata (tags, labels) for Docker
128+
- name: Extract Docker metadata
129+
id: meta
130+
uses: docker/metadata-action@v5
131+
with:
132+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
133+
134+
- name: Create and push multi-arch manifest
135+
run: |
136+
tags="${{ steps.meta.outputs.tags }}"
137+
for tag in $tags; do
138+
args=""
139+
for file in /tmp/digests/*; do
140+
args="$args ${tag}@sha256:$(basename "$file")"
141+
done
142+
docker buildx imagetools create -t "$tag" $args
143+
done
144+
145+
# Install the cosign tool
146+
- name: Install cosign
147+
uses: sigstore/cosign-installer@v3.5.0
148+
149+
- name: Sign the published Docker images
93150
env:
94-
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
95151
TAGS: ${{ steps.meta.outputs.tags }}
96-
DIGEST: ${{ steps.build-and-push.outputs.digest }}
97-
# This step uses the identity token to provision an ephemeral certificate
98-
# against the sigstore community Fulcio instance.
99-
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
152+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}

0 commit comments

Comments
 (0)