diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 25dbfe41ba9a..5bcb28ab750c 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -174,7 +174,10 @@ kong_directory_genrule( fi done LN ${BUILD_DESTDIR}/openresty/nginx/sbin/nginx ${BUILD_DESTDIR}/openresty/bin/openresty - """, + """ + """ + # Make INSTALL_DESTDIR available to Kong Lua code + echo 'return "%s/kong"' > ${BUILD_DESTDIR}/share/lua/5.1/kong/kong_usr_path.lua + """ % KONG_VAR["INSTALL_DESTDIR"], # XXX: bazel forces 0555 as artifact permission, which is not correct for packagin # here we deliberately use a different directory so file permission is preserved # see also https://github.com/bazelbuild/bazel/issues/5588 diff --git a/kong/cmd/utils/prefix_handler.lua b/kong/cmd/utils/prefix_handler.lua index 189c3a03981c..2be0ae452d11 100644 --- a/kong/cmd/utils/prefix_handler.lua +++ b/kong/cmd/utils/prefix_handler.lua @@ -828,7 +828,11 @@ local function prepare_prefix(kong_config, nginx_custom_template_path, skip_writ end if kong_config.admin_gui_listeners then - prepare_prefixed_interface_dir("/usr/local/kong", "gui", kong_config) + -- kong.kong_usr_path is an AUTO GENERATED Lua module generated by BUILD.bazel + -- It's only used for locating the GUI directory under Kong's USR path + -- The module itself DOES NOT exist under /kong + local kong_usr_path_ok, kong_usr_path = pcall(require, "kong.kong_usr_path") + prepare_prefixed_interface_dir(kong_usr_path_ok and kong_usr_path or "/usr/local/kong", "gui", kong_config) end if secrets then