Skip to content

Commit 027f39e

Browse files
authored
Merge pull request #4771 from ykakarap/builder_args
🌱 Add build arg to override builder image
2 parents 0792a60 + a31425b commit 027f39e

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616

1717
# Build the manager binary
18-
FROM golang:1.16.5 as builder
18+
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
19+
ARG builder_image
20+
FROM ${builder_image} as builder
1921
WORKDIR /workspace
2022

2123
# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ SHELL:=/usr/bin/env bash
2020

2121
.DEFAULT_GOAL:=help
2222

23+
GO_VERSION ?= 1.16.5
24+
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)
25+
2326
# Use GOPROXY environment variable if set
2427
GOPROXY := $(shell go env GOPROXY)
2528
ifeq ($(GOPROXY),)
@@ -372,7 +375,7 @@ modules: ## Runs go mod to ensure modules are up to date.
372375
.PHONY: docker-pull-prerequisites
373376
docker-pull-prerequisites:
374377
docker pull docker.io/docker/dockerfile:1.1-experimental
375-
docker pull docker.io/library/golang:1.16.4
378+
docker pull $(GO_CONTAINER_IMAGE)
376379
docker pull gcr.io/distroless/static:latest
377380

378381
.PHONY: docker-build
@@ -383,19 +386,19 @@ docker-build: docker-pull-prerequisites ## Build the docker images for controlle
383386

384387
.PHONY: docker-build-core
385388
docker-build-core: ## Build the docker image for core controller manager
386-
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
389+
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg ldflags="$(LDFLAGS)" . -t $(CONTROLLER_IMG)-$(ARCH):$(TAG)
387390
$(MAKE) set-manifest-image MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
388391
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
389392

390393
.PHONY: docker-build-kubeadm-bootstrap
391394
docker-build-kubeadm-bootstrap: ## Build the docker image for kubeadm bootstrap controller manager
392-
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./bootstrap/kubeadm --build-arg ldflags="$(LDFLAGS)" . -t $(KUBEADM_BOOTSTRAP_CONTROLLER_IMG)-$(ARCH):$(TAG)
395+
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./bootstrap/kubeadm --build-arg ldflags="$(LDFLAGS)" . -t $(KUBEADM_BOOTSTRAP_CONTROLLER_IMG)-$(ARCH):$(TAG)
393396
$(MAKE) set-manifest-image MANIFEST_IMG=$(KUBEADM_BOOTSTRAP_CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./bootstrap/kubeadm/config/default/manager_image_patch.yaml"
394397
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./bootstrap/kubeadm/config/default/manager_pull_policy.yaml"
395398

396399
.PHONY: docker-build-kubeadm-control-plane
397400
docker-build-kubeadm-control-plane: ## Build the docker image for kubeadm control plane controller manager
398-
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./controlplane/kubeadm --build-arg ldflags="$(LDFLAGS)" . -t $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG)-$(ARCH):$(TAG)
401+
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) --build-arg package=./controlplane/kubeadm --build-arg ldflags="$(LDFLAGS)" . -t $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG)-$(ARCH):$(TAG)
399402
$(MAKE) set-manifest-image MANIFEST_IMG=$(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_image_patch.yaml"
400403
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./controlplane/kubeadm/config/default/manager_pull_policy.yaml"
401404

@@ -541,7 +544,7 @@ release-binary: $(RELEASE_DIR)
541544
-e GOARCH=$(GOARCH) \
542545
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
543546
-w /workspace \
544-
golang:1.16.4 \
547+
golang:$(GOLANG_VERSION) \
545548
go build -a -ldflags "$(LDFLAGS) -extldflags '-static'" \
546549
-o $(RELEASE_DIR)/$(notdir $(RELEASE_BINARY))-$(GOOS)-$(GOARCH) $(RELEASE_BINARY)
547550

test/infrastructure/docker/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
FROM golang:1.16.5 as builder
17+
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
18+
ARG builder_image
19+
FROM ${builder_image} as builder
1820

1921
# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
2022
ARG goproxy=https://proxy.golang.org

test/infrastructure/docker/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ ROOT = ../../..
1919

2020
.DEFAULT_GOAL:=help
2121

22+
GO_VERSION ?= 1.16.5
23+
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)
24+
2225
# Use GOPROXY environment variable if set
2326
GOPROXY := $(shell go env GOPROXY)
2427
ifeq ($(GOPROXY),)
@@ -155,12 +158,12 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
155158
.PHONY: docker-pull-prerequisites
156159
docker-pull-prerequisites:
157160
docker pull docker.io/docker/dockerfile:1.1-experimental
158-
docker pull docker.io/library/golang:1.16.4
161+
docker pull $(GO_CONTAINER_IMAGE)
159162
docker pull gcr.io/distroless/static:latest
160163

161164
.PHONY: docker-build
162165
docker-build: docker-pull-prerequisites ## Build the docker image for controller-manager
163-
DOCKER_BUILDKIT=1 docker build --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) ../../.. -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) --file Dockerfile
166+
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg ARCH=$(ARCH) ../../.. -t $(CONTROLLER_IMG)-$(ARCH):$(TAG) --file Dockerfile
164167
MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
165168
$(MAKE) set-manifest-pull-policy
166169

0 commit comments

Comments
 (0)