Skip to content

Commit

Permalink
Merge branch 'set-version-in-make' into 'main'
Browse files Browse the repository at this point in the history
Set version and git commit from version.mk

See merge request nvidia/cloud-native/mig-parted!129
  • Loading branch information
Evan Lezar committed Oct 24, 2023
2 parents ac214fa + 06a66e5 commit de6e6ae
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

MODULE := github.com/NVIDIA/mig-parted

DOCKER ?= docker

include $(CURDIR)/versions.mk
Expand Down Expand Up @@ -44,14 +42,20 @@ DOCKER_TARGETS := $(patsubst %, docker-%, $(TARGETS))
.PHONY: $(TARGETS) $(DOCKER_TARGETS)

GOOS := linux
ifeq ($(VERSION),)
CLI_VERSION = $(LIB_VERSION)$(if $(LIB_TAG),-$(LIB_TAG))
else
CLI_VERSION = $(VERSION)
endif
CLI_VERSION_PACKAGE = $(MODULE)/internal/info

binaries: cmds
ifneq ($(PREFIX),)
cmd-%: COMMAND_BUILD_OPTIONS = -o $(PREFIX)/$(*)
endif
cmds: $(CMD_TARGETS)
$(CMD_TARGETS): cmd-%:
GOOS=$(GOOS) go build -ldflags "-s -w" $(COMMAND_BUILD_OPTIONS) $(MODULE)/cmd/$(*)
GOOS=$(GOOS) go build -ldflags "-extldflags=-Wl,-z,lazy -s -w -X $(CLI_VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) -X $(CLI_VERSION_PACKAGE).version=$(CLI_VERSION)" $(COMMAND_BUILD_OPTIONS) $(MODULE)/cmd/$(*)

build:
GOOS=$(GOOS) go build $(MODULE)/...
Expand Down Expand Up @@ -129,8 +133,8 @@ $(DOCKER_TARGETS): docker-%: .build-image
$(DOCKER) run \
--rm \
-e GOCACHE=/tmp/.cache \
-v $(PWD):$(PWD) \
-w $(PWD) \
-v $(PWD):/work \
-w /work \
--user $$(id -u):$$(id -g) \
$(BUILDIMAGE) \
make $(*)
Expand All @@ -142,8 +146,8 @@ PHONY: .shell
--rm \
-ti \
-e GOCACHE=/tmp/.cache \
-v $(PWD):$(PWD) \
-w $(PWD) \
-v $(PWD):/work \
-w /work \
--user $$(id -u):$$(id -g) \
$(BUILDIMAGE)

Expand Down
3 changes: 2 additions & 1 deletion cmd/nvidia-mig-parted/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/export"
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/restore"
"github.com/NVIDIA/mig-parted/cmd/nvidia-mig-parted/util"
"github.com/NVIDIA/mig-parted/internal/info"
log "github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
)
Expand All @@ -43,7 +44,7 @@ func main() {
c.UseShortOptionHandling = true
c.EnableBashCompletion = true
c.Usage = "Manage MIG partitions across the full set of NVIDIA GPUs on a node"
c.Version = "0.5.5"
c.Version = info.GetVersionString()

// Setup the flags for this command
c.Flags = []cli.Flag{
Expand Down
1 change: 1 addition & 0 deletions deployments/gpu-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ $(BUILD_TARGETS): build-%: $(ARTIFACTS_ROOT)
--build-arg CUDA_VERSION="$(CUDA_VERSION)" \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg VERSION="$(vVERSION)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
--build-arg NVIDIA_CTK_VERSION=$(NVIDIA_CTK_VERSION) \
--build-arg CVE_UPDATES="$(CVE_UPDATES)" \
-f $(DOCKERFILE) \
Expand Down
2 changes: 2 additions & 0 deletions deployments/gpu-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"sync"

"github.com/NVIDIA/mig-parted/internal/info"
log "github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"

Expand Down Expand Up @@ -109,6 +110,7 @@ func main() {
c := cli.NewApp()
c.Before = validateFlags
c.Action = start
c.Version = info.GetVersionString()

c.Flags = []cli.Flag{
&cli.StringFlag{
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ RUN go install golang.org/x/lint/golint@6edffad5e6160f5949cdefc81710b2706fbcd4f6
RUN go install github.com/matryer/moq@latest
RUN go install github.com/gordonklaus/ineffassign@d2c82e48359b033cde9cf1307f6d5550b8d61321
RUN go install github.com/client9/misspell/cmd/misspell@latest

# We need to set the /work directory as a safe directory.
# This allows git commands to run in the container.
RUN git config --file=/.gitconfig --add safe.directory /work
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) 2022, 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, "\n")
}
5 changes: 4 additions & 1 deletion versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION ?= 0.5.5
MODULE := github.com/NVIDIA/mig-parted
VERSION ?= v0.5.5

vVERSION := v$(VERSION:v%=%)

CUDA_VERSION := 12.2.2
GOLANG_VERSION := 1.20.1

NVIDIA_CTK_VERSION := v1.13.4

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

0 comments on commit de6e6ae

Please sign in to comment.