Installing Custom Plugin with dependencies

I am trying to install a custom plugin which has some dependencies (xml2lua is the dependency I have)

  1. Load the custom plugin code via docker environment variables - This is showing error when Kong starts up stating missing dependencies.

-e “KONG_LUA_PACKAGE_PATH=/plugins/?.lua;;”
-e “KONG_PLUGINS=bundled,event-gen”
-v “./plugins:/plugins” \

  1. I wanted to use a base image and install my custom plugin with dependencies and create a custom image for my use - I am unclear on the steps to do this.

I was able to test the plugin in pongo environment but I am unclear of the installation step where the plugin has some dependency. All the resources I saw online was plugins without dependency.

Any help much appreciated.

rockspec file:

dependencies = {
“xml2lua >= 1.5-2”,
“lua >= 5.1, <= 5.4”,

build = {
type = “builtin”,
modules = {
[“kong.plugins.”…plugin_name…“.handler”] = “kong/plugins/”…plugin_name…“/handler.lua”,
[“kong.plugins.”…plugin_name…“.schema”] = “kong/plugins/”…plugin_name…“/schema.lua”,
[“kong.plugins.”…plugin_name…“.converter”] = “kong/plugins/”…plugin_name…“/converter.lua”,

Hi @JohnWilliams - You have not mentioned Kong version and exact error message you received. However, if it is asking for xml2lua dependencies, use this “luarocks install xml2lua” command while deploying the kong.

you can also use another environment variable "KONG_LOG_LEVEL: “debug” to see the debug logs in the container.

Apart from this, I can see that the environment variable you mentioned above has relative path, not sure this is the cause but still better try to put absolute path like below:

KONG_LUA_PACKAGE_PATH: “/usr/local/kong/custom/?.lua;;”

Hope this will help you

Thanks @Sachin_Ghumbre . I was able to finally create a custom image using the below dockerfile. Thing I missed was the source image should have an environment to install and run commands.

FROM kong/kong-gateway:
USER root
RUN apk update
RUN apk add lua5.1 lua5.1-dev luarocks5.1
RUN apk add gcc expat expat-dev expat-static musl-dev
RUN luarocks install xml2lua 1.5-2
USER kong
WORKDIR /usr/local/share/lua/5.1/kong/plugins
COPY kong/plugins/ ./ #Copy the plugin code from local to docker path

After building this custom image, I was able to start the container by passing this param,

-e “KONG_PLUGINS=bundled,custom-plugin-name”

This Video also gave me some more insight

1 Like

That’s Great news @JohnWilliams . Happy to see that

I see you have already solved your issue, but I’d like to add that there exists another way to manage plugin dependencies: a rockspec. Apart from setting your plugin metadata, you can also use it to list dependencies. If you create a rock from your plugin or use the rockspec to install your plugin, luarocks will automatically install dependencies listed in the rockspec.
For an example rockspec for a Kong plugin see: kong-plugin/kong-plugin-myplugin-0.1.0-1.rockspec at ad362b7235d8d9844a376f557fad003f0138e90e · Kong/kong-plugin · GitHub
For all available options see: Rockspec format · luarocks/luarocks Wiki · GitHub