Skip to content

Commit 5fefe25

Browse files
committed
.github: cross-compile docker images
Build docker images for amd64, arm64, and arm/v7. Also several other small improvements to docker workflow like documenting which actions we run on, setting concurrency settings, and reversing the logic for when we push new images live (specifically looking for a push event rather than a "not pull request" event, in case we add other events later). Fixes #26
1 parent af7ceb5 commit 5fefe25

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

.github/workflows/docker.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ name: Docker
22

33
on:
44
push:
5+
# push events will publish a new image, so only trigger on main branch or semver tags.
56
branches: [ 'main' ]
67
tags: [ 'v*' ]
78
pull_request:
9+
# Run the workflow on pull_request events to ensure we can still build the image.
10+
# We only publish the image on push events (see if statements in steps below).
811
branches: [ 'main' ]
912

1013
env:
1114
REGISTRY: ghcr.io
1215
IMAGE_NAME: ${{ github.repository }}
1316

17+
concurrency:
18+
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
1421
jobs:
1522
build-and-push-image:
1623
runs-on: ubuntu-latest
@@ -27,7 +34,7 @@ jobs:
2734

2835
- name: Log into registry ${{ env.REGISTRY }}
2936
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
30-
if: github.event_name != 'pull_request'
37+
if: github.event_name == 'push'
3138
with:
3239
registry: ${{ env.REGISTRY }}
3340
username: ${{ github.actor }}
@@ -44,16 +51,17 @@ jobs:
4451
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
4552
with:
4653
context: .
47-
push: ${{ github.event_name != 'pull_request' }}
54+
push: ${{ github.event_name == 'push' }}
4855
tags: ${{ steps.meta.outputs.tags }}
4956
labels: ${{ steps.meta.outputs.labels }}
57+
platforms: linux/amd64,linux/arm64,linux/arm/v7
5058

5159
# Sign the Docker image
5260
- name: Install cosign
53-
if: github.event_name != 'pull_request'
61+
if: github.event_name == 'push'
5462
uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b #v2.8.1
5563
- name: Sign the published Docker image
56-
if: github.event_name != 'pull_request'
64+
if: github.event_name == 'push'
5765
env:
5866
COSIGN_EXPERIMENTAL: "true"
5967
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}

0 commit comments

Comments
 (0)