diff --git a/blockbook.go b/blockbook.go index a3672b42..6d8d6c41 100644 --- a/blockbook.go +++ b/blockbook.go @@ -117,6 +117,8 @@ func main() { chanOsSignal = make(chan os.Signal, 1) signal.Notify(chanOsSignal, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) + glog.Infof("Blockbook: %+v", common.GetVersionInfo()) + if *prof != "" { go func() { log.Println(http.ListenAndServe(*prof, nil)) diff --git a/build/bin/Makefile b/build/bin/Makefile index c1861871..3b29d758 100644 --- a/build/bin/Makefile +++ b/build/bin/Makefile @@ -1,12 +1,16 @@ UPDATE_VENDOR ?= 1 +VERSION ?= devel +GITCOMMIT = $(shell cd /src && git describe --tags --always --dirty) +BUILDTIME = $(shell date --iso-8601=seconds) +LDFLAGS := -X blockbook/common.version=$(VERSION) -X blockbook/common.gitcommit=$(GITCOMMIT) -X blockbook/common.buildtime=$(BUILDTIME) build: prepare-sources - cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook -ldflags="-s -w" + cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook -ldflags="-s -w $(LDFLAGS)" cp $(CURDIR)/blockbook /out/blockbook chown $(PACKAGER) /out/blockbook build-debug: prepare-sources - cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook + cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook -ldflags="$(LDFLAGS)" cp $(CURDIR)/blockbook /out/blockbook chown $(PACKAGER) /out/blockbook diff --git a/build/deb/build-deb.sh b/build/deb/build-deb.sh index 4b97be27..368060b6 100755 --- a/build/deb/build-deb.sh +++ b/build/deb/build-deb.sh @@ -6,6 +6,8 @@ cp -r /src/configs . cp -r /src/static static mkdir cert && cp /src/server/testcert.* cert +export VERSION=$(dpkg-parsechangelog | sed -rne 's/^Version: ([0-9.]+)([-+~].+)?$/\1/p') + dpkg-buildpackage -us -uc mv ../*.deb /out chown $PACKAGER /out/*.deb diff --git a/common/version.go b/common/version.go new file mode 100644 index 00000000..43a96e2f --- /dev/null +++ b/common/version.go @@ -0,0 +1,27 @@ +package common + +import "runtime" + +var ( + version = "unknown" + gitcommit = "unknown" + buildtime = "unknown" +) + +type VersionInfo struct { + Version string `json:"version"` + GitCommit string `json:"gitcommit"` + BuildTime string `json:"buildtime"` + GoVersion string `json:"goversion"` + OSArch string `json:"os/arch"` +} + +func GetVersionInfo() VersionInfo { + return VersionInfo{ + Version: version, + GitCommit: gitcommit, + BuildTime: buildtime, + GoVersion: runtime.Version(), + OSArch: runtime.GOOS + "/" + runtime.GOARCH, + } +} diff --git a/server/socketio.go b/server/socketio.go index bade3398..cce86e75 100644 --- a/server/socketio.go +++ b/server/socketio.go @@ -19,7 +19,7 @@ import ( "github.com/martinboehm/golang-socketio/transport" ) -const blockbookAbout = "Blockbook v0.0.1, blockchain indexer for TREZOR wallet https://trezor.io/. Do not use for any other purpose." +const blockbookAbout = "Blockbook - blockchain indexer for TREZOR wallet https://trezor.io/. Do not use for any other purpose." // SocketIoServer is handle to SocketIoServer type SocketIoServer struct { @@ -140,6 +140,7 @@ func (s *SocketIoServer) apiBlockIndex(w http.ResponseWriter, r *http.Request) { type resBlockIndex struct { BlockHash string `json:"blockHash"` About string `json:"about"` + common.VersionInfo } var err error var hash string @@ -157,7 +158,11 @@ func (s *SocketIoServer) apiBlockIndex(w http.ResponseWriter, r *http.Request) { if err != nil { glog.Error(err) } else { - r := resBlockIndex{BlockHash: hash, About: blockbookAbout} + r := resBlockIndex{ + BlockHash: hash, + About: blockbookAbout, + VersionInfo: common.GetVersionInfo(), + } json.NewEncoder(w).Encode(r) } }