Updated makefile to include git commit

This commit is contained in:
Carlos Salguero
2019-09-07 16:16:44 -03:00
parent 8af89a638d
commit 737c5de9af
5 changed files with 47 additions and 38 deletions

View File

@@ -3,13 +3,14 @@ pkgs = $(shell find . -type d -name "pt-*" -exec basename {} \;)
VERSION="3.0.13" VERSION="3.0.13"
BUILD=$(shell date +%FT%T%z) BUILD=$(shell date +%FT%T%z)
GOVERSION=$(shell go version | cut --delimiter=" " -f3) GOVERSION=$(shell go version | cut --delimiter=" " -f3)
COMMIT=$(shell git rev-list -1 HEAD)
GOUTILSDIR ?= $(GOPATH)/bin GOUTILSDIR ?= $(GOPATH)/bin
PREFIX=$(shell pwd) PREFIX=$(shell pwd)
TOP_DIR=$(shell git rev-parse --show-toplevel) TOP_DIR=$(shell git rev-parse --show-toplevel)
BIN_DIR=$(shell git rev-parse --show-toplevel)/bin BIN_DIR=$(shell git rev-parse --show-toplevel)/bin
SRC_DIR=$(shell git rev-parse --show-toplevel)/src/go SRC_DIR=$(shell git rev-parse --show-toplevel)/src/go
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.GoVersion=${GOVERSION} -s -w" LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.GoVersion=${GOVERSION} -X main.Commit=${COMMIT} -s -w"
TEST_PSMDB_VERSION?=3.6 TEST_PSMDB_VERSION?=3.6
TEST_MONGODB_FLAVOR?=percona/percona-server-mongodb TEST_MONGODB_FLAVOR?=percona/percona-server-mongodb

View File

@@ -38,9 +38,10 @@ const (
) )
var ( var (
Build string = "01-01-1980" Build string = "01-01-1980" //nolint
GoVersion string = "1.8" GoVersion string = "1.8" //nolint
Version string = "3.0.1" Version string = "3.0.1" //nolint
Commit string //nolint
) )
type cliOptions struct { type cliOptions struct {
@@ -90,6 +91,7 @@ func main() {
fmt.Println(TOOLNAME) fmt.Println(TOOLNAME)
fmt.Printf("Version %s\n", Version) fmt.Printf("Version %s\n", Version)
fmt.Printf("Build: %s using %s\n", Build, GoVersion) fmt.Printf("Build: %s using %s\n", Build, GoVersion)
fmt.Printf("Commit: %s\n", Commit)
return return
} }
@@ -98,12 +100,10 @@ func main() {
advice, err := versioncheck.CheckUpdates(TOOLNAME, Version) advice, err := versioncheck.CheckUpdates(TOOLNAME, Version)
if err != nil { if err != nil {
log.Infof("cannot check version updates: %s", err.Error()) log.Infof("cannot check version updates: %s", err.Error())
} else { } else if advice != "" {
if advice != "" {
log.Warn(advice) log.Warn(advice)
} }
} }
}
log.Debugf("Command line options:\n%+v\n", opts) log.Debugf("Command line options:\n%+v\n", opts)

View File

