From 2d09731dfdecd2861144a1c86bd33eeadcedb0b5 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Thu, 16 Feb 2017 15:16:32 -0600 Subject: [PATCH] Add Makefile and versioning/build time in pilosa/pilosactl --- Makefile | 47 +++++++++++++++++++++++++++++++++++++------ cmd/pilosa/main.go | 12 ++++++++--- cmd/pilosactl/main.go | 15 ++++++++++++++ 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 61abf2026..62d6fe2f1 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,45 @@ -.PHONY: vendor +.PHONY: glide vendor-update docker pilosa pilosactl crossbuild install -default: +GLIDE := $(shell command -v glide 2>/dev/null) +VERSION := $(shell git describe --tags) +IDENTIFIER := $(VERSION)-$(GOOS)-$(GOARCH) +CLONE_URL=github.com/pilosa/pilosa +BUILD_TIME=`date -u +%FT%T%z` +LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)" -vendor: - godep save ./... - cp -r $(GOPATH)/src/github.com/gogo/protobuf/proto/testdata vendor/github.com/gogo/protobuf/proto/testdata +default: test pilosa pilosactl -docker: +$(GLIDE): + curl https://glide.sh/get | sh + touch $(GLIDE) + +glide: $(GLIDE) + +vendor: $(GLIDE) glide.yaml + glide install + +glide.lock: $(GLIDE) glide.yaml + glide update + +vendor-update: glide.lock + +test: vendor + go test $(shell cd $(GOPATH)/src/$(CLONE_URL); go list ./... | grep -v vendor) + +pilosa: vendor + go build $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa + +pilosactl: vendor + go build $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosactl + +crossbuild: vendor + mkdir -p build/pilosa-$(IDENTIFIER) + make pilosa FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosa" + make pilosactl FLAGS="-o build/pilosa-$(IDENTIFIER)/pilosactl" + +install: vendor + go install $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosa + go install $(LDFLAGS) $(FLAGS) $(CLONE_URL)/cmd/pilosactl + +docker: vendor docker build -t pilosa:latest . diff --git a/cmd/pilosa/main.go b/cmd/pilosa/main.go index bcd3ee453..4f7474996 100644 --- a/cmd/pilosa/main.go +++ b/cmd/pilosa/main.go @@ -17,13 +17,19 @@ import ( "github.com/pilosa/pilosa" ) -// Version holds the version information passed in at compile time. -var Version string +// Version and BuildTime hold the version/build time information passed in at compile time. +var ( + Version string + BuildTime string +) func init() { if Version == "" { Version = "v0.0.0" } + if BuildTime == "" { + BuildTime = "not recorded" + } rand.Seed(time.Now().UTC().UnixNano()) } @@ -36,7 +42,7 @@ const ( func main() { m := NewMain() m.Server.Handler.Version = Version - fmt.Fprintf(m.Stderr, "Pilosa %s\n", Version) + fmt.Fprintf(m.Stderr, "Pilosa %s, build time %s\n", Version, BuildTime) // Parse command line arguments. if err := m.ParseFlags(os.Args[1:]); err != nil { diff --git a/cmd/pilosactl/main.go b/cmd/pilosactl/main.go index 331459c31..08a86c708 100644 --- a/cmd/pilosactl/main.go +++ b/cmd/pilosactl/main.go @@ -42,11 +42,26 @@ var ( // ErrPathRequired is returned when executing a command without a required path. ErrPathRequired = errors.New("path required") + Version string + BuildTime string ) +func init() { + if Version == "" { + Version = "v0.0.0" + } + if BuildTime == "" { + BuildTime = "not recorded" + } + + rand.Seed(time.Now().UTC().UnixNano()) +} + func main() { m := NewMain() + fmt.Fprintf(m.Stderr, "Pilosactl %s, build time %s\n", Version, BuildTime) + // Parse command line arguments. if err := m.ParseFlags(os.Args[1:]); err == flag.ErrHelp { os.Exit(2)