Skip to content

Commit 000a6ff

Browse files
committed
Add GOMAXPROCS support when building
Right now when we build the container (make docker-build) or the controller (make build) the go compiler will try to use all the CPUs on the machine. This can become problematic in some systems that may suffer starvation (eg: audio problems), so we add support for the `GOMAXPROCS` env var to be passed to those 2 make targets.
1 parent 088608c commit 000a6ff

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
5+
ARG GOMAXPROCS
56

67
WORKDIR /workspace
78
# Copy the Go Modules manifests
@@ -21,7 +22,7 @@ COPY internal/controller/ internal/controller/
2122
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2223
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2324
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
25+
RUN GOMAXPROCS=${GOMAXPROCS} CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2526

2627
# Use distroless as minimal base image to package the manager binary
2728
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
146146

147147
.PHONY: build
148148
build: manifests generate fmt vet ## Build manager binary.
149-
go build -o bin/manager cmd/main.go
149+
GOMAXPROCS=$(GOMAXPROCS) go build -o bin/manager cmd/main.go
150150

151151
.PHONY: run
152152
run: manifests generate fmt vet ## Run a controller from your host.
@@ -157,7 +157,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
157157
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
158158
.PHONY: docker-build
159159
docker-build: ## Build docker image with the manager.
160-
$(CONTAINER_TOOL) build -t ${IMG} .
160+
$(CONTAINER_TOOL) build --build-arg GOMAXPROCS=$(GOMAXPROCS) -t ${IMG} .
161161

162162
.PHONY: docker-push
163163
docker-push: ## Push docker image with the manager.

0 commit comments

Comments
 (0)