Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support version/githash for make api-run command #1200

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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