Skip to content

Commit 9babb62

Browse files
flexxxxerflexxxxer
and
flexxxxer
authored
add support for arm64 docker builds using Buildx+QEMU (#152)
Co-authored-by: flexxxxer <bahx4pc@gmail.com>
1 parent 455b9c1 commit 9babb62

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.github/workflows/docker-image.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,31 @@ jobs:
2222
steps:
2323
- name: Checkout repository
2424
uses: actions/checkout@v4
25+
- name: Set up QEMU
26+
uses: docker/setup-qemu-action@v3
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
2529
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
2630
- name: Log in to the Container registry
27-
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
31+
uses: docker/login-action@v3
2832
with:
2933
registry: ${{ env.REGISTRY }}
3034
username: ${{ github.actor }}
3135
password: ${{ secrets.GITHUB_TOKEN }}
3236
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
3337
- name: Extract metadata (tags, labels) for Docker
3438
id: meta
35-
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
39+
uses: docker/metadata-action@v5
3640
with:
3741
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3842
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
3943
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
4044
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
4145
- name: Build and push Docker image
42-
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
46+
uses: docker/build-push-action@v6
4347
with:
4448
context: .
4549
push: true
50+
platforms: linux/amd64,linux/arm64
4651
tags: ${{ steps.meta.outputs.tags }}
47-
labels: ${{ steps.meta.outputs.labels }}
52+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.22.1-alpine3.19 as build
1+
FROM golang:1.22.1-alpine3.19 AS build
22

33
WORKDIR /app
44

@@ -9,7 +9,10 @@ RUN go mod download
99

1010
COPY . .
1111

12-
ENV CGO_ENABLED=0
12+
# Architecture and OS are set dynamically (by BuildKit)
13+
ARG TARGETOS
14+
ARG TARGETARCH
15+
ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH
1316

1417
RUN go build -o anonymousoverflow && go build -o healthcheck ./src/healthcheck
1518

0 commit comments

Comments
 (0)