Skip to content

Commit

Permalink
dockerfile: builder image configurable through a Makefile variable.
Browse files Browse the repository at this point in the history
Switch over to the "non-point-release" version of the image. Now we
always use the latest patch version of golang with latest security
fixes, for example, without the need to manually bump the version after
every point release.

This patch also makes the builder image configurable through a Makefile
variable pointing to the go.mod go version, that way the go.mod file
becomes the source of truth for the go version.
  • Loading branch information
ArangoGutierrez committed Jan 17, 2023
1 parent 080350a commit 665f699
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ARG BUILDER_IMAGE
ARG BASE_IMAGE_FULL
ARG BASE_IMAGE_MINIMAL
# Build the manager biinary
FROM golang:1.19.5-buster as builder
FROM ${BUILDER_IMAGE} as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

GO_CMD ?= go
GO_FMT ?= gofmt
GO_VERSION := $(shell awk '/go /{print $$2}' go.mod|grep -v v)
CONTAINER_RUN_CMD ?= docker run -u "`id -u`:`id -g`"

# Docker base command for working with html documentation.
Expand Down Expand Up @@ -62,6 +63,7 @@ IMAGE_EXTRA_TAG_NAMES ?=
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG ?= $(IMAGE_REPO):$(IMAGE_TAG_NAME)
IMAGE_EXTRA_TAGS := $(foreach tag,$(IMAGE_EXTRA_TAG_NAMES),$(IMAGE_REPO):$(tag))
BUILDER_IMAGE ?= golang:$(GO_VERSION)-buster
BASE_IMAGE_FULL ?= debian:buster-slim
BASE_IMAGE_MINIMAL ?= gcr.io/distroless/base

Expand Down Expand Up @@ -173,6 +175,7 @@ generate: controller-gen
image:
$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
--target full \
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
--build-arg BASE_IMAGE_FULL=$(BASE_IMAGE_FULL) \
--build-arg BASE_IMAGE_MINIMAL=$(BASE_IMAGE_MINIMAL) \
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)) \
Expand Down

0 comments on commit 665f699

Please sign in to comment.