From 53dcd7617703f3372ffbb730e14e8ec6a769bfaa Mon Sep 17 00:00:00 2001 From: Lyra Naeseth Date: Thu, 8 Sep 2022 15:39:47 -0700 Subject: [PATCH 1/3] Build an arm64 container image --- Dockerfile | 8 +++++--- Makefile | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile index 5d795c9..db49725 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ -FROM golang:1.18.3 as builder +FROM --platform=${BUILDPLATFORM} golang:1.18.3 as builder +ARG TARGETARCH +ARG TARGETOS WORKDIR /go/src/github.com/max-rocket-internet/k8s-event-logger COPY . . RUN go get -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o k8s-event-logger +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o k8s-event-logger RUN adduser --disabled-login --no-create-home --disabled-password --system --uid 101 non-root -FROM alpine:3.15.4 +FROM --platform=${TARGETPLATFORM} alpine:3.15.4 RUN addgroup -S non-root && adduser -S -G non-root non-root USER 101 ENV USER non-root diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..90aab4f --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +VERSION ?= 1.6.1 +IMG ?= maxrocketinternet/k8s-event-logger:$(VERSION) + +.PHONY: image + +image: + docker buildx build --platform linux/amd64,linux/arm64 --push -t $(IMG) . From e64af6983d5f0054606a93d399648ec275330734 Mon Sep 17 00:00:00 2001 From: Lyra Naeseth Date: Thu, 15 Sep 2022 12:47:53 -0700 Subject: [PATCH 2/3] Let the container image build be further customized --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 90aab4f..4beb41c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ -VERSION ?= 1.6.1 -IMG ?= maxrocketinternet/k8s-event-logger:$(VERSION) +IMG ?= maxrocketinternet/k8s-event-logger +TAG ?= 1.6 +PLATFORMS ?= linux/amd64,linux/arm64 .PHONY: image image: - docker buildx build --platform linux/amd64,linux/arm64 --push -t $(IMG) . + docker buildx build --platform $(PLATFORMS) --push -t $(IMG):$(TAG) . From 5af0b1b328d886a1fe2c3c2b101136b0249a44dd Mon Sep 17 00:00:00 2001 From: Lyra Naeseth Date: Thu, 15 Sep 2022 12:48:06 -0700 Subject: [PATCH 3/3] Add a README section on image builds --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80d8ed5..90fe37c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,22 @@ Use the [Helm](https://helm.sh/) chart: helm install chart/ ``` -Or user the docker image [maxrocketinternet/k8s-event-logger](https://hub.docker.com/r/maxrocketinternet/k8s-event-logger) +Or use the docker image [maxrocketinternet/k8s-event-logger][image] + +[image]: https://hub.docker.com/r/maxrocketinternet/k8s-event-logger + +#### Building a container image + +If you're unable to use the [prebuilt][image] docker image, you can build it yourself: + +```sh +make IMG=your.docker.registry/k8s-event-logger image +``` + +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]. + +[multi-platform image]: https://docs.docker.com/build/building/multi-platform/ +[qemu-binfmt]: https://docs.nvidia.com/datacenter/cloud-native/playground/x-arch.html ### Testing