本地部署 Kong 中如何安装自定义插件

我创建了一个自定义的 kong 插件,并尝试在本地部署。 我已经尝试使用 Luarocks、Pongo 和手动方式,但无法让它工作。

以下是我遵循的步骤。

命令

luarocks make

日志

kong-check-x-header 1.0-1 依赖于 lua ~> 5.1(VM 提供了 5.1-1),kong-check-x-header 1.0-1 现在已安装于 /usr/local/Cellar/openresty@1.19.3.2/1.19.3.2/luarocks(许可证:Apache 2.0)

命令

luarocks pack kong-check-x-header 1.0-1

日志

Packed: /Users/jaikratsinghtariyal/Sandbox/kong-check-x-header/kong-check-x-header-1.0-1.all.rock

命令

luarocks install kong-check-x-header-1.0-1.all.rock

日志

kong-check-x-header 1.0-1 依赖于 lua ~> 5.1(VM 提供了 5.1-1)

错误:/usr/local/Cellar/openresty@1.19.3.2/1.19.3.2/luarocks/lib/luarocks/rocks-5.1/kong-check-x-header/1.0-1/lua/kong/plugins/kong-check-x-header/schema.lua: No such file or directory

已经过了好几天了......还在苦苦挣扎......这里需要一些帮助。

GITHUB - https://github.com/jaikratsinghtariyal/kong-check-x-header

经过评论更新

以下是按顺序执行的命令:

  • pongo pack

日志 -

Creating kong-pongo_kong_run ... done

kong-plugin-check-x-header 1.0-1 依赖于 lua ~> 5.1(VM 提供了 5.1-1
Stopping after installing dependencies for kong-plugin-check-x-header 1.0-1

Kong version: 2.5.0

kong-plugin-check-x-header 1.0-1 依赖于 lua ~> 5.1(VM 提供了 5.1-1
kong-plugin-check-x-header 1.0-1 现在已安装于 /usr/local(许可证:Apache 2.0

Packed: /kong-plugin/kong-plugin-check-x-header-1.0-1.all.rock

`

  • pongo shell
  • luarocks install /kong-plugin/kong-plugin-check-x-header-1.0-1.all.rock

日志:-

kong-plugin-check-x-header 1.0-1 依赖于 lua ~> 5.1(VM 提供了 5.1-1)
kong-plugin-check-x-header 1.0-1 现在已安装于 /usr/local(许可证:Apache 2.0
  • export KONG_PLUGINS=bundled,kong-plugin-check-x-header (我应该提到 kong-plugin-check-x-header 还是 check-x-header...实际上我都尝试过,但都失败了,但错误信息更有希望)
  • kong migrations bootstrap
  • kong start

除了 kong start 命令之外,所有命令都有效。

日志 -

错误:
/usr/local/share/lua/5.1/kong/cmd/start.lua:75: /usr/local/share/lua/5.1/kong/cmd/start.lua:64: nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:515: error loading plugin schemas: on plugin 'kong-plugin-check-x-header': kong-plugin-check-x-header plugin is enabled but not installed;
no plugin found
stack traceback:
    [C]: in function 'assert'
    /usr/local/share/lua/5.1/kong/init.lua:515: in function 'init'
    init_by_lua:3: in main chunk

stack traceback:
    [C]: in function 'error'
    /usr/local/share/lua/5.1/kong/cmd/start.lua:75: in function 'cmd_exec'
    /usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:88>
    [C]: in function 'xpcall'
    /usr/local/share/lua/5.1/kong/cmd/init.lua:88: in function </usr/local/share/lua/5.1/kong/cmd/init.lua:45>
    /kong/bin/kong:9: in function 'file_gen'
    init_worker_by_lua:47: in function <init_worker_by_lua:45>
    [C]: in function 'xpcall'
    init_worker_by_lua:54: in function <init_worker_by_lua:52>

原文链接 https://stackoverflow.com/questions/69085647

点赞
stackoverflow用户4605105
stackoverflow用户4605105

将 pongo 应用到项目中,需要注意文件路径和插件名称的命名规则

kong-check-x-header 应当改为 kong-plugin-check-x-header

并将文件放到正确的目录下

kong/plugins/check-x-header/

在具体规范文件中,check-x-header 应当变为 kong-check-header-x

建议使用类似于 pongo lint 的校验工具来检测问题。例如,应当避免使用 X-Auth-Token 作为键的名称,而应当使用 X_Auth_Token

2021-09-07 11:22:32