Skip to content

Commit 536adc8

Browse files
simonostendorflentzi90
authored andcommitted
feat: use specified go version for docker build
1 parent eb09788 commit 536adc8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515
# Build the manager binary
16-
FROM golang:1.22.0 as builder
16+
ARG GO_VERSION
17+
FROM golang:${GO_VERSION} AS builder
1718
WORKDIR /workspace
1819

1920
# Run this with docker build --build_arg goproxy=$(go env GOPROXY) to override the goproxy
@@ -30,7 +31,7 @@ COPY orc/go.sum orc/go.sum
3031
# Cache deps before building and copying source so that we don't need to re-download as much
3132
# and so that source changes don't invalidate our downloaded layer
3233
RUN --mount=type=cache,target=/go/pkg/mod \
33-
go mod download
34+
go mod download
3435

3536
# Copy the sources
3637
COPY ./ ./
@@ -42,10 +43,10 @@ ARG ldflags
4243

4344
# Do not force rebuild of up-to-date packages (do not use -a) and use the compiler cache folder
4445
RUN --mount=type=cache,target=/root/.cache/go-build \
45-
--mount=type=cache,target=/go/pkg/mod \
46-
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
47-
go build -ldflags "${ldflags} -extldflags '-static'" \
48-
-o manager ${package}
46+
--mount=type=cache,target=/go/pkg/mod \
47+
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
48+
go build -ldflags "${ldflags} -extldflags '-static'" \
49+
-o manager ${package}
4950

5051
# Production image
5152
FROM gcr.io/distroless/static:nonroot

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ generate-api-docs-%: $(GEN_CRD_API_REFERENCE_DOCS) FORCE
359359

360360
.PHONY: docker-build
361361
docker-build: ## Build the docker image for controller-manager
362-
docker build -f Dockerfile --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG_TAG)
362+
docker build -f Dockerfile --build-arg GO_VERSION=$(GO_VERSION) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG_TAG)
363363

364364
.PHONY: docker-push
365365
docker-push: ## Push the docker image

0 commit comments

Comments
 (0)