@@ -41,9 +41,10 @@ const (
) )
var ( var (
Build string = "01-01-1980" Build string = "01-01-1980" // nolint
GoVersion string = "1.8" GoVersion string = "1.8" // nolint
Version string = "3.0.1" Version string = "3.0.1" // nolint
Commit string // nolint
) )
type TimedStats struct { type TimedStats struct {
@@ -126,20 +127,20 @@ type clusterwideInfo struct {
} }
type cliOptions struct { type cliOptions struct {
Help bool
Host string Host string
User string User string
Password string Password string
AuthDB string AuthDB string
LogLevel string LogLevel string
OutputFormat string
SSLCAFile string
SSLPEMKeyFile string
RunningOpsSamples int
RunningOpsInterval int
Help bool
Version bool Version bool
NoVersionCheck bool NoVersionCheck bool
NoRunningOps bool NoRunningOps bool
OutputFormat string
RunningOpsSamples int
RunningOpsInterval int
SSLCAFile string
SSLPEMKeyFile string
} }
type collectedInfo struct { type collectedInfo struct {
@@ -179,6 +180,7 @@ func main() {
fmt.Println(TOOLNAME) fmt.Println(TOOLNAME)
fmt.Printf("Version %s\n", Version) fmt.Printf("Version %s\n", Version)
fmt.Printf("Build: %s using %s\n", Build, GoVersion) fmt.Printf("Build: %s using %s\n", Build, GoVersion)
fmt.Printf("Commit: %s\n", Commit)
return return
} }
@@ -187,12 +189,10 @@ func main() {
advice, err := versioncheck.CheckUpdates(TOOLNAME, Version) advice, err := versioncheck.CheckUpdates(TOOLNAME, Version)
if err != nil { if err != nil {
log.Infof("cannot check version updates: %s", err.Error()) log.Infof("cannot check version updates: %s", err.Error())
} else { } else if advice != "" {
if advice != "" {
log.Infof(advice) log.Infof(advice)
} }
} }
}
ctx := context.Background() ctx := context.Background()
clientOptions := getClientOptions(opts) clientOptions := getClientOptions(opts)
@@ -203,9 +203,12 @@ func main() {
if err := client.Connect(ctx); err != nil { if err := client.Connect(ctx); err != nil {
log.Fatalf("Cannot connect to MongoDB: %s", err) log.Fatalf("Cannot connect to MongoDB: %s", err)
} }
defer client.Disconnect(ctx) defer client.Disconnect(ctx) // nolint
hostnames, err := util.GetHostnames(ctx, client) hostnames, err := util.GetHostnames(ctx, client)
if err != nil {
log.Errorf("Cannot get hostnames: %s", err)
}
log.Debugf("hostnames: %v", hostnames) log.Debugf("hostnames: %v", hostnames)
ci := &collectedInfo{} ci := &collectedInfo{}
@@ -288,39 +291,39 @@ func formatResults(ci *collectedInfo, format string) ([]byte, error) {
t := template.Must(template.New("replicas").Parse(templates.Replicas)) t := template.Must(template.New("replicas").Parse(templates.Replicas))
if err := t.Execute(buf, ci.ReplicaMembers); err != nil { if err := t.Execute(buf, ci.ReplicaMembers); err != nil {
return nil, errors.Wrap(err, "cannnot parse replicas section of the output template") return nil, errors.Wrap(err, "cannot parse replicas section of the output template")
} }
t = template.Must(template.New("hosttemplateData").Parse(templates.HostInfo)) t = template.Must(template.New("hosttemplateData").Parse(templates.HostInfo))
if err := t.Execute(buf, ci.HostInfo); err != nil { if err := t.Execute(buf, ci.HostInfo); err != nil {
return nil, errors.Wrap(err, "cannnot parse hosttemplateData section of the output template") return nil, errors.Wrap(err, "cannot parse hosttemplateData section of the output template")
} }
t = template.Must(template.New("runningOps").Parse(templates.RunningOps)) t = template.Must(template.New("runningOps").Parse(templates.RunningOps))
if err := t.Execute(buf, ci.RunningOps); err != nil { if err := t.Execute(buf, ci.RunningOps); err != nil {
return nil, errors.Wrap(err, "cannnot parse runningOps section of the output template") return nil, errors.Wrap(err, "cannot parse runningOps section of the output template")
} }
t = template.Must(template.New("ssl").Parse(templates.Security)) t = template.Must(template.New("ssl").Parse(templates.Security))
if err := t.Execute(buf, ci.SecuritySettings); err != nil { if err := t.Execute(buf, ci.SecuritySettings); err != nil {
return nil, errors.Wrap(err, "cannnot parse ssl section of the output template") return nil, errors.Wrap(err, "cannot parse ssl section of the output template")
} }
if ci.OplogInfo != nil && len(ci.OplogInfo) > 0 { if ci.OplogInfo != nil && len(ci.OplogInfo) > 0 {
t = template.Must(template.New("oplogInfo").Parse(templates.Oplog)) t = template.Must(template.New("oplogInfo").Parse(templates.Oplog))
if err := t.Execute(buf, ci.OplogInfo[0]); err != nil { if err := t.Execute(buf, ci.OplogInfo[0]); err != nil {
return nil, errors.Wrap(err, "cannnot parse oplogInfo section of the output template") return nil, errors.Wrap(err, "cannot parse oplogInfo section of the output template")
} }
} }
t = template.Must(template.New("clusterwide").Parse(templates.Clusterwide)) t = template.Must(template.New("clusterwide").Parse(templates.Clusterwide))
if err := t.Execute(buf, ci.ClusterWideInfo); err != nil { if err := t.Execute(buf, ci.ClusterWideInfo); err != nil {
return nil, errors.Wrap(err, "cannnot parse clusterwide section of the output template") return nil, errors.Wrap(err, "cannot parse clusterwide section of the output template")
} }
t = template.Must(template.New("balancer").Parse(templates.BalancerStats)) t = template.Must(template.New("balancer").Parse(templates.BalancerStats))
if err := t.Execute(buf, ci.BalancerStats); err != nil { if err := t.Execute(buf, ci.BalancerStats); err != nil {
return nil, errors.Wrap(err, "cannnot parse balancer section of the output template") return nil, errors.Wrap(err, "cannot parse balancer section of the output template")
} }
} }
@@ -566,7 +569,8 @@ func getNodeType(ctx context.Context, client *mongo.Client) (string, error) {
return "mongod", nil return "mongod", nil
} }
func getOpCountersStats(ctx context.Context, client *mongo.Client, count int, sleep time.Duration) (*opCounters, error) { func getOpCountersStats(ctx context.Context, client *mongo.Client, count int,
sleep time.Duration) (*opCounters, error) {
oc := &opCounters{} oc := &opCounters{}
prevOpCount := &opCounters{} prevOpCount := &opCounters{}
ss := proto.ServerStatus{} ss := proto.ServerStatus{}

View File

@@ -18,9 +18,10 @@ import (
) )
var ( var (
version = "dev" Build string = "01-01-1980" //nolint
commit = "none" Commit string //nolint
date = "unknown" GoVersion string = "1.8" //nolint
Version string = "3.0.1" //nolint
) )
type connOpts struct { type connOpts struct {
@@ -190,7 +191,8 @@ func safeConnString(opts connOpts, dbName string) string {
func parseCommandLineOpts(args []string) (cliOptions, error) { func parseCommandLineOpts(args []string) (cliOptions, error) {
app := kingpin.New("pt-pg-summary", "Percona Toolkit - PostgreSQL Summary") app := kingpin.New("pt-pg-summary", "Percona Toolkit - PostgreSQL Summary")
// version, commit and date will be set at build time by the compiler -ldflags param // version, commit and date will be set at build time by the compiler -ldflags param
app.Version(fmt.Sprintf("%s version %s, git commit %s, date: %s", app.Name, version, commit, date)) app.Version(fmt.Sprintf("%s version %s\nGIT commit %s\nDate: %s\nGo version: %s",
app.Name, Version, Commit, Build, GoVersion))
opts := cliOptions{app: app} opts := cliOptions{app: app}
app.Flag("ask-pass", "Prompt for a password when connecting to PostgreSQL"). app.Flag("ask-pass", "Prompt for a password when connecting to PostgreSQL").

View File

@@ -84,9 +84,10 @@ var (
"pt-mysql-summary --host=$mysql-host --port=$mysql-port --user=$mysql-user --password=$mysql-pass", "pt-mysql-summary --host=$mysql-host --port=$mysql-port --user=$mysql-user --password=$mysql-pass",
} }
Build string = "01-01-1980" Build string = "01-01-1980" //nolint
GoVersion string = "1.8" GoVersion string = "1.8" //nolint
Version string = "3.0.1" Version string = "3.0.1" //nolint
Commit string //nolint
) )
func main() { func main() {
@@ -177,7 +178,8 @@ func processCliParams(baseTempPath string, usageWriter io.Writer) (*cliOptions,
} }
// Add support for --version flag // Add support for --version flag
app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion) app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion +
" Go version: " + GoVersion)
opts := &cliOptions{ opts := &cliOptions{
CollectCommand: app.Command(collectCmd, "Collect, sanitize, pack and encrypt data from pt-tools."), CollectCommand: app.Command(collectCmd, "Collect, sanitize, pack and encrypt data from pt-tools."),