1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

add the version command

This commit is contained in:
shuting 2019-05-29 14:44:21 -07:00
parent 88f3579b2c
commit ea08ef3fbe
3 changed files with 62 additions and 1 deletions

View file

@ -1,17 +1,42 @@
.DEFAULT_GOAL: build
# The CLI binary to build
BIN ?= kyverno
GIT_VERSION := $(shell git describe --dirty --always --tags)
GIT_HASH := $(shell git log -1 --pretty=format:"%H")
TIMESTAMP := $(shell date '+%Y-%m-%d_%I:%M:%S%p')
PACKAGE ?=github.com/nirmata/kyverno
MAIN ?=$(PACKAGE)
LD_FLAGS ="-s -w"
LD_FLAGS="-s -w -X $(PACKAGE)/pkg/kyverno/version.buildVersion=$(GIT_VERSION) -X $(PACKAGE)/pkg/kyverno/version.buildHash=$(GIT_HASH) -X $(PACKAGE)/pkg/kyverno/version.buildTime=$(TIMESTAMP)"
REPO=nirmata/kyverno
TAG=0.1
GOOS ?= $(shell go env GOOS)
OUTPUT=$(shell pwd)/_output/cli/$(BIN)
build:
GOOS=linux go build -ldflags=$(LD_FLAGS) $(MAIN)
local:
go build -ldflags=$(LD_FLAGS) $(MAIN)
cli: cli-dirs
GOOS=$(GOOS) \
go build \
-o $(OUTPUT) \
-ldflags $(LD_FLAGS) \
$(PACKAGE)/cmd/$(BIN)
go build -ldflags=$(LD_FLAGS) $(CLI)
cli-dirs:
@mkdir -p _output/cli
image:
docker build -t $(REPO):$(TAG) .
docker tag $(REPO):$(TAG) $(REPO):latest

View file

@ -5,6 +5,7 @@ import (
"os"
"github.com/nirmata/kyverno/pkg/kyverno/apply"
"github.com/nirmata/kyverno/pkg/kyverno/version"
"github.com/spf13/cobra"
)
@ -21,5 +22,6 @@ func NewKyvernoCommand(in io.Reader, out, errout io.Writer) *cobra.Command {
}
cmds.AddCommand(apply.NewCmdApply(in, out, errout))
cmds.AddCommand(version.NewCmdVersion(out))
return cmds
}

View file

@ -0,0 +1,34 @@
package version
import (
"fmt"
"io"
"github.com/spf13/cobra"
)
var (
buildVersion = "--"
buildHash = "--"
buildTime = "--"
)
// NewCmdVersion is a command to display the build version
func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "",
Run: func(cmd *cobra.Command, args []string) {
showVersion()
},
}
return versionCmd
}
func showVersion() {
fmt.Printf("Version: %s\n", buildVersion)
fmt.Printf("Time: %s\n", buildTime)
fmt.Printf("Git commit ID: %s\n", buildHash)
}