Skip to content

Commit 72b0def

Browse files
committed
update github workflow to build multi architecture container images
1 parent 32415ca commit 72b0def

File tree

1 file changed

+66
-40
lines changed

1 file changed

+66
-40
lines changed

.github/workflows/docker.yml

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,82 @@
11
name: Docker build and release
22

33
on:
4-
release:
5-
types: [published]
64
push:
7-
branches: [master,develop]
5+
pull_request:
86

97
jobs:
10-
deploy_image:
11-
name: 'Publish: DockerHub'
12-
runs-on: ubuntu-latest
13-
if: github.event_name == 'release' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master'
8+
build:
9+
name: 'Build container image'
10+
runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
11+
outputs:
12+
digest_arm64: ${{ steps.export_digest.outputs.digest_arm64 }}
13+
digest_amd64: ${{ steps.export_digest.outputs.digest_amd64 }}
14+
strategy:
15+
matrix:
16+
platform:
17+
- linux/amd64
18+
- linux/arm64
1419
steps:
15-
- name: Set up QEMU
16-
uses: docker/setup-qemu-action@v1
20+
- uses: actions/checkout@v4
21+
22+
- name: Docker meta
23+
id: meta
24+
uses: docker/metadata-action@v5
25+
with:
26+
images: "ghcr.io/${{ github.repository }}"
27+
28+
- name: Login to GHCR
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.repository_owner }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
1734

1835
- name: Set up Docker Buildx
1936
uses: docker/setup-buildx-action@v1
2037

21-
- name: Extract branch name
22-
shell: bash
23-
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
24-
id: extract_branch
25-
26-
- name: Generating release tags and labels
27-
if: github.event_name == 'release'
28-
id: release_meta
29-
uses: docker/metadata-action@v4
30-
with:
31-
images: jaedb/snapserver
32-
tags: |
33-
latest
34-
type=semver,pattern={{version}}
35-
type=semver,pattern={{major}}.{{minor}}
36-
37-
- name: Generating edge branch labels
38-
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master'
39-
id: edge_meta
40-
uses: docker/metadata-action@v4
38+
- name: Build and push by digest
39+
id: build
40+
uses: docker/build-push-action@v6
4141
with:
42-
images: jaedb/snapserver
43-
tags: ${{ steps.extract_branch.outputs.branch }}
42+
platforms: ${{ matrix.platform }}
43+
labels: ${{ steps.meta.outputs.labels }}
44+
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true
4445

45-
- name: Login to DockerHub
46-
uses: docker/login-action@v1
46+
- name: Export digest
47+
id: export_digest
48+
run: |
49+
arch="$(echo -n ${{ matrix.platform }} | sed -e 's/linux\///')"
50+
digest="${{ steps.build.outputs.digest }}"
51+
echo "digest_${arch}=${digest#sha256:}" >> "$GITHUB_OUTPUT"
52+
53+
merge:
54+
runs-on: "ubuntu-24.04"
55+
needs:
56+
- build
57+
steps:
58+
- name: Docker meta
59+
id: meta
60+
uses: docker/metadata-action@v5
4761
with:
48-
username: ${{ secrets.DOCKERHUB_USERNAME }}
49-
password: ${{ secrets.DOCKERHUB_TOKEN }}
62+
images: ghcr.io/${{ github.repository }}
5063

51-
- name: Build and push
52-
uses: docker/build-push-action@v2
64+
- name: Login to GHCR
65+
uses: docker/login-action@v3
5366
with:
54-
push: true
55-
tags: ${{ steps.release_meta.outputs.tags || steps.edge_meta.outputs.tags }}
56-
labels: ${{ steps.release_meta.outputs.labels || steps.edge_meta.outputs.tags }}
67+
registry: ghcr.io
68+
username: ${{ github.repository_owner }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: Create manifest list and push
75+
run: |
76+
docker buildx imagetools create \
77+
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
78+
${{ env.DOCKERHUB_REPO }}@sha256:${{ needs.build.outputs.digest_arm64 }} \
79+
${{ env.DOCKERHUB_REPO }}@sha256:${{ needs.build.outputs.digest_amd64 }}
80+
81+
- name: Inspect image
82+
run: docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)