Skip to content

Commit

Permalink
fix: Support version/githash for target api-run (#1200)
Browse files Browse the repository at this point in the history
Signed-off-by: imjoey <majunjiev@gmail.com>
  • Loading branch information
imjoey authored Jan 5, 2021
1 parent 3d30aa0 commit 45e90ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ api-test: api-default
### api-run: Run the manager-api
.PHONY: api-run
api-run: api-default
cd api/ && go run ./cmd/manager
api/build.sh --dry-run


### api-stop: Stop the manager-api
api-stop:
Expand Down
17 changes: 13 additions & 4 deletions api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex
export ENV=local
pwd=`pwd`
set -e

VERSION=$(cat ./api/VERSION)
GITHASH=$(cat ./.githash 2> /dev/null || HASH="ref: HEAD"; while [[ $HASH == ref\:* ]]; do HASH="$(cat ".git/$(echo $HASH | cut -d \ -f 2)")"; done; echo ${HASH:0:7})
GOLDFLAGS="-X github.com/apisix/manager-api/cmd.Version=${VERSION} -X github.com/apisix/manager-api/cmd.GitHash=${GITHASH}"

# Enter dry-run mode
if [ "$1" == "--dry-run" ]; then
cd ./api && go run -ldflags "${GOLDFLAGS}" ./cmd/manager
exit 0
fi

set -x
export ENV=local
pwd=`pwd`

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

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

# build
cd ./api && go build -o ../output/manager-api -ldflags "-X github.com/apisix/manager-api/cmd.Version=${VERSION} -X github.com/apisix/manager-api/cmd.GitHash=${GITHASH}" ./cmd/manager && cd ..
cd ./api && go build -o ../output/manager-api -ldflags "${GOLDFLAGS}" ./cmd/manager && cd ..

cp ./api/conf/schema.json ./output/conf/schema.json
cp ./api/conf/conf.yaml ./output/conf/conf.yaml
Expand Down

0 comments on commit 45e90ec

Please sign in to comment.