diff --git a/README.md b/README.md index 2c2adc7ab3f..d64c51148b8 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,13 @@ go get github.com/grafana/grafana ``` ### Building the backend +Replace X.Y.Z by actual version number. ``` cd $GOPATH/src/github.com/grafana/grafana go run build.go setup (only needed once to install godep) godep restore (will pull down all golang lib dependencies in your current GOPATH) -go build . +go build -ldflags "-X main.build_date=`date +%Y-%m-%d` -X main.version=X.Y.Z -X main.commit=`git rev-parse --verify HEAD`" + ``` ### Building frontend assets diff --git a/main.go b/main.go index 9639d432bea..4a052ea4934 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "io/ioutil" "os" "os/signal" @@ -27,6 +28,7 @@ import ( var version = "master" var commit = "NA" var buildstamp string +var build_date string var configFile = flag.String("config", "", "path to config file") var homePath = flag.String("homepath", "", "path to grafana install/home path, defaults to working directory") @@ -38,6 +40,14 @@ func init() { } func main() { + + v := flag.Bool("v", false, "prints current version and exits") + flag.Parse() + if *v { + fmt.Printf("Version %s (commit: %s)\n", version, commit) + os.Exit(0) + } + buildstampInt64, _ := strconv.ParseInt(buildstamp, 10, 64) setting.BuildVersion = version