Show fission deployment version with cli (#538)
Add version information to binary through go ldflags
This commit is contained in:
@@ -33,6 +33,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dchest/uniuri"
|
||||
|
||||
"github.com/fission/fission"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -68,6 +70,11 @@ func MakeBuilder(sharedVolumePath string) *Builder {
|
||||
}
|
||||
}
|
||||
|
||||
func (builder *Builder) VersionHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
fmt.Fprintf(w, fission.VersionInfo().String())
|
||||
}
|
||||
|
||||
func (builder *Builder) Handler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
e := fmt.Sprintf("Method not allowed: %v", r.Method)
|
||||
|
||||
+16
-1
@@ -1,3 +1,18 @@
|
||||
#!/bin/bash
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -o builder .
|
||||
version=$1
|
||||
if [ -z $version ]; then
|
||||
version=$(git rev-parse HEAD)
|
||||
fi
|
||||
|
||||
date=$2
|
||||
if [ -z $date ]; then
|
||||
date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
fi
|
||||
|
||||
gitcommit=$3
|
||||
if [ -z $gitcommit ]; then
|
||||
gitcommit=$(git rev-parse HEAD)
|
||||
fi
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version" -o builder .
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ func main() {
|
||||
builder := builder.MakeBuilder(dir)
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", builder.Handler)
|
||||
mux.HandleFunc("/version", builder.VersionHandler)
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user