Skip to content

Commit fe0f08a

Browse files
author
styree
committed
feat(nginx-module) Add support for building lua-kong-nginx-module
The lua-kong-nginx-module nginx module adds support for mTLS amongst other things. I also fixed the openresty version for kong enterprise 1.3. Notably, openresty 1.5.8.1 makes building libpcre a pain openresty/lua-resty-core#258 The workaround is to add some custom linker commands. For now I'm not going to do that, but maybe I'll add some sort of version-specific linker option in the future.
1 parent 0fb7150 commit fe0f08a

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

kong-env.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
logging.basicConfig(level=logging.INFO, format='%(asctime)-15s: %(message)s')
1111
logger = logging.getLogger(__name__)
1212

13-
LIBYAML_HOSTPATH = 'http://pyyaml.org/download/libyaml/'
14-
OPENRESTY_HOSTPATH = 'https://openresty.org/download/'
15-
OPENRESTY_PATCHES_URL = 'https://github.com/Kong/openresty-patches/archive/master.tar.gz'
16-
OPENRESTY_PATCHES_TARBALL = 'master.tar.gz'
17-
OPENSSL_HOSTPATH = 'https://www.openssl.org/source/'
18-
PCRE_HOSTPATH = 'https://ftp.pcre.org/pub/pcre/'
19-
LUAROCKS_HOSTPATH = 'https://luarocks.org/releases/'
13+
LIBYAML_HOSTPATH = 'http://pyyaml.org/download/libyaml/'
14+
LUA_KONG_NGINX_MODULE_REPO = 'https://github.com/Kong/lua-kong-nginx-module'
15+
OPENRESTY_HOSTPATH = 'https://openresty.org/download/'
16+
OPENRESTY_PATCHES_URL = 'https://github.com/Kong/openresty-patches/archive/master.tar.gz'
17+
OPENRESTY_PATCHES_TARBALL = 'master.tar.gz'
18+
OPENSSL_HOSTPATH = 'https://www.openssl.org/source/'
19+
PCRE_HOSTPATH = 'https://ftp.pcre.org/pub/pcre/'
20+
LUAROCKS_HOSTPATH = 'https://luarocks.org/releases/'
2021

