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

[bin] fix loading apicast from luarocks #538

Merged
merged 4 commits into from
Jan 10, 2018
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Detecting local rover installation from the CLI [PR #519](https://github.com/3scale/apicast/pull/519)
- Use more `command` instead of `which` to work in plain shell [PR #521](https://github.com/3scale/apicast/pull/521)
- Fixed rockspec so APIcast can be installed by luarocks [PR #523](https://github.com/3scale/apicast/pull/523)
- Fixed rockspec so APIcast can be installed by luarocks [PR #523](https://github.com/3scale/apicast/pull/523), [PR #538](https://github.com/3scale/apicast/pull/538)
- Fix loading renamed APIcast code [PR #525](https://github.com/3scale/apicast/pull/525)
- Fix `apicast` command when installed from luarocks [PR #527](https://github.com/3scale/apicast/pull/527)
- Fix lua docs formatting in the CORS policy [PR #530](https://github.com/3scale/apicast/pull/530)
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Load policies by the APIcast loader instead of changing load path [PR #532](https://github.com/3scale/apicast/pull/532), [PR #536](https://github.com/3scale/apicast/pull/536)
- Add `src` directory to the Lua load path when using CLI [PR #533](https://github.com/3scale/apicast/pull/533)
- Move rejection reason parsing from CacheHandler to Proxy [PR #541](https://github.com/3scale/apicast/pull/541)
- Propagate full package.path and cpath from the CLI to Nginx [PR #538](https://github.com/3scale/apicast/pull/538)

## [3.2.0-alpha2] - 2017-11-30

14 changes: 9 additions & 5 deletions gateway/bin/apicast
Original file line number Diff line number Diff line change
@@ -36,20 +36,23 @@ _LUA_
return (
$rock . '/bin',
$rock . '/conf',
$rock =~ s{/lib/luarocks/rocks/apicast/.+?/?$}[/share/lua/@{[ detect_lua_version ]}]r
$rock =~ s{/lib/luarocks/rocks/apicast/.+?/?$}[/share/lua/@{[ detect_lua_version ]}]r,
$rock =~ s{/lib/luarocks/rocks/apicast/.+?/?$}[/lib/lua/@{[ detect_lua_version ]}]r,
);
} else {
return (
$apicast_dir . '/bin',
$apicast_dir,
$apicast_dir . '/src'
$apicast_dir . '/src',
$apicast_dir . '/lib',
)
}
}

my ($apicast_bin, $apicast_conf, $apicast_src) = detect_apicast_paths();
my ($apicast_bin, $apicast_conf, $apicast_src, $apicast_lib) = detect_apicast_paths();

my $lua_path = $ENV{LUA_PATH};
my $lua_lib = $ENV{LUA_CPATH};
my $cwd = getcwd();

$ENV{PATH} .= ":$cwd/lua_modules/bin";
@@ -61,18 +64,19 @@ if ($rover && !$lua_path) {
exec '/usr/bin/env', $rover, 'exec', $0, @ARGV
} else {
$lua_path ||= ';';
$lua_lib ||= ';';
}

$ENV{APICAST_DIR} = $apicast_conf;

$ENV{LUA_PATH} = sprintf('%1$s/?.lua;', $apicast_src) . $lua_path;
$ENV{LUA_CPATH} = sprintf('%1$s/?.so;', $apicast_lib) . $lua_lib;

$ENV{PWD} = $cwd;

my $bin = "$apicast_bin/cli";

if (! -f $bin) {
warn "$bin does not exist";

my ($lua, $lua_file) = tempfile();

print $lua <<_LUA_;
3 changes: 2 additions & 1 deletion gateway/conf/nginx.conf.liquid
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@ http {
log_format time '[$time_local] $host:$server_port $remote_addr:$remote_port "$request" $status $body_bytes_sent ($request_time) $post_action_impact';
access_log off;

lua_package_path ";;{{prefix}}/?.lua;{{prefix}}/src/?.lua;";
lua_package_path "{{ lua_path | default: package.path }}";
lua_package_cpath "{{ lua_cpath | default: package.cpath }}";

{% if nameservers %}
resolver {{ nameservers | join: " " }};
6 changes: 6 additions & 0 deletions gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
@@ -51,11 +51,17 @@ _M.default_environment = 'production'
-- @tfield ?string ca_bundle path to CA store file
-- @tfield ?policy_chain policy_chain @{policy_chain} instance
-- @tfield ?{string,...} nameservers list of nameservers
-- @tfield ?string package.path path to load Lua files
-- @tfield ?string package.cpath path to load libraries
-- @table environment.default_config default configuration
_M.default_config = {
ca_bundle = resty_env.value('SSL_CERT_FILE'),
policy_chain = require('apicast.policy_chain').default(),
nameservers = parse_nameservers(),
package = {
path = package.path,
cpath = package.cpath,
}
}

local mt = { __index = _M }