Skip to content

Commit 91da656

Browse files
authored
Add qemu for arm (#24)
* Add qemu for arm * Try to split to multiple runners * Fix name * correct plaform * Don't tag on push by digest * Try login and push * Add tag * try tag with just repo name * Lowercase tag * login * Add in the manifest * Try to simplify * Lowercase image name * Fix lowercase * Restore only running on tag * More tag checks
1 parent da8f31a commit 91da656

File tree

1 file changed

+96
-30
lines changed

1 file changed

+96
-30
lines changed

.github/workflows/ci.yml

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Written using
2+
# https://docs.docker.com/build/ci/github-actions/multi-platform/
3+
# and
4+
# https://github.com/sredevopsorg/multi-arch-docker-github-workflow/blob/main/.github/workflows/multi-build.yaml
15
name: CI
26

37
on:
@@ -8,62 +12,124 @@ on:
812
- '*'
913
pull_request:
1014

15+
env:
16+
# The name of the Docker image to be built and pushed to GHCR
17+
# The image name is derived from the GitHub repository name and the GitHub Container Registry (GHCR) URL.
18+
# The image name will be in the format: ghcr.io/<owner>/<repo>
19+
GHCR_IMAGE: ghcr.io/${{ github.repository }}
20+
1121
jobs:
1222

13-
build_container:
14-
runs-on: ubuntu-latest
23+
build:
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
include:
29+
- arch: amd64
30+
runner: ubuntu-latest
31+
- arch: arm64
32+
runner: ubuntu-24.04-arm
33+
runs-on: ${{ matrix.runner }}
1534

1635
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v6
19-
with:
20-
# Need this to get version number from last tag
21-
fetch-depth: 0
36+
- name: Lowercase the image name
37+
run: echo "GHCR_IMAGE=${GHCR_IMAGE,,}" >> $GITHUB_ENV
2238

2339
- name: Set up Docker Buildx
24-
id: buildx
2540
uses: docker/setup-buildx-action@v3
2641

27-
- name: Log in to GitHub Docker Registry
28-
if: github.event_name != 'pull_request'
29-
uses: docker/login-action@v3
42+
- name: Extract metadata for publishing image
43+
id: meta
44+
uses: docker/metadata-action@v5
3045
with:
31-
registry: ghcr.io
32-
username: ${{ github.actor }}
33-
password: ${{ secrets.GITHUB_TOKEN }}
46+
images: ${{ env.GHCR_IMAGE }}
3447

3548
- name: Build and export to Docker local cache
3649
uses: docker/build-push-action@v6
37-
env:
38-
DOCKER_BUILD_RECORD_UPLOAD: false
3950
with:
40-
context: .
4151
# Need load and tags so we can test it below
4252
load: true
4353
tags: tag_for_testing
4454

4555
- name: Test cli works in cached runtime image
4656
run: docker run --rm tag_for_testing uvx pycowsay 'hello ubuntu-devcontainer!'
4757

58+
- name: Log in to GitHub Docker Registry
59+
if: github.ref_type == 'tag'
60+
uses: docker/login-action@v3
61+
with:
62+
registry: ghcr.io
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
66+
- name: Build and push by digest
67+
if: github.ref_type == 'tag'
68+
id: build
69+
uses: docker/build-push-action@v6
70+
with:
71+
labels: ${{ steps.meta.outputs.labels }}
72+
annotations: ${{ steps.meta.outputs.annotations }}
73+
outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true
74+
75+
- name: Export digest
76+
if: github.ref_type == 'tag'
77+
run: |
78+
mkdir -p ${{ runner.temp }}/digests
79+
digest="${{ steps.build.outputs.digest }}"
80+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
81+
82+
- name: Upload digest
83+
if: github.ref_type == 'tag'
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: digests-linux-${{ matrix.arch }}
87+
path: ${{ runner.temp }}/digests/*
88+
if-no-files-found: error
89+
90+
merge:
91+
runs-on: ubuntu-latest
92+
needs:
93+
- build
94+
if: github.ref_type == 'tag'
95+
96+
steps:
97+
- name: Lowercase the image name
98+
run: echo "GHCR_IMAGE=${GHCR_IMAGE,,}" >> $GITHUB_ENV
99+
100+
- name: Download digests
101+
uses: actions/download-artifact@v4
102+
with:
103+
path: ${{ runner.temp }}/digests
104+
pattern: digests-*
105+
merge-multiple: true
106+
107+
- name: Set up Docker Buildx
108+
uses: docker/setup-buildx-action@v3
109+
48110
- name: Create tags for publishing image
49111
id: meta
50112
uses: docker/metadata-action@v5
51113
with:
52-
images: ghcr.io/${{ github.repository }}
114+
images: ${{ env.GHCR_IMAGE }}
53115
tags: |
54116
type=ref,event=tag
55117
type=raw,value=latest
56118
type=raw,value=noble
57-
58-
- name: Push cached image to container registry
59-
if: github.ref_type == 'tag'
60-
uses: docker/build-push-action@v6
61-
env:
62-
DOCKER_BUILD_RECORD_UPLOAD: false
63-
# This does not build the image again, it will find the image in the
64-
# Docker cache and publish it
119+
120+
- name: Log in to GitHub Docker Registry
121+
uses: docker/login-action@v3
65122
with:
66-
context: .
67-
push: true
68-
tags: ${{ steps.meta.outputs.tags }}
69-
labels: ${{ steps.meta.outputs.labels }}
123+
registry: ghcr.io
124+
username: ${{ github.actor }}
125+
password: ${{ secrets.GITHUB_TOKEN }}
126+
127+
- name: Create manifest list and push
128+
working-directory: ${{ runner.temp }}/digests
129+
run: |
130+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
131+
$(printf '${{ env.GHCR_IMAGE }}@sha256:%s ' *)
132+
133+
- name: Inspect image
134+
run: |
135+
docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)