Skip to content

Commit

Permalink
feat: support to show version info when manager-api starting (#900)
Browse files Browse the repository at this point in the history
fix #866
fix #853
  • Loading branch information
starsz authored Dec 11, 2020
1 parent 4196844 commit d72c478
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 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
12 changes: 12 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +86,8 @@ func main() {
}
}()

printInfo()

sig := <-quit
log.Infof("The Manager API server receive %s and start shutting down", sig.String())

Expand Down
33 changes: 32 additions & 1 deletion api/test/shell/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#

set -ex
VERSION=$(cat ./VERSION)

clean_up() {
git checkout conf/conf.yaml
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d72c478

Please sign in to comment.