Skip to content

Commit 6d4a5cd

Browse files
ronenscopenshift-merge-bot[bot]
authored andcommitted
Add build info to logs
1 parent 4366322 commit 6d4a5cd

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ endif
9797
SHELL = /usr/bin/env bash -o pipefail
9898
.SHELLFLAGS = -ec
9999

100+
BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M)
101+
BUILD_TAG_SHA := $(shell git rev-list --abbrev-commit --tags --max-count=1)
102+
BUILD_TAG_NAME := $(shell git describe --abbrev=0 --tags ${BUILD_TAG_SHA} 2>/dev/null || true)
103+
BUILD_SHA := $(shell git rev-parse --short HEAD)
104+
BUILD_VERSION := $(BUILD_TAG_NAME:v%=%)
105+
ifneq ($(BUILD_SHA), $(BUILD_TAG_SHA))
106+
BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA)
107+
endif
108+
ifneq ($(shell git status --porcelain),)
109+
BUILD_VERSION := $(BUILD_VERSION)-dirty
110+
endif
111+
100112
.PHONY: all
101113
all: build
102114

@@ -147,7 +159,7 @@ modules: ## Update Go dependencies.
147159

148160
.PHONY: build
149161
build: modules fmt vet ## Build manager binary.
150-
go build -o bin/manager main.go
162+
go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" -o bin/manager main.go
151163

152164
.PHONY: run
153165
run: modules manifests fmt vet ## Run a controller from your host.

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ import (
5858
)
5959

6060
var (
61-
scheme = runtime.NewScheme()
62-
setupLog = ctrl.Log.WithName("setup")
61+
scheme = runtime.NewScheme()
62+
setupLog = ctrl.Log.WithName("setup")
63+
BuildVersion = "UNKNOWN"
64+
BuildDate = "UNKNOWN"
6365
)
6466

6567
func init() {
@@ -85,6 +87,7 @@ func main() {
8587
zapOptions.BindFlags(flag.CommandLine)
8688

8789
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
90+
setupLog.Info("Build info", "version", BuildVersion, "date", BuildDate)
8891

8992
ctx := ctrl.SetupSignalHandler()
9093

0 commit comments

Comments
 (0)