diff --git a/api/build-tools/schema-sync.sh b/api/build-tools/schema-sync.sh new file mode 100755 index 0000000000..830e19c9e3 --- /dev/null +++ b/api/build-tools/schema-sync.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +pwd=`pwd` + +version="master" +if [[ -n $1 ]]; then +version=$1 +fi + +rm -rf ./api/build-tools/apisix/ +wget https://github.com/apache/apisix/archive/$version.zip + +unzip $version.zip +mkdir -p ./api/build-tools/apisix/ +mv ./apisix-$version/apisix/* ./api/build-tools/apisix/ +rm -rf ./apisix-$version +cd ./api/build-tools/ && lua schema-sync.lua > ${pwd}/api/conf/schema.json + +echo "sync success:" +echo "${pwd}/api/conf/schema.json" diff --git a/api/build.sh b/api/build.sh new file mode 100755 index 0000000000..17867a50ee --- /dev/null +++ b/api/build.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +export ENV=local +pwd=`pwd` + +# get dag-to-lua lib +if [[ ! -f "dag-to-lua-1.1/lib/dag-to-lua.lua" ]]; then + wget https://github.com/api7/dag-to-lua/archive/v1.1.tar.gz + tar -zxvf v1.1.tar.gz +fi + +# build +cd ./api && go build -o ../manager-api . + +echo "done." diff --git a/api/run.sh b/api/run.sh index a45061dc61..deced4a70b 100755 --- a/api/run.sh +++ b/api/run.sh @@ -20,44 +20,7 @@ export ENV=local pwd=`pwd` # config -cp ${pwd}/api/conf/conf_preview.json ${pwd}/conf.json export APIX_DAG_LIB_PATH="${pwd}/dag-to-lua-1.1/lib/" export APIX_ETCD_ENDPOINTS="127.0.0.1:2379" -export SYSLOG_HOST=127.0.0.1 - -if [[ "$unamestr" == 'Darwin' ]]; then - sed -i '' -e "s%#syslogAddress#%`echo $SYSLOG_HOST`%g" ${pwd}/conf.json -else - sed -i -e "s%#syslogAddress#%`echo $SYSLOG_HOST`%g" ${pwd}/conf.json -fi - -cp ${pwd}/conf.json ${pwd}/api/conf/conf.json - - -# get dag-to-lua lib -if [[ ! -f "dag-to-lua-1.1/lib/dag-to-lua.lua" ]]; then - wget https://github.com/api7/dag-to-lua/archive/v1.1.tar.gz - tar -zxvf v1.1.tar.gz -fi - - -# generate json schema if need a new one -if [[ ! -f "${pwd}/api/conf/schema.json" ]]; then - rm master.zip - rm -rf ./api/build-tools/apisix/ - wget https://github.com/apache/apisix/archive/master.zip - unzip master.zip - mkdir -p ./api/build-tools/apisix/ - mv ./apisix-master/apisix/* ./api/build-tools/apisix/ - rm -rf ./apisix-master - cd ./api/build-tools/ && lua schema-sync.lua > ${pwd}/api/conf/schema.json - cd ../../ -fi - -# build -if [[ ! -f "${pwd}/manager-api" ]]; then - cd ./api && go build -o ../manager-api . - cd ../ -fi exec ./manager-api diff --git a/docs/deploy.md b/docs/deploy.md index a91dc3dbad..b6cd8558b6 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -61,10 +61,16 @@ export APIX_ETCD_ENDPOINTS="127.0.0.1:2379,127.0.0.1:3379" $ go env -w GOPROXY=https://goproxy.cn,direct ``` -3. Build and Run +3. Build ```sh -$ ./api/run.sh & +$ api/build.sh +``` + +4. Run + +```sh +$ api/run.sh & ``` ## Build the frontend diff --git a/docs/deploy.zh-CN.md b/docs/deploy.zh-CN.md index f8a899b6f5..24b72d1045 100644 --- a/docs/deploy.zh-CN.md +++ b/docs/deploy.zh-CN.md @@ -61,10 +61,16 @@ $ export APIX_ETCD_ENDPOINTS="127.0.0.1:2379,127.0.0.1:3379" $ go env -w GOPROXY=https://goproxy.cn,direct ``` -3. 构建并启动 +3. 构建 ```sh -$ ./api/run.sh & +$ api/build.sh +``` + +4. 启动 + +```sh +$ api/run.sh ``` ## 构建前端 diff --git a/docs/develop.md b/docs/develop.md index 2a6385c37e..54431cea59 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -38,4 +38,18 @@ $ yarn start ## manager-api -TODO +### Sync jsonschema + +To sync jsonschema from Apache APISIX, `Lua` 5.1+ and `zip` need to be preinstalled, then execute this command: `api/build-tools/schema-sync.sh $version`. + +NOTE: `$version` should be `master` or Apache APISIX's version. + +Example: + +```sh +# Using "master" +$ api/build-tools/schema-sync.sh master + +# Using Apache APISIX's version +$ api/build-tools/schema-sync.sh 2.0 +``` diff --git a/docs/develop.zh-CN.md b/docs/develop.zh-CN.md index 4f730944a2..99f02535d9 100644 --- a/docs/develop.zh-CN.md +++ b/docs/develop.zh-CN.md @@ -41,4 +41,18 @@ $ yarn start ## manager-api 开发 -待补充 +### 同步 jsonschema + +从 Apache APISIX 同步 jsonschema ,需要预安装 `Lua` 5.1+ 和 `zip` ,并执行命令 `api/build-tools/schema-sync.sh $version`。 + +注意:`$version` 为 `master` 或者 Apache APISIX 的版本号。 + +示例: + +```sh +# 使用 "master" +$ api/build-tools/schema-sync.sh master + +# 使用 Apache APISIX 的版本号 +$ api/build-tools/schema-sync.sh 2.0 +```