Skip to content

Commit 75c6e25

Browse files
authored
Build an arm64 container image (max-rocket-internet#11)
* Build an arm64 container image * Let the container image build be further customized * Add a README section on image builds
1 parent eeab653 commit 75c6e25

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM golang:1.18.3 as builder
1+
FROM --platform=${BUILDPLATFORM} golang:1.18.3 as builder
2+
ARG TARGETARCH
3+
ARG TARGETOS
24
WORKDIR /go/src/github.com/max-rocket-internet/k8s-event-logger
35
COPY . .
46
RUN go get
5-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o k8s-event-logger
7+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o k8s-event-logger
68
RUN adduser --disabled-login --no-create-home --disabled-password --system --uid 101 non-root
79

8-
FROM alpine:3.15.4
10+
FROM --platform=${TARGETPLATFORM} alpine:3.15.4
911
RUN addgroup -S non-root && adduser -S -G non-root non-root
1012
USER 101
1113
ENV USER non-root

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
IMG ?= maxrocketinternet/k8s-event-logger
2+
TAG ?= 1.6
3+
PLATFORMS ?= linux/amd64,linux/arm64
4+
5+
.PHONY: image
6+
7+
image:
8+
docker buildx build --platform $(PLATFORMS) --push -t $(IMG):$(TAG) .

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,22 @@ Use the [Helm](https://helm.sh/) chart:
3838
helm install chart/
3939
```
4040

41-
Or user the docker image [maxrocketinternet/k8s-event-logger](https://hub.docker.com/r/maxrocketinternet/k8s-event-logger)
41+
Or use the docker image [maxrocketinternet/k8s-event-logger][image]
42+
43+
[image]: https://hub.docker.com/r/maxrocketinternet/k8s-event-logger
44+
45+
#### Building a container image
46+
47+
If you're unable to use the [prebuilt][image] docker image, you can build it yourself:
48+
49+
```sh
50+
make IMG=your.docker.registry/k8s-event-logger image
51+
```
52+
53+
This uses `docker buildx` to create a [multi-platform image][]. To set up your build host system to be able to build these images, see [this guide][qemu-binfmt].
54+
55+
[multi-platform image]: https://docs.docker.com/build/building/multi-platform/
56+
[qemu-binfmt]: https://docs.nvidia.com/datacenter/cloud-native/playground/x-arch.html
4257

4358
### Testing
4459

0 commit comments

Comments
 (0)