1+ name : Build and Push Multi-Arch Docker Image
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+ workflow_dispatch :
8+
9+ env :
10+ REGISTRY : ghcr.io
11+ IMAGE_NAME : ${{ github.repository }}/server
12+
13+ jobs :
14+ build :
15+ runs-on : ${{ matrix.runner }}
16+ permissions :
17+ contents : read
18+ packages : write
19+
20+ strategy :
21+ fail-fast : false
22+ matrix :
23+ include :
24+ - platform : linux/amd64
25+ runner : ubuntu-latest
26+ arch : amd64
27+ - platform : linux/arm64
28+ runner : ubuntu-24.04-arm64
29+ arch : arm64
30+
31+ steps :
32+ - name : Give GitHub Actions access to @thirdweb-dev/vault
33+ uses : webfactory/ssh-agent@a6f90b1f127823b31d4d4a8d96047790581349bd
34+ with :
35+ ssh-private-key : ${{ secrets.VAULT_REPO_DEPLOY_KEY }}
36+
37+ - name : Checkout repository
38+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
39+
40+ - name : Set up Docker Buildx
41+ uses : docker/setup-buildx-action@8026d2bc3645ea78b0d2544766a1225eb5691f89
42+
43+ - name : Log in to Container Registry
44+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
45+ with :
46+ registry : ${{ env.REGISTRY }}
47+ username : ${{ github.actor }}
48+ password : ${{ secrets.GITHUB_TOKEN }}
49+
50+ - name : Extract metadata
51+ id : meta
52+ uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
53+ with :
54+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
55+ tags : |
56+ type=ref,event=tag
57+ type=raw,value=latest,enable={{is_default_branch}}
58+
59+ - name : Configure Git for SSH
60+ run : |
61+ git config --global url."git@github.com:".insteadOf "https://github.com/"
62+
63+ - name : Build and push platform-specific image
64+ id : build
65+ uses : docker/build-push-action@48aba3b46d1b1fec4febb7c167d0c247842c735b
66+ with :
67+ context : .
68+ file : ./server/Dockerfile
69+ platforms : ${{ matrix.platform }}
70+ push : true
71+ tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ matrix.arch }}
72+ labels : ${{ steps.meta.outputs.labels }}
73+ cache-from : type=gha,scope=${{ matrix.arch }}
74+ cache-to : type=gha,mode=max,scope=${{ matrix.arch }}
75+ ssh : |
76+ default=${{ env.SSH_AUTH_SOCK }}
77+
78+ - name : Export digest
79+ run : |
80+ mkdir -p /tmp/digests
81+ digest="${{ steps.build.outputs.digest }}"
82+ touch "/tmp/digests/${digest#sha256:}"
83+
84+ - name : Upload digest
85+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
86+ with :
87+ name : digests-${{ matrix.arch }}
88+ path : /tmp/digests/*
89+ if-no-files-found : error
90+ retention-days : 1
91+
92+ merge :
93+ runs-on : ubuntu-latest
94+ needs : build
95+ permissions :
96+ contents : read
97+ packages : write
98+
99+ steps :
100+ - name : Download digests
101+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
102+ with :
103+ path : /tmp/digests
104+ pattern : digests-*
105+ merge-multiple : true
106+
107+ - name : Set up Docker Buildx
108+ uses : docker/setup-buildx-action@8026d2bc3645ea78b0d2544766a1225eb5691f89
109+
110+ - name : Log in to Container Registry
111+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
112+ with :
113+ registry : ${{ env.REGISTRY }}
114+ username : ${{ github.actor }}
115+ password : ${{ secrets.GITHUB_TOKEN }}
116+
117+ - name : Extract metadata
118+ id : meta
119+ uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
120+ with :
121+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
122+ tags : |
123+ type=ref,event=tag
124+ type=raw,value=latest,enable={{is_default_branch}}
125+
126+ - name : Create manifest list and push
127+ working-directory : /tmp/digests
128+ run : |
129+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
130+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-amd64 \
131+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-arm64
132+
133+ - name : Inspect image
134+ run : |
135+ docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}
0 commit comments