Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

I am curious how to recognize the external folder path of customs plugin. #145

Closed
youngkiu opened this issue Jun 12, 2020 · 9 comments
Closed

Comments

@youngkiu
Copy link

youngkiu commented Jun 12, 2020

-some_dir
  |-kong-vagrant
     |-kong
     |-kong-plugin

When the directory structure is the same as above,

$ export KONG_PLUGINS=bundled,myplugin

Although it is said to set environment variables,

  • kong
    • host: some_dir/kong-vagrant/kong/kong/plugins/myplugin/
    • guest: /kong/kong/plugins/myplugin/
  • kong-plugin
    • host: some_dir/kong-vagrant/kong-plugin/kong/plugins/myplugin/
    • guest: /kong-plugin/kong/plugins/myplugin/

How to recognize the folder path of customs plugin
located in external folder(kong-plugin/kong/plugins/myplugin/) of kong,
not located in subfolder(kong/kong/plugins/myplugin/) of kong?

@youngkiu
Copy link
Author

Using https://github.com/eyolas/kong-plugin-referer.git instead of https://github.com/Kong/kong-plugin,
I experimented as follows, but an error occurs.

$ git clone https://github.com/Kong/kong-vagrant
$ cd kong-vagrant
$ git clone https://github.com/Kong/kong
$ git clone https://github.com/eyolas/kong-plugin-referer.git
$ mv kong-plugin-referer kong-plugin # for Vagrantfile
$ vagrant up
$ vagrant ssh
$ cd /kong
$ make dev
$ export KONG_PLUGINS=bundled,referer
$ cd /kong
$ bin/kong migrations bootstrap
$ bin/kong start
$ curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=referer" \
    --data "config.referers=mockbin.com, *.mockbin.com"
HTTP/1.1 400 Bad Request
Date: Fri, 12 Jun 2020 08:35:25 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/2.0.4
Content-Length: 249
X-Kong-Admin-Latency: 221

{"message":"schema violation (name: plugin ' referer' not enabled; add it to the 'plugins' configuration property)","name":"schema violation","fields":{"name":"plugin ' referer' not enabled; add it to the 'plugins' configuration property"},"code":2}

@niaomingjian
Copy link

I think the custom plugin hasn't been installed in the system, so it couldn't be recognized by kong.
Using luarocks to install it as follows:

 $ cd kong-plugin
 $ luarocks make

Refer to https://docs.konghq.com/2.0.x/plugin-development/distribution/#installing-the-plugin

@Tieske
Copy link
Member

Tieske commented Jul 16, 2020

It should not need to be installed in this enviornment, since the mapped folder /kong-plugin is already in the Lua path, so Kong should pick it up

$ vagrant ssh
vagrant@ubuntu-bionic:/kong$ printenv | grep LUA_
LUA_PATH=/kong/?.lua;/kong/?/init.lua;/kong-plugin/?.lua;/kong-plugin/?/init.lua;;
vagrant@ubuntu-bionic:/kong$

@Tieske
Copy link
Member

Tieske commented Jul 16, 2020

@youngkiu your post doesn't make sense?

curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=referer" \
    --data "config.referers=mockbin.com, *.mockbin.com"

the above still has "/apis/" which has been deprecated, and also placeholders {api}, so that is not what you executed

If you are working with an older version of Kong, make sure the installed version matches the source code in the repo

export MY_VERSION=1.3.1

# checkout the right source version
git clone https://github.com/Kong/kong
cd kong
git checkout $MY_VERSION
cd ..

# build vagrant box with the corresponding Kong binaries
KONG_VERSION=$MY_VERSION vagrant up

also there is a variable for the plugin source, so instead of;

$ git clone https://github.com/eyolas/kong-plugin-referer.git
$ mv kong-plugin-referer kong-plugin # for Vagrantfile
$ vagrant up

you can do:

git clone https://github.com/eyolas/kong-plugin-referer.git
KONG_PLUGIN_PATH=./kong-plugin-referer vagrant up

See docs here: https://github.com/Kong/kong-vagrant#environment-variables-and-configuration

@youngkiu
Copy link
Author

Thank you for the very kind explanation.
$ mv kong-plugin-referer kong-plugin # for Vagrantfile
Without executing the above command, I understood what would be like below.
KONG_PLUGIN_PATH=./kong-plugin-referer vagrant up

However, the expected LUA-related environment variables were not seen.
$ vagrant ssh vagrant@ubuntu-bionic:~$ printenv LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36: SSH_CONNECTION=10.0.2.2 59109 10.0.2.15 22 LESSCLOSE=/usr/bin/lesspipe %s %s LANG=C.UTF-8 XDG_SESSION_ID=5 USER=vagrant PWD=/home/vagrant HOME=/home/vagrant LC_TERMINAL=iTerm2 SSH_CLIENT=10.0.2.2 59109 22 LC_TERMINAL_VERSION=3.3.12 XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop SSH_TTY=/dev/pts/0 MAIL=/var/mail/vagrant TERM=xterm-256color SHELL=/bin/bash SHLVL=1 LOGNAME=vagrant XDG_RUNTIME_DIR=/run/user/1000 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin LESSOPEN=| /usr/bin/lesspipe %s _=/usr/bin/printenv

@youngkiu
Copy link
Author

kong-vagrant: 6e789de (HEAD -> master, tag: 2.0.4) chore(*) bump Kong to 2.0.4
kong: f37b6516 (HEAD -> master) fix(go) reload killed plugin instance

I was using the revision shown above, but I updated it to the revision shown below.
However, even after, LUA-related environment variables were not seen.

kong-vagrant: 5f8bd87 (HEAD -> master, origin/master, origin/HEAD) fix(readme) fix example curl command in README.md (#161)
kong: 4c1a1ea8 (HEAD -> master, origin/master, origin/HEAD) chore(docs) drop "development", no longer relevant (#6499)

@youngkiu
Copy link
Author

youngkiu commented Oct 24, 2020

I found LUA_PATH in the provision.sh file.
# Adjust LUA_PATH to find the source and plugin dev setup
echo "export LUA_PATH=\"/kong/?.lua;/kong/?/init.lua;/kong-plugin/?.lua;/kong-plugin/?/init.lua;;\"" >> /home/vagrant/.bash_profile

Then, I ran the following command.
$ vagrant provision

It seems to be fully installed now.
$ vagrant ssh
vagrant@ubuntu-bionic:~$ printenv | grep LUA
LUA_PATH=/kong/?.lua;/kong/?/init.lua;/kong-plugin/?.lua;/kong-plugin/?/init.lua;;

Sorry for the late reply.

@zffocussss
Copy link

vagrant

what's the difference between vagrant provision and vagrant provision?

@Tieske
Copy link
Member

Tieske commented Sep 7, 2021

@zffocussss sorry I didn't get your question? can you elaborate?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants