Skip to content

Commit 8626768

Browse files
committed
Add arm64 platform to docker image
1 parent d9a30df commit 8626768

File tree

1 file changed

+77
-13
lines changed

1 file changed

+77
-13
lines changed

.github/workflows/main.yml

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ jobs:
2222
- run: mix test
2323

2424
docker:
25-
name: Docker
26-
runs-on: ubuntu-24.04
25+
name: Docker (${{ matrix.platform }})
26+
runs-on: ${{ matrix.runner }}
2727

2828
permissions:
2929
contents: 'read'
3030
id-token: 'write'
3131

32+
strategy:
33+
matrix:
34+
include:
35+
- platform: linux/amd64
36+
runner: ubuntu-24.04
37+
- platform: linux/arm64
38+
runner: ubuntu-24.04-arm
39+
3240
env:
3341
IMAGE_NAME: 'diff'
3442
PROJECT_ID: 'hexpm-prod'
@@ -38,12 +46,6 @@ jobs:
3846
steps:
3947
- uses: actions/checkout@v4
4048

41-
- name: Set short git commit SHA
42-
id: vars
43-
run: |
44-
calculatedSha=$(git rev-parse --short ${{ github.sha }})
45-
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
46-
4749
- name: Set up Docker Buildx
4850
uses: docker/setup-buildx-action@v3
4951

@@ -66,10 +68,72 @@ jobs:
6668
username: 'oauth2accesstoken'
6769
password: '${{ steps.auth.outputs.access_token }}'
6870

69-
- name: Build and push
71+
- name: Build and push by digest
72+
id: build
7073
uses: docker/build-push-action@v6
7174
with:
72-
tags: gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.COMMIT_SHORT_SHA }}
73-
push: ${{ github.event_name != 'pull_request' }}
74-
cache-from: type=gha
75-
cache-to: type=gha,mode=max
75+
platforms: ${{ matrix.platform }}
76+
outputs: type=image,name=gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
77+
cache-from: type=gha,scope=${{ matrix.platform }}
78+
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
79+
80+
- name: Export digest
81+
if: ${{ github.event_name != 'pull_request' }}
82+
run: |
83+
mkdir -p /tmp/digests
84+
digest="${{ steps.build.outputs.digest }}"
85+
touch "/tmp/digests/${digest#sha256:}"
86+
87+
- name: Upload digest
88+
if: ${{ github.event_name != 'pull_request' }}
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: digests-${{ matrix.runner }}
92+
path: /tmp/digests/*
93+
if-no-files-found: error
94+
retention-days: 1
95+
96+
docker-merge:
97+
name: Docker Merge
98+
runs-on: ubuntu-24.04
99+
if: ${{ github.event_name != 'pull_request' }}
100+
needs: docker
101+
permissions:
102+
contents: 'read'
103+
id-token: 'write'
104+
env:
105+
IMAGE_NAME: 'diff'
106+
PROJECT_ID: 'hexpm-prod'
107+
SERVICE_ACCOUNT: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
108+
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCLOUD_WORKFLOW_IDENTITY_POOL_PROVIDER }}
109+
steps:
110+
- name: Set short git commit SHA
111+
run: echo "COMMIT_SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
112+
- name: Download digests
113+
uses: actions/download-artifact@v4
114+
with:
115+
path: /tmp/digests
116+
pattern: digests-*
117+
merge-multiple: true
118+
- name: Set up Docker Buildx
119+
uses: docker/setup-buildx-action@v3
120+
- name: Google auth
121+
id: auth
122+
uses: 'google-github-actions/auth@v2'
123+
with:
124+
token_format: 'access_token'
125+
project_id: ${{ env.PROJECT_ID }}
126+
service_account: ${{ env.SERVICE_ACCOUNT }}
127+
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
128+
- name: Docker Auth
129+
uses: 'docker/login-action@v3'
130+
with:
131+
registry: gcr.io
132+
username: 'oauth2accesstoken'
133+
password: '${{ steps.auth.outputs.access_token }}'
134+
- name: Create manifest list and push
135+
working-directory: /tmp/digests
136+
run: |
137+
docker buildx imagetools create \
138+
-t gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.COMMIT_SHORT_SHA }} \
139+
$(printf 'gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)

0 commit comments

Comments
 (0)