From 04ddeeb37099467d0d608ea263cb61a3302c5eed Mon Sep 17 00:00:00 2001 From: haijianyang Date: Wed, 27 Sep 2023 02:58:51 -0400 Subject: [PATCH] Fix arm image build error --- Dockerfile | 10 ++++++++-- Makefile | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6923bb52..a80948f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1.4 + # Copyright 2022. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Build architecture +ARG ARCH + # Build the manager binary FROM golang:1.20.7 as builder WORKDIR /workspace @@ -31,14 +36,15 @@ RUN go mod download COPY ./ ./ # Build -ARG ARCH=amd64 +ARG ARCH ARG ldflags + RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \ go build -a -ldflags "${ldflags} -extldflags '-static'" \ -o manager . # Copy the controller-manager into a thin image -FROM gcr.io/distroless/static:nonroot +FROM gcr.io/distroless/static:nonroot-${ARCH} WORKDIR / COPY --from=builder /workspace/manager . # Use uid of nonroot user (65532) because kubernetes expects numeric user when applying PSPs diff --git a/Makefile b/Makefile index 2693b5d9..e1aadf33 100644 --- a/Makefile +++ b/Makefile @@ -296,7 +296,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi .PHONY: docker-build docker-build: docker-pull-prerequisites ## Build the docker image for controller-manager - docker build --platform linux/$(ARCH) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(IMAGE_TAG) + docker build --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(IMAGE_TAG) .PHONY: docker-push docker-push: ## Push the docker image @@ -304,6 +304,7 @@ docker-push: ## Push the docker image .PHONY: docker-pull-prerequisites docker-pull-prerequisites: + docker pull docker.io/docker/dockerfile:1.4 docker pull gcr.io/distroless/static:latest ## --------------------------------------