Skip to content

Commit

Permalink
Fix arm image build error (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang authored Sep 27, 2023
1 parent 8c50eb9 commit d5f7227
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1.4

# Copyright 2022.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,15 @@ 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
docker push $(CONTROLLER_IMG)-$(ARCH):$(IMAGE_TAG)

.PHONY: docker-pull-prerequisites
docker-pull-prerequisites:
docker pull docker.io/docker/dockerfile:1.4
docker pull gcr.io/distroless/static:latest

## --------------------------------------
Expand Down

0 comments on commit d5f7227

Please sign in to comment.