2122
CONFIG = {
2223
'0.36' : {
@@ -61,6 +62,9 @@
6162
'kong-community' : {
6263
'version' : '1.3.0'
6364
},
65+
'lua-kong-nginx-module' : {
66+
'version' : '0.0.4'
67+
},
6468
'libyaml' : {
6569
'version' : '0.2.2',
6670
'package' : 'yaml-0.2.2',
@@ -74,10 +78,10 @@
7478
'sha1' : 'f1a9364d31a50bee87765274dde113094337d27b'
7579
},
7680
'openresty' : {
77-
'version' : '1.13.6.2',
78-
'package' : 'openresty-1.13.6.2',
79-
'tarball' : 'openresty-1.13.6.2.tar.gz',
80-
'sha1' : '870055f4698168f1f045de92c467a33361dee5d7',
81+
'version' : '1.15.8.1',
82+
'package' : 'openresty-1.15.8.1',
83+
'tarball' : 'openresty-1.15.8.1.tar.gz',
84+
'sha1' : 'cb8cb132f06c9618bdbe57f5e16f4d9d513a6fe3',
8185
'luajit_version' : '2.1',
8286
'luajit_package' : 'luajit-2.1.0-beta3',
8387
'lua_version' : '5.1'
@@ -205,7 +209,17 @@ def download_and_extract_pcre(environment_directory, tmp_directory, config, verb
205209

206210
return True
207211

208-
def download_and_extract_openresty(environment_directory, tmp_directory, config, pcre_package, verbose):
212+
def download_lua_kong_nginx_module(environment_directory, tmp_directory, lua_kong_nginx_module_config, verbose):
213+
with cd(tmp_directory):
214+
module_version = lua_kong_nginx_module_config['version']
215+
logger.debug('git clone\'ing lua-kong-nginx-module: version=%s' % (module_version))
216+
if not run_command(['git', 'clone', '--branch', module_version, LUA_KONG_NGINX_MODULE_REPO, 'lua-kong-nginx-module'], verbose):
217+
logger.error('unable to clone lua-kong-nginx-module repository: version=%s' % (module_version))
218+
return False
219+
220+
return True
221+
222+
def download_and_extract_openresty(environment_directory, tmp_directory, config, pcre_package, lua_kong_nginx_module_config, verbose):
209223
with cd(tmp_directory):
210224
tarball_url = OPENRESTY_HOSTPATH + config['tarball']
211225
logger.debug('fetching openresty tarball: url=%s directory=%s' % (tarball_url, tmp_directory))
@@ -250,6 +264,9 @@ def download_and_extract_openresty(environment_directory, tmp_directory, config,
250264
'--with-ld-opt="-L' + path.join(environment_directory, 'lib') + '"',
251265
'--with-luajit-xcflags="-DLUAJIT_NUMMODE=2"', '-j8',
252266
'--with-stream_ssl_preread_module', '--with-stream_realip_module']
267+
if lua_kong_nginx_module_config is not None:
268+
shell_command.append('--add-module=' + path.join(tmp_directory, 'lua-kong-nginx-module'))
269+
253270
if not run_command(['sh', '-c', ' '.join(shell_command)], verbose):
254271
logger.error('unable to configure openresty package, exiting: package=%s' % (config['package']))
255272
return False
@@ -460,33 +477,42 @@ def initialize(environment_directory, kong_config, kong_version, verbose):
460477
if not download_and_extract_pcre(environment_directory, tmp_directory, pcre_config, verbose):
461478
sys.exit(1)
462479

480+
lua_kong_nginx_module_config = None
481+
if 'lua-kong-nginx-module' not in kong_config:
482+
logger.info('[5/11] skipping downloading lua-kong-nginx-module')
483+
else:
484+
lua_kong_nginx_module_config = kong_config['lua-kong-nginx-module']
485+
logger.info('[5/11] downloading lua-kong-nginx-module: version=%s' % (lua_kong_nginx_module_config['version']))
486+
if not download_lua_kong_nginx_module(environment_directory, tmp_directory, lua_kong_nginx_module_config, verbose):
487+
sys.exit(1)
488+
463489
openresty_config = kong_config['openresty']
464-
logger.info('[5/11] downloading, compiling and installing openresty: version=%s' % (openresty_config['version']))
465-
if not download_and_extract_openresty(environment_directory, tmp_directory, openresty_config, pcre_config['package'], verbose):
490+
logger.info('[6/11] downloading, compiling and installing openresty: version=%s' % (openresty_config['version']))
491+
if not download_and_extract_openresty(environment_directory, tmp_directory, openresty_config, pcre_config['package'], lua_kong_nginx_module_config, verbose):
466492
sys.exit(1)
467493

468494
luarocks_config = kong_config['luarocks']
469-
logger.info('[6/11] downloading and installing luarocks: version=%s' % (luarocks_config['version']))
495+
logger.info('[7/11] downloading and installing luarocks: version=%s' % (luarocks_config['version']))
470496
if not download_and_extract_luarocks(environment_directory, tmp_directory, luarocks_config,
471497
openresty_config['lua_version'], openresty_config['luajit_version'],
472498
verbose):
473499
sys.exit(1)
474500

475501
libyaml_config = kong_config['libyaml']
476-
logger.info('[7/11] downloading, compiling and installing libyaml: version=%s' % (libyaml_config['version']))
502+
logger.info('[8/11] downloading, compiling and installing libyaml: version=%s' % (libyaml_config['version']))
477503
if not download_and_extract_libyaml(environment_directory, tmp_directory, libyaml_config, verbose):
478504
sys.exit(1)
479505

480506
kong_community_config = kong_config['kong-community']
481-
logger.info('[8/10] installing kong community luarock: version=%s' % (kong_community_config['version']))
507+
logger.info('[9/11] installing kong community luarock: version=%s' % (kong_community_config['version']))
482508
if not install_kong_luarock(environment_directory, kong_community_config, verbose):
483509
sys.exit(1)
484510

485-
logger.info('[9/10] creating activation scripts')
511+
logger.info('[10/11] creating activation scripts')
486512
if not create_activation_scripts(environment_directory, kong_version, openresty_config['lua_version'], openresty_config['luajit_package']):
487513
sys.exit(1)
488514

489-
logger.info('[10/10] cleaning up temp directory')
515+
logger.info('[11/11] cleaning up temp directory')
490516
if not cleanup_directory(tmp_directory, verbose):
491517
sys.exit(1)
492518

0 commit comments

Comments
 (0)