Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arm image build error #148

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个和18行加的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