Skip to content

Commit

Permalink
Log version and git_commit info
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Desiniotis <[email protected]>
  • Loading branch information
cdesiniotis committed Mar 13, 2024
1 parent 43cb12e commit a2e9233
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DOCKER_TARGETS := $(patsubst %, docker-%, $(TARGETS))
.PHONY: $(TARGETS) $(DOCKER_TARGETS)

GOOS := linux
VERSION_PKG=$(MODULE)/internal/info

ifneq ($(PREFIX),)
cmd-%: COMMAND_BUILD_OPTIONS = -o $(PREFIX)/$(*)
Expand Down
6 changes: 6 additions & 0 deletions cmd/nvidia-k8s-vgpu-dm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/NVIDIA/vgpu-device-manager/internal/info"
)

const (
Expand Down Expand Up @@ -102,8 +104,10 @@ func (m *SyncableVGPUConfig) Get() string {

func main() {
c := cli.NewApp()
c.Name = "nvidia-k8s-vgpu-dm"
c.Before = validateFlags
c.Action = start
c.Version = info.GetVersionString()

c.Flags = []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -147,6 +151,8 @@ func main() {
},
}

log.Infof("version: %s", c.Version)

err := c.Run(os.Args)
if err != nil {
log.SetOutput(os.Stderr)
Expand Down
5 changes: 4 additions & 1 deletion cmd/nvidia-vgpu-dm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/NVIDIA/vgpu-device-manager/cmd/nvidia-vgpu-dm/apply"
"github.com/NVIDIA/vgpu-device-manager/cmd/nvidia-vgpu-dm/assert"
"github.com/NVIDIA/vgpu-device-manager/internal/info"
)

// Flags represents the top level flags that can be passed to the vgpu-dm CLI
Expand All @@ -37,7 +38,7 @@ func main() {
c := cli.NewApp()
c.Name = "nvidia-vgpu-dm"
c.Usage = "Manage NVIDIA vGPU devices"
c.Version = "0.2.0"
c.Version = info.GetVersionString()

c.Flags = []cli.Flag{
&cli.BoolFlag{
Expand Down Expand Up @@ -66,6 +67,8 @@ func main() {
return nil
}

log.Infof("version: %s", c.Version)

err := c.Run(os.Args)
if err != nil {
log.Fatalf(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions deployments/container/Dockerfile.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

ARG BASE_DIST=ubi8
ARG CUDA_VERSION
ARG GOLANG_VERSION=x.x.x
ARG VERSION="N/A"

FROM nvcr.io/nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST} as build

Expand All @@ -39,6 +37,8 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

WORKDIR /build
COPY . .
ARG VERSION="N/A"
ARG GIT_COMMIT="unknown"
RUN make PREFIX=/artifacts cmds


Expand Down
1 change: 1 addition & 0 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $(BUILD_TARGETS): build-%:
--build-arg CUDA_VERSION="$(CUDA_VERSION)" \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg VERSION="$(VERSION)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
--build-arg CVE_UPDATES="$(CVE_UPDATES)" \
--file $(DOCKERFILE) \
$(CURDIR)
43 changes: 43 additions & 0 deletions internal/info/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/

package info

import "strings"

// version must be set by go build's -X main.version= option in the Makefile.
var version = "unknown"

// gitCommit will be the hash that the binary was built from
// and will be populated by the Makefile
var gitCommit = ""

// GetVersionParts returns the different version components
func GetVersionParts() []string {
v := []string{version}

if gitCommit != "" {
v = append(v, "commit: "+gitCommit)
}

return v
}

// GetVersionString returns the string representation of the version
func GetVersionString(more ...string) string {
v := append(GetVersionParts(), more...)
return strings.Join(v, ", ")
}
2 changes: 2 additions & 0 deletions versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ vVERSION := v$(VERSION:v%=%)
CUDA_VERSION := 12.3.2

GOLANG_VERSION := 1.21.8

GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "")

0 comments on commit a2e9233

Please sign in to comment.