Skip to content

Commit 235b8a6

Browse files
committed
Adding GitHub Action to build and push image.
1 parent f59db6f commit 235b8a6

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

.github/workflows/docker-build.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
name: Docker Multi-arch Build
3+
4+
on:
5+
push:
6+
branches: [ 9.x ]
7+
8+
permissions:
9+
contents: read
10+
11+
env:
12+
REGISTRY_IMAGE: ghcr.io/rgrizzell/circuitpython
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
platform:
21+
- linux/amd64
22+
- linux/arm64
23+
steps:
24+
- name: Prepare
25+
run: |
26+
platform=${{ matrix.platform }}
27+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
28+
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Docker meta
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ${{ env.REGISTRY_IMAGE }}
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Login to GitHub Container Registry
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.repository_owner }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Build and push by digest
52+
id: build
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
platforms: ${{ matrix.platform }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
59+
60+
- name: Export digest
61+
run: |
62+
mkdir -p /tmp/digests
63+
digest="${{ steps.build.outputs.digest }}"
64+
touch "/tmp/digests/${digest#sha256:}"
65+
66+
- name: Upload digest
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: digests-${{ env.PLATFORM_PAIR }}
70+
path: /tmp/digests/*
71+
if-no-files-found: error
72+
retention-days: 1
73+
74+
merge:
75+
runs-on: ubuntu-latest
76+
needs:
77+
- build
78+
steps:
79+
- name: Download digests
80+
uses: actions/download-artifact@v4
81+
with:
82+
path: /tmp/digests
83+
pattern: digests-*
84+
merge-multiple: true
85+
86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
89+
- name: Docker meta
90+
id: meta
91+
uses: docker/metadata-action@v5
92+
with:
93+
images: ${{ env.REGISTRY_IMAGE }}
94+
95+
- name: Login to GitHub Container Registry
96+
uses: docker/login-action@v3
97+
with:
98+
registry: ghcr.io
99+
username: ${{ github.repository_owner }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
102+
- name: Create manifest list and push
103+
working-directory: /tmp/digests
104+
run: |
105+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
106+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
107+
108+
- name: Inspect image
109+
run: |
110+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)