Skip to content

Commit 63c7d8a

Browse files
committed
Make Docker image multiarch
1 parent 6c9e272 commit 63c7d8a

1 file changed

Lines changed: 83 additions & 4 deletions

File tree

.github/workflows/build-docker.yml

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ concurrency:
1212
group: docker
1313
cancel-in-progress: true
1414

15+
env:
16+
REGISTRY_IMAGE: ghcr.io/ogcincubator/bblocks-viewer
17+
1518
jobs:
16-
docker:
19+
build:
1720
runs-on: ubuntu-latest
1821
permissions:
1922
contents: read
2023
packages: write
2124

25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
platform:
29+
- linux/amd64
30+
- linux/arm64
31+
2232
steps:
33+
- name: Prepare
34+
run: |
35+
platform=${{ matrix.platform }}
36+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
37+
2338
- name: Checkout repository
24-
uses: actions/checkout@v4
39+
uses: actions/checkout@v5
2540

2641
- name: Log in to the Container registry
2742
if: github.event_name != 'pull_request'
@@ -35,16 +50,80 @@ jobs:
3550
id: meta
3651
uses: docker/metadata-action@v5
3752
with:
38-
images: ghcr.io/ogcincubator/bblocks-viewer
53+
images: ${{ env.REGISTRY_IMAGE }}
3954
tags: |
4055
type=raw,value=latest,enable={{is_default_branch}}
4156
type=ref,event=branch
4257
type=ref,event=tag
4358
59+
- name: Set up QEMU
60+
uses: docker/setup-qemu-action@v3
61+
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
4465
- name: Build and push Docker image
45-
uses: docker/build-push-action@v5
66+
uses: docker/build-push-action@v6
4667
with:
68+
platforms: ${{ matrix.platform }}
4769
context: .
4870
push: ${{ github.event_name != 'pull_request' }}
4971
tags: ${{ steps.meta.outputs.tags }}
5072
labels: ${{ steps.meta.outputs.labels }}
73+
cache-from: type=gha,scope=image-${{ matrix.platform }}
74+
cache-to: type=gha,mode=max,scope=image-${{ matrix.platform }}
75+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
76+
77+
- name: Export digest
78+
run: |
79+
mkdir -p /tmp/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "/tmp/digests/${digest#sha256:}"
82+
83+
- name: Upload digest
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: digests-${{ env.PLATFORM_PAIR }}
87+
path: /tmp/digests/*
88+
if-no-files-found: error
89+
retention-days: 1
90+
91+
merge:
92+
runs-on: ubuntu-latest
93+
needs:
94+
- build
95+
steps:
96+
- name: Download digests
97+
uses: actions/download-artifact@v4
98+
with:
99+
path: /tmp/digests
100+
pattern: digests-*
101+
merge-multiple: true
102+
103+
- name: Set up Docker Buildx
104+
uses: docker/setup-buildx-action@v3
105+
106+
- name: Docker meta
107+
id: meta
108+
uses: docker/metadata-action@v5
109+
with:
110+
images: ${{ env.REGISTRY_IMAGE }}
111+
112+
- name: Log in to the Container registry
113+
if: github.event_name != 'pull_request'
114+
uses: docker/login-action@v3
115+
with:
116+
registry: ghcr.io
117+
username: ${{ github.actor }}
118+
password: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Create manifest list and push
121+
working-directory: /tmp/digests
122+
if: ${{ github.event_name != 'pull_request' }}
123+
run: |
124+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
125+
-t ${{ env.REGISTRY_IMAGE }}:latest $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
126+
127+
- name: Inspect image
128+
run: |
129+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)