Skip to content

Commit

Permalink
Fix potential load conflicts with other Lua libraries on the system.
Browse files Browse the repository at this point in the history
No longer include the default paths in the lua load paths. This ensures
we load our dependencies in isolation of any other lua libraries that
might be installed on the same system.

See: #250
  • Loading branch information
GUI committed Jun 15, 2016
1 parent f9db54a commit 213946c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
23 changes: 23 additions & 0 deletions bin/api-umbrella
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ if [ -z "$API_UMBRELLA_EMBEDDED_ROOT" ]; then
fi
fi

# Set the path for binaries.
export PATH=$API_UMBRELLA_EMBEDDED_ROOT/sbin:$API_UMBRELLA_EMBEDDED_ROOT/bin:$PATH

# Set the Lua load paths to include the vendored app dependencies and the
# embedded openresty installation.
#
# Note that we purposefully don't use any of the default Lua load paths (like
# /usr/local) so that other Lua packages on the system aren't picked up (since
# they might conflict).
export LUA_PATH="$API_UMBRELLA_EMBEDDED_ROOT/apps/core/shared/vendor/share/lua/5.1/?.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/apps/core/shared/vendor/share/lua/5.1/?/init.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/lualib/?.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/lualib/?/init.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/luajit/share/luajit-2.1.0-beta1/?.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/luajit/share/luajit-2.1.0-beta1/?/init.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/luajit/share/lua/5.1/?.lua;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/luajit/share/lua/5.1/?/init.lua"
if [ -n "$API_UMBRELLA_SRC_ROOT" ]; then
export LUA_PATH="$API_UMBRELLA_SRC_ROOT/src/?.lua;$LUA_PATH"
fi
export LUA_CPATH="$API_UMBRELLA_EMBEDDED_ROOT/apps/core/shared/vendor/lib/lua/5.1/?.so;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/lualib/?.so;\
$API_UMBRELLA_EMBEDDED_ROOT/openresty/luajit/lib/lua/5.1/?.so"

# Run the Lua CLI app.
exec $API_UMBRELLA_SRC_ROOT/bin/api-umbrella-cli "$@"
24 changes: 0 additions & 24 deletions bin/api-umbrella-cli
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
#!/usr/bin/env luajit

local embedded_root = os.getenv("API_UMBRELLA_EMBEDDED_ROOT")
if embedded_root then
package.path =
embedded_root .. "/apps/core/shared/vendor/share/lua/5.1/?.lua;" ..
embedded_root .. "/apps/core/shared/vendor/share/lua/5.1/?/init.lua;" ..
embedded_root .. "/openresty/lualib/?.lua;" ..
embedded_root .. "/openresty/lualib/?/init.lua;" ..
embedded_root .. "/openresty/luajit/share/luajit-2.1.0-beta1/?.lua;" ..
embedded_root .. "/openresty/luajit/share/luajit-2.1.0-beta1/?/init.lua;" ..
embedded_root .. "/openresty/luajit/share/lua/5.1/?.lua;" ..
embedded_root .. "/openresty/luajit/share/lua/5.1/?/init.lua;" ..
package.path
package.cpath =
embedded_root .. "/apps/core/shared/vendor/lib/lua/5.1/?.so;" ..
embedded_root .. "/openresty/lualib/?.so;" ..
embedded_root .. "/openresty/luajit/lib/lua/5.1/?.so;" ..
package.cpath
end

local src_root = os.getenv("API_UMBRELLA_SRC_ROOT")
if src_root then
package.path = src_root .. "/src/?.lua;" .. package.path
end

local cli = require "api-umbrella.cli"
cli()

0 comments on commit 213946c

Please sign in to comment.