Skip to content

Commit 6e962fb

Browse files
Add multi-arch Docker build for amd64 & arm64
Switch CI to Docker Buildx with QEMU to build and push a single manifest targeting linux/amd64 and linux/arm64. Provide a Makefile target to build multiarch images in non CI contexts. Closes mikkeloscar#67 Signed-off-by: Nestor Manrique <n.manriquecruz@celonis.com>
1 parent 06bc039 commit 6e962fb

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,42 @@ jobs:
1919
make test
2020
make
2121
make build.docker
22+
- run: |
23+
make test
24+
make build.linux.amd64
25+
make build.linux.arm64
2226
- run: goveralls -coverprofile=profile.cov -service=github
2327
env:
2428
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
- name: Push the latest Docker image
26-
run: |
27-
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
28-
VERSION=latest make build.push
29+
- name: Set up QEMU for multi-arch
30+
uses: docker/setup-qemu-action@v2
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Log in to DockerHub
36+
uses: docker/login-action@v2
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
40+
41+
- name: Build & push multi-arch image (latest)
2942
if: github.ref == 'refs/heads/master'
30-
- name: Push the release Docker image
31-
run: |
32-
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
33-
VERSION=${{ github.ref_name }} make build.push
43+
uses: docker/build-push-action@v3
44+
with:
45+
context: .
46+
file: Dockerfile
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
tags: mikkeloscar/pdb-controller:latest
50+
51+
- name: Build & push multi-arch image (release)
3452
if: startsWith(github.ref, 'refs/tags/')
53+
uses: docker/build-push-action@v3
54+
with:
55+
context: .
56+
file: Dockerfile
57+
platforms: linux/amd64,linux/arm64
58+
push: true
59+
tags: |
60+
mikkeloscar/pdb-controller:${{ github.ref_name }}

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,13 @@ build/osx/$(BINARY): $(SOURCES)
4848
build.docker: build.linux
4949
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) --build-arg TARGETARCH= .
5050

51+
build.docker.multi: build/linux/amd64 build/linux/arm64
52+
docker buildx build \
53+
--platform linux/amd64,linux/arm64 \
54+
--build-arg TARGETARCH=${TARGETARCH} \
55+
--push \
56+
-t "$(IMAGE):$(TAG)" \
57+
-f $(DOCKERFILE) .
58+
5159
build.push: build.docker
5260
docker push "$(IMAGE):$(TAG)"

0 commit comments

Comments
 (0)