Skip to content

Commit

Permalink
feat: add version into manager-api (apache#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
starsz committed Nov 28, 2020
1 parent 277ae59 commit f8b3955
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.1-rc1
5 changes: 4 additions & 1 deletion api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set -ex
export ENV=local
pwd=`pwd`

VERSION=$(cat ./api/VERSION)
GIT_VERSION=$(git log -1 --pretty=format:%h)

rm -rf output && mkdir -p output/conf && mkdir -p output/dag-to-lua

# get dag-to-lua lib
Expand All @@ -29,7 +32,7 @@ if [[ ! -f "dag-to-lua-1.1/lib/dag-to-lua.lua" ]]; then
fi

# build
cd ./api && go build -o ../output/manager-api . && cd ..
cd ./api && go build -o ../output/manager-api -ldflags "-X main.Version=${VERSION}(${GIT_VERSION})" . && cd ..

cp ./api/conf/schema.json ./output/conf/schema.json
cp ./api/conf/conf.yaml ./output/conf/conf.yaml
Expand Down
10 changes: 2 additions & 8 deletions api/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package conf

import (
"flag"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -93,14 +92,9 @@ type Config struct {
Authentication Authentication
}

func init() {
func Init(dir string) {
//go test
if workDir := os.Getenv("APISIX_API_WORKDIR"); workDir != "" {
WorkDir = workDir
} else {
flag.StringVar(&WorkDir, "p", ".", "current work dir")
flag.Parse()
}
WorkDir = dir

setConf()
setEnvironment()
Expand Down
21 changes: 21 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"flag"
"fmt"
"net/http"
"os"
Expand All @@ -33,6 +34,26 @@ import (
"github.com/apisix/manager-api/log"
)

var Version string

func init() {
showVersion := flag.Bool("v", false, "show version")
workDir := flag.String("p", ".", "current work dir")

flag.Parse()

if *showVersion {
fmt.Fprintf(os.Stdout, "manager-apisix version: %s\n", Version)
os.Exit(0)
}

if dir := os.Getenv("APISIX_API_WORKDIR"); dir != "" {
conf.Init(dir)
} else {
conf.Init(*workDir)
}
}

func main() {

if err := storage.InitETCDClient(conf.ETCDEndpoints); err != nil {
Expand Down

0 comments on commit f8b3955

Please sign in to comment.