diff --git a/api/VERSION b/api/VERSION new file mode 100644 index 0000000000..1f3e3c351b --- /dev/null +++ b/api/VERSION @@ -0,0 +1 @@ +v2.1-rc1 diff --git a/api/build.sh b/api/build.sh index 811eb84269..5bae5d28b3 100755 --- a/api/build.sh +++ b/api/build.sh @@ -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 @@ -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 diff --git a/api/main.go b/api/main.go index 48fb6a8303..4e4eec176b 100644 --- a/api/main.go +++ b/api/main.go @@ -36,6 +36,16 @@ import ( "github.com/apisix/manager-api/log" ) +var Version string + +func printInfo() { + fmt.Fprint(os.Stdout, "The manager-api is running successfully!\n\n") + fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Version", Version) + fmt.Fprintf(os.Stdout, "%-8s: %s:%d\n", "Listen", conf.ServerHost, conf.ServerPort) + fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Loglevel", conf.ErrorLogLevel) + fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "Logfile", conf.ErrorLogPath) +} + func main() { droplet.Option.Orchestrator = func(mws []droplet.Middleware) []droplet.Middleware { var newMws []droplet.Middleware @@ -76,6 +86,8 @@ func main() { } }() + printInfo() + sig := <-quit log.Infof("The Manager API server receive %s and start shutting down", sig.String()) diff --git a/api/test/shell/cli_test.sh b/api/test/shell/cli_test.sh index 76d313da81..ad1568d2a8 100755 --- a/api/test/shell/cli_test.sh +++ b/api/test/shell/cli_test.sh @@ -18,6 +18,7 @@ # set -ex +VERSION=$(cat ./VERSION) clean_up() { git checkout conf/conf.yaml @@ -39,7 +40,7 @@ clean_logfile() { trap clean_up EXIT export GO111MODULE=on -go build -o ./manager-api . +go build -o ./manager-api -ldflags "-X main.Version=${VERSION}" . # default level: warn, path: logs/error.log @@ -94,6 +95,36 @@ if [[ `grep -c "INFO" ./error.log` -eq '0' ]]; then exit 1 fi + +# test start info + +LOGLEVEL=$(cat conf/conf.yaml | awk '$1=="level:"{print $2}') +HOST=$(cat conf/conf.yaml | awk '$1=="host:"{print $2}') +PORT=$(cat conf/conf.yaml | awk '$1=="port:"{print $2}') +STDOUT=/tmp/manager-api +./manager-api &>/tmp/manager-api & +sleep 3 + +if [[ `grep -c "The manager-api is running successfully\!" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${VERSION}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${LOGLEVEL}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${HOST}:${PORT}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + # set an invalid etcd endpoint clean_up