Recently, the computer was updated, and the M1 was replaced. All work started again, which means that the stumbling block in the development of APISIX plug-ins - the preparation of the single test environment, must be re-prepared.
Due to the upgrade of the chip and the latest macOS system (12.2.1), the process did not go as smoothly as expected. The pits that have not been encountered before have been exposed one by one. Here is a sharing and BackUp.
I also want to complain about the official documentation of APISIX. Regarding the content of unit testing and plug-in writing, the output is not particularly large, and it is scattered everywhere, which really brings trouble to developers.
The following operations are all based on the APISIX source code ( https://github.com/apache/apisix ), and the version at the time of writing this article is V2.12.1.
normal installation process
- Install various environment dependencies
# install OpenResty, etcd and some compilation tools
brew install openresty/brew/openresty luarocks lua@5.1 etcd curl git pcre openldap cpanminus
# start etcd server
brew services start etcd
The script is provided in the official latest source code, located at utils/install-dependencies.sh
. Execute this script directly to install and start the above dependencies.
- Modify environment variables
Modify the .bash_profile
file according to the actual installation situation, and don't forget source ~/.bash_profile
.
OPENRESTY_HOME=/usr/local/openresty
PATH=$OPENRESTY_HOME/nginx/sbin:$OPENRESTY_HOME/bin:$PATH
export OPENRESTY_HOME
- Download APISIX source code
git clone https://github.com/apache/apisix.git
- Processing in source code environment
# 源码根目录下
git clone https://github.com/iresty/test-nginx.git
rm -rf test-nginx/.git
sudo cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
export PERL5LIB=.:$PERL5LIB
make deps
I see the official recommendation to use make deps ENV_LUAROCKS_SERVER=https://luarocks.cn
, but I tried it, and it didn't work, I still use https://luarocks.org , and later I modified the luarocks configuration file ~/.luarocks/config-5.1.lua
, it took effect, you can also try it yourself, in the article Give feedback below.
rocks_servers = {
"https://luarocks.cn"
}
Due to the network reasons of github, the process of make deps
may not be smooth sailing. It is enough to be patient and try a few more times.
- Download the toolkit file
In the t/
directory, execute
git clone https://github.com/api7/test-toolkit toolkit
rm -rf toolkit/.git
It needs to be renamed to toolkit, otherwise the reference cannot be found.
If you do not download the source code here, it will cause the problem that toolkit.json
cannot be found.
https://github.com/apache/apisix/issues/2936
- Start the APISIX service (not necessary, it can be based on the actual situation)
I started it through Docker
git clone https://github.com/apache/apisix-docker.git
cd apisix-docker/compose/
docker-compose -f docker-compose.yaml -p docker-apisix up -d
📢 Note that we have already started etcd above, and etcd will also be started here, so just choose one of them.
- have a test
In the source root directory, execute
prove -Itest-nginx/lib -r t/plugin/limit-conn.t
Under normal circumstances, this can be started.
But the reality is not so smooth, and the above process is already the result of my pit mining.
Problems and Solutions
Unable to use brew to install openresty under the latest version
% brew install openresty/brew/openresty
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 10 formulae.
==> Tapping openresty/brew
Cloning into '/opt/homebrew/Library/Taps/openresty/homebrew-brew'...
remote: Enumerating objects: 2866, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 2866 (delta 22), reused 10 (delta 6), pack-reused 2832
Receiving objects: 100% (2866/2866), 627.61 KiB | 638.00 KiB/s, done.
Resolving deltas: 100% (1610/1610), done.
Error: Invalid formula: /opt/homebrew/Library/Taps/openresty/homebrew-brew/Formula/php-session-nginx-module.rb
php-session-nginx-module: Calling bottle :unneeded is disabled! There is no replacement.
Please report this issue to the openresty/brew tap (not Homebrew/brew or Homebrew/core):
/opt/homebrew/Library/Taps/openresty/homebrew-brew/Formula/php-session-nginx-module.rb:8
The official solution is to brew the version. https://github.com/openresty/openresty/issues/814
and I chose to install openresty manually
tar -xzvf openresty-VERSION.tar.gz
// openresty-VERSION/ 目录
./configure --prefix=/usr/local/openresty --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module --with-pcre=/Users/demo/installapps/pcre-8.45 --with-openssl=/Users/demo/installapps/openssl
make
make install
Installing openresty requires pcre and openssl, so we also have to install it manually
- openssl:https://blog.csdn.net/qyee16/article/details/72799852
- pcre:https://www.cnblogs.com/Jordandan/p/10402912.html
It should be noted here that pcre should use 1, not 2, otherwise there will be the following problems
src/core/ngx_regex.h:15:10: fatal error: 'pcre.h' file not found
#include <pcre.h>
^~~~~~~~
1 error generated.
make[1]: *** [objs/src/core/nginx.o] Error 1
make: *** [install] Error 2
Don't forget to modify the environment variables.
Path not found when make deps
It can be solved by using the ln -s
soft link.
nginx error
When running a single test, the following error is reported
nginx: [emerg] "listen" directive is not allowed here in /Users/gjason/project/apisix-all/apisix/t/servroot/conf/nginx.conf:188
It may be that the data format is wrong and the nginx.conf configuration is wrong.
It may also be that Nginx is not installed properly, such as the lack of pcre and openssl mentioned above.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。