11# VERSION defines the project version for the deploy scripts, not for bundles
22VERSION ?= main
3- BUILD_DATE := $(shell date +% Y-% m-% d\ % H:% M)
4- TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
5- TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
6- BUILD_SHA := $(shell git rev-parse --short HEAD)
7- BUILD_VERSION := $(TAG:v%=% )
8- ifneq ($(COMMIT ) , $(TAG_COMMIT ) )
9- BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA)
10- endif
11- ifneq ($(shell git status --porcelain) ,)
12- BUILD_VERSION := $(BUILD_VERSION)-dirty
13- endif
143
154# Go architecture and targets images to build
165GOARCH ?= amd64
@@ -87,7 +76,6 @@ BUNDLE_CONFIG ?= config/openshift-olm
8776
8877# Image URL to use all building/pushing image targets
8978IMAGE ?= $(IMAGE_TAG_BASE ) :$(VERSION )
90- OCI_BUILD_OPTS ?=
9179# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
9280ENVTEST_K8S_VERSION = 1.23
9381GOLANGCI_LINT_VERSION = v1.53.3
@@ -102,6 +90,13 @@ endif
10290# Image building tool (docker / podman) - docker is preferred in CI
10391OCI_BIN_PATH := $(shell which docker 2>/dev/null || which podman)
10492OCI_BIN ?= $(shell basename ${OCI_BIN_PATH})
93+ OCI_BUILD_OPTS ?=
94+
95+ ifneq ($(CLEAN_BUILD ) ,)
96+ BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M)
97+ BUILD_SHA := $(shell git rev-parse --short HEAD)
98+ LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}'
99+ endif
105100
106101DATE =$(shell date -u +"% Y-% m-% dT% H:% M:% SZ")
107102
@@ -127,7 +122,7 @@ include .bingo/Variables.mk
127122# build a single arch target provided as argument
128123define build_target
129124 echo 'building image for arch $(1 ) '; \
130- DOCKER_BUILDKIT=1 $(OCI_BIN ) buildx build --load --build-arg TARGETARCH=$(1 ) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1 ) -f Dockerfile .;
125+ DOCKER_BUILDKIT=1 $(OCI_BIN ) buildx build --load --build-arg LDFLAGS="${LDFLAGS}" --build-arg TARGETARCH=$(1 ) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1 ) -f Dockerfile .;
131126endef
132127
133128# push a single arch target image
@@ -336,7 +331,7 @@ coverage-report-html: ## Generate HTML coverage report
336331 go tool cover --html=./cover.out
337332
338333build : fmt lint # # Build manager binary.
339- GOARCH=${GOARCH} go build -ldflags " -X 'main.buildVersion= ${BUILD_VERSION} ' -X 'main.buildDate= ${BUILD_DATE} ' " - mod vendor -o bin/manager main.go
334+ GOARCH=${GOARCH} go build -mod vendor -o bin/manager main.go
340335
341336# #@ Images
342337
0 commit comments