Skip to content

Commit

Permalink
[cli] append lualib paths to load openresty libraries
Browse files Browse the repository at this point in the history
* when rover.setup is activated it strips out all paths other than
lua_modules
* openresty ships shared code in $prefix/lualib/ directory
  • Loading branch information
mikz committed Feb 15, 2018
1 parent 3481441 commit f334564
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Running with development config in Docker [PR #555](https://github.com/3scale/apicast/pull/555)
- Fix setting twice the headers in a pre-flight request in the CORS policy [PR #570](https://github.com/3scale/apicast/pull/570)
- Fix case where debug headers are returned without enabling the option [PR #577](https://github.com/3scale/apicast/pull/577)
- Fix errors loading openresty libraries when rover is active [PR #598](https://github.com/3scale/apicast/pull/598)

## Changed

Expand Down
1 change: 0 additions & 1 deletion bin/cli

This file was deleted.

64 changes: 61 additions & 3 deletions gateway/bin/apicast
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ my $bin = "$apicast_bin/cli";
if (! -f $bin) {
my ($lua, $lua_file) = tempfile();

print $lua <<_LUA_;
require('apicast.cli')(arg)
_LUA_
print { $lua } <DATA>;
close DATA;
close $lua;

$bin = $lua_file;
}
Expand All @@ -109,3 +109,61 @@ for my $inc ($apicast_src, 'src') {
my @args = ('resty', @resty_args, $bin, @ARGV);

exec '/usr/bin/env', @args;

__DATA__
#!/usr/bin/env resty
local ok, setup = pcall(require, 'rover.setup')
local re = require('ngx.re')
-- detect the full path to resty binary this has been started with
local function resty(code)
local cmd
do
local i = 0
while not cmd do
if not arg[i-1] then cmd = arg[i] end
i = i - 1
end
end
if not cmd then return nil, 'could not find resty' end
local handle = io.popen(([[/usr/bin/env -i %q -e %q]]):format(cmd, code))
local result = handle:read("*l")
handle:close()
return result
end
-- get the default package.path and strip out paths for shared code
local function default_package_path()
local sep = ';'
local filtered = {}
local LUA_DEFAULT_PATH = resty('print(package.path)')
local contains = function(str, pattern) return str:find(pattern, 1, true) end
local paths = re.split(LUA_DEFAULT_PATH or '', sep, 'oj')
for i=1,#paths do
local path = paths[i]
if not contains(path, '/site/') and
not contains(path, '/share/') and
path:find('^/') then
table.insert(filtered, path)
end
end
return table.concat(filtered, sep)
end
if ok then
setup()
-- use not only rover paths but also code shipped with openresty
package.path = package.path ..';' .. default_package_path()
-- load apicast and dependencies
require('apicast.executor')
else
package.path = './src/?.lua;' .. package.path
end
require('apicast.cli')(arg)
14 changes: 0 additions & 14 deletions gateway/bin/cli

This file was deleted.

0 comments on commit f334564

Please sign in to comment.