diff --git a/.travis/linux_apisix_master_luarocks_runner.sh b/.travis/linux_apisix_master_luarocks_runner.sh index 01a8d6af..61d0ca58 100755 --- a/.travis/linux_apisix_master_luarocks_runner.sh +++ b/.travis/linux_apisix_master_luarocks_runner.sh @@ -60,6 +60,9 @@ script() { sudo PATH=$PATH ./utils/install-apisix.sh install > build.log 2>&1 || (cat build.log && exit 1) which apisix + # TODO: DELETE ME AFTER + sudo cp ../bin/apisix /usr/bin/apisix + lua -e 'print(package.path)' # run test sudo PATH=$PATH apisix help @@ -72,6 +75,10 @@ script() { # install APISIX by luarocks sudo luarocks install $APISIX_MAIN > build.log 2>&1 || (cat build.log && exit 1) + # TODO: DELETE ME AFTER + sudo cp ../bin/apisix /usr/bin/apisix + lua -e 'print(package.path)' + # show install files luarocks show apisix diff --git a/apisix/cli/env.lua b/apisix/cli/env.lua index ce49f7a8..0fc45f0e 100644 --- a/apisix/cli/env.lua +++ b/apisix/cli/env.lua @@ -15,6 +15,7 @@ -- limitations under the License. -- +local require = require local util = require("apisix.cli.util") local pcall = pcall @@ -22,61 +23,59 @@ local error = error local exit = os.exit local stderr = io.stderr local str_find = string.find -local pkg_cpath_org = package.cpath -local pkg_path_org = package.path +local arg = arg +local package = package -local min_etcd_version = "3.4.0" -local apisix_home = "/usr/local/apisix" -local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;" - .. apisix_home .. "/deps/lib/lua/5.1/?.so;;" -local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;" --- only for developer, use current folder as working space -local is_root_path = false -local script_path = arg[0] -if script_path:sub(1, 2) == './' then - apisix_home = util.trim(util.execute_cmd("pwd")) - if not apisix_home then - error("failed to fetch current path") +return function (apisix_home, pkg_cpath_org, pkg_path_org) + -- only for developer, use current folder as working space + local is_root_path = false + local script_path = arg[0] + if script_path:sub(1, 2) == './' then + apisix_home = util.trim(util.execute_cmd("pwd")) + if not apisix_home then + error("failed to fetch current path") + end + + if str_find(apisix_home .. "/", '/root/', nil, true) == 1 then + is_root_path = true + end + + local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;" + .. apisix_home .. "/deps/lib/lua/5.1/?.so;" + + local pkg_path = apisix_home .. "/?/init.lua;" + .. apisix_home .. "/deps/share/lua/5.1/?.lua;;" + + package.cpath = pkg_cpath .. package.cpath + package.path = pkg_path .. package.path end - if str_find(apisix_home .. "/", '/root/', nil, true) == 1 then - is_root_path = true - end - - pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;" - .. apisix_home .. "/deps/lib/lua/5.1/?.so;" - - pkg_path = apisix_home .. "/?/init.lua;" - .. apisix_home .. "/deps/share/lua/5.1/?.lua;;" -end - -package.cpath = pkg_cpath .. pkg_cpath_org -package.path = pkg_path .. pkg_path_org - -do - -- skip luajit environment - local ok = pcall(require, "table.new") - if not ok then - local ok, json = pcall(require, "cjson") - if ok and json then - stderr:write("please remove the cjson library in Lua, it may " - .. "conflict with the cjson library in openresty. " - .. "\n luarocks remove cjson\n") - exit(1) + do + -- skip luajit environment + local ok = pcall(require, "table.new") + if not ok then + local ok, json = pcall(require, "cjson") + if ok and json then + stderr:write("please remove the cjson library in Lua, it may " + .. "conflict with the cjson library in openresty. " + .. "\n luarocks remove cjson\n") + exit(1) + end end end + + local openresty_args = [[openresty -p ]] .. apisix_home .. [[ -c ]] + .. apisix_home .. [[/conf/nginx.conf]] + + local min_etcd_version = "3.4.0" + + return { + apisix_home = apisix_home, + is_root_path = is_root_path, + openresty_args = openresty_args, + pkg_cpath_org = pkg_cpath_org, + pkg_path_org = pkg_path_org, + min_etcd_version = min_etcd_version, + } end - -local openresty_args = [[openresty -p ]] .. apisix_home .. [[ -c ]] - .. apisix_home .. [[/conf/nginx.conf]] - - -return { - apisix_home = apisix_home, - is_root_path = is_root_path, - openresty_args = openresty_args, - pkg_cpath_org = pkg_cpath_org, - pkg_path_org = pkg_path_org, - min_etcd_version = min_etcd_version, -} diff --git a/bin/apisix b/bin/apisix index 72e54528..b1ff52e9 100755 --- a/bin/apisix +++ b/bin/apisix @@ -17,7 +17,24 @@ -- limitations under the License. -- +local pkg_cpath_org = package.cpath +local pkg_path_org = package.path + +local apisix_home = "/usr/local/apisix" +local pkg_cpath = apisix_home .. "/deps/lib64/lua/5.1/?.so;" + .. apisix_home .. "/deps/lib/lua/5.1/?.so;;" +local pkg_path = apisix_home .. "/deps/share/lua/5.1/?.lua;;" + +-- modify the load path to load our dependencies +package.cpath = pkg_cpath .. pkg_cpath_org +package.path = pkg_path .. pkg_path_org + +-- FIXME DELETE AFTER MERGE local env = require("apisix.cli.env") +if type(env) == 'function' then + -- the cached master one returns table instead of function + env = env(apisix_home, pkg_cpath_org, pkg_path_org) +end local util = require("apisix.cli.util") local ngx_tpl = require("apisix.cli.ngx_tpl") local yaml = require("tinyyaml")