Kong / kong-python-pdk

Write Kong plugins in Python (Experimental)
Apache License 2.0
40 stars 14 forks source link

Working Python plugin in Alpine fails when switching to Kong Ubuntu #129

Closed shawnchapla-8451 closed 10 months ago

shawnchapla-8451 commented 10 months ago

I have a bespoke Python plugin that works when running with Kong 3.1.1 in an Alpine container, but switching to same Kong version on Ubuntu, it gets this error at startup:

2023/08/17 18:09:30 [debug] 1#0: [kong] process.lua:66 search config for pluginserver named: python-plugin
sh: 1: /usr/bin/kong-python-pluginserver: not found
2023/08/17 18:09:30 [error] 1#0: init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:150: Not a plugin info table: 
/usr/bin/kong-python-pluginserver --no-lua-style --plugins-directory /usr/local/kong/python/ --dump-all-plugins

stack traceback:
    [C]: in function 'error'
    ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:150: in function 'ask_info'
    ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:169: in function 'get_plugin_info'
    ...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:338: in function 'get_plugin'
    ...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:346: in function 'load_plugin'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:156: in function 'load_plugin_handler'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:260: in function 'load_plugin'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:312: in function 'load_plugin_schemas'
    /usr/local/share/lua/5.1/kong/init.lua:593: in function 'init'
    init_by_lua:3: in main chunk
nginx: [error] init_by_lua error: ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:150: Not a plugin info table: 
/usr/bin/kong-python-pluginserver --no-lua-style --plugins-directory /usr/local/kong/python/ --dump-all-plugins

stack traceback:
    [C]: in function 'error'
    ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:150: in function 'ask_info'
    ...al/share/lua/5.1/kong/runloop/plugin_servers/process.lua:169: in function 'get_plugin_info'
    ...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:338: in function 'get_plugin'
    ...local/share/lua/5.1/kong/runloop/plugin_servers/init.lua:346: in function 'load_plugin'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:156: in function 'load_plugin_handler'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:260: in function 'load_plugin'
    /usr/local/share/lua/5.1/kong/db/dao/plugins.lua:312: in function 'load_plugin_schemas'
    /usr/local/share/lua/5.1/kong/init.lua:593: in function 'init'
    init_by_lua:3: in main chunk

This is the Dockerfile for Alpine (we also have some bespoke Lua plugins but I've removed the references for that for brevity):

FROM kong:3.1.1-alpine
USER root
RUN update-ca-certificates && \
    apk update

# Add the Python dependencies and the Python PDK dependency
RUN apk add python3 py3-pip python3-dev musl-dev libffi-dev gcc g++ file make && \
    PYTHONWARNINGS=ignore pip3 install kong-pdk requests jinja2 pyyaml
# Copy the plugin code
COPY --chown=kong --chmod=555 oas-server/python/oas-server.py oas-server/python/swagger.tmpl /usr/local/kong/python/
USER kong

And this is the Ubuntu Dockerfile:

FROM kong:3.1.1-ubuntu
USER root
RUN apt update && \
    apt install -y ca-certificates && \
    update-ca-certificates && \
    apt install -y python3 python3-pip python3-dev musl-dev libffi-dev gcc g++ file make && \
    PYTHONWARNINGS=ignore pip3 install kong-pdk requests jinja2 pyyaml

COPY --chown=kong --chmod=555 oas-server/python/oas-server.py oas-server/python/swagger.tmpl /usr/local/kong/python/
USER kong

The env settings in the Kong startup command are the same for both:

      - KONG_PLUGINS=bundled,oas-server
      - KONG_PLUGINSERVER_NAMES=python-plugin
      - KONG_PLUGINSERVER_PYTHON_PLUGIN_SOCKET=/usr/local/kong/python_pluginserver.sock
      - KONG_PLUGINSERVER_PYTHON_PLUGIN_START_CMD=/usr/bin/kong-python-pluginserver --no-lua-style --plugins-directory /usr/local/kong/python/
      - KONG_PLUGINSERVER_PYTHON_PLUGIN_QUERY_CMD=/usr/bin/kong-python-pluginserver --no-lua-style --plugins-directory /usr/local/kong/python/ --dump-all-plugins

I can confirm that the kong-pdk modules are installed in the image. Is there something specific about using the Python PDK on Ubuntu?

shawnchapla-8451 commented 10 months ago

Actually, I found out the issue ... evidently on the Ubuntu image, the executable kong-python-pluginserver is located in /usr/local/bin, not /usr/bin as on Alpine. :-\