Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
add build version information logging
Browse files Browse the repository at this point in the history
This adds build version information to the binary and logs it.

Signed-off-by: Ukri Niemimuukko <[email protected]>
  • Loading branch information
uniemimu authored and madalazar committed Jan 3, 2023
1 parent 3973ef8 commit f03e9b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
14 changes: 13 additions & 1 deletion gpu-aware-scheduling/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ IMAGE_TAG=:$(TAG)
endif

GOLICENSES_VERSION?=v1.5.0
BUILD_OUTPUT_DIR?=./bin

ifneq ("$(wildcard licenses/)","")
LOCAL_LICENSES=TRUE
endif

GOVERSION=$(shell go version | sed 's/^[^0-9]*//' | cut -d' ' -f1)
BUILDDATE=$(shell date "+%Y%m%d-%T")
VERSION=$(shell git describe --tags --long --match gpu-aware-scheduling/v*)

LDFLAGS = \
-s -w \
-X main.version=$(VERSION) \
-X main.buildDate=$(BUILDDATE) \
-X main.goVersion=$(GOVERSION)


.PHONY: test all build image release-image format clean licenses mock e2e lint

test:
Expand All @@ -19,7 +31,7 @@ lint: format build
golangci-lint run

build:
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o ./bin/extender ./cmd/gas-scheduler-extender
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="$(LDFLAGS)" -o $(BUILD_OUTPUT_DIR)/extender ./cmd/gas-scheduler-extender

#note: you can speed up subsequent docker builds by doing "go mod vendor"
#note: you can further speed up subsequent docker builds by doing "make licenses"
Expand Down
15 changes: 15 additions & 0 deletions gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ import (
"k8s.io/klog/v2"
)

// build variables need to be globals
//
//nolint:gochecknoglobals
var (
goVersion = "value is set during build"
buildDate = "value is set during build"
version = "value is set during build"
)

const (
l1 = klog.Level(1)
)

func main() {
var (
kubeConfig, port, certFile, keyFile, caFile, balancedRes string
Expand All @@ -29,6 +42,8 @@ func main() {
klog.InitFlags(nil)
flag.Parse()

klog.V(l1).Infof("%s built on %s with go %s", version, buildDate, goVersion)

kubeClient, _, err := extender.GetKubeClient(kubeConfig)
if err != nil {
klog.Error("couldn't get kube client, cannot continue: ", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG LOCAL_LICENSES
COPY . /src_root
WORKDIR /src_root/gpu-aware-scheduling
RUN mkdir -p /install_root/etc && adduser --disabled-password --quiet --gecos "" -u 10001 gas && tail -1 /etc/passwd > /install_root/etc/passwd \
&& CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o /install_root/extender ./cmd/gas-scheduler-extender \
&& BUILD_OUTPUT_DIR=/install_root make build \
&& if [ -z "$LOCAL_LICENSES" ] ; then \
GO111MODULE=on go run github.com/google/go-licenses@${GOLICENSES_VERSION} save "./cmd/gas-scheduler-extender" --save_path /install_root/licenses ; \
else cp -r licenses /install_root/ ; fi
Expand Down

0 comments on commit f03e9b0

Please sign in to comment.