From f48e62c5bff5b86921a1952d67e313bb70952832 Mon Sep 17 00:00:00 2001 From: Michael Martin <3277009+flrgh@users.noreply.github.com> Date: Wed, 6 Apr 2022 09:49:52 -0700 Subject: [PATCH] feat(openresty) bundle Kong/lua-resty-websocket This adds Kong's fork of lua-resty-websocket to kong-ngx-build. This is opt-in for now but expected to be standard later on. --- Makefile | 3 +++ build-openresty.sh | 7 ++++++ dockerfiles/Dockerfile.openresty | 3 +++ openresty-build-tools/kong-ngx-build | 35 ++++++++++++++++++++++++++++ test/tests/01-package/run.sh | 4 ++++ 5 files changed, 52 insertions(+) diff --git a/Makefile b/Makefile index b782aaac..dc91b106 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ KONG_GMP_VERSION ?= `grep KONG_GMP_VERSION $(KONG_SOURCE_LOCATION)/.requirements KONG_NETTLE_VERSION ?= `grep KONG_NETTLE_VERSION $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'` KONG_NGINX_MODULE ?= `grep KONG_NGINX_MODULE $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'` RESTY_LMDB ?= `grep RESTY_LMDB $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'` +RESTY_WEBSOCKET ?= `grep RESTY_WEBSOCKET $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'` LIBYAML_VERSION ?= `grep LIBYAML_VERSION $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'` OPENRESTY_PATCHES ?= 1 DOCKER_KONG_VERSION = 'master' @@ -109,6 +110,7 @@ debug: @echo ${DEBUG} @echo ${KONG_NGINX_MODULE} @echo ${RESTY_LMDB} + @echo ${RESTY_WEBSOCKET} setup-ci: setup-build @@ -166,6 +168,7 @@ else --build-arg KONG_NETTLE_VERSION=$(KONG_NETTLE_VERSION) \ --build-arg KONG_NGINX_MODULE=$(KONG_NGINX_MODULE) \ --build-arg RESTY_LMDB=$(RESTY_LMDB) \ + --build-arg RESTY_WEBSOCKET=$(RESTY_WEBSOCKET) \ --build-arg OPENRESTY_PATCHES=$(OPENRESTY_PATCHES) \ --build-arg DEBUG=$(DEBUG) \ -t $(DOCKER_REPOSITORY):openresty-$(PACKAGE_TYPE)-$(DOCKER_OPENRESTY_SUFFIX) . ) diff --git a/build-openresty.sh b/build-openresty.sh index cae70287..e0e0f175 100755 --- a/build-openresty.sh +++ b/build-openresty.sh @@ -44,6 +44,12 @@ then RESTY_LMDB=0 fi +if [ -z "$RESTY_WEBSOCKET" ] +then + RESTY_WEBSOCKET=0 +fi + + LUAROCKS_PREFIX=/usr/local \ LUAROCKS_DESTDIR=/tmp/build \ OPENRESTY_PREFIX=/usr/local/openresty \ @@ -57,6 +63,7 @@ EDITION=$EDITION \ --openresty $RESTY_VERSION \ --openssl $RESTY_OPENSSL_VERSION \ --resty-lmdb $RESTY_LMDB \ +--resty-websocket $RESTY_WEBSOCKET \ --luarocks $RESTY_LUAROCKS_VERSION \ --kong-nginx-module $KONG_NGINX_MODULE \ --pcre $RESTY_PCRE_VERSION \ diff --git a/dockerfiles/Dockerfile.openresty b/dockerfiles/Dockerfile.openresty index fb9e002c..980a9326 100644 --- a/dockerfiles/Dockerfile.openresty +++ b/dockerfiles/Dockerfile.openresty @@ -81,6 +81,9 @@ LABEL resty_luarocks_version="${RESTY_LUAROCKS_VERSION}" ARG RESTY_LMDB=0 LABEL resty_lmdb="${RESTY_LMDB}" +ARG RESTY_WEBSOCKET=0 +LABEL resty_websocket="${RESTY_WEBSOCKET}" + COPY openresty-build-tools /tmp/openresty-build-tools COPY openresty-patches /tmp/openresty-patches COPY build-openresty.sh /tmp/build-openresty.sh diff --git a/openresty-build-tools/kong-ngx-build b/openresty-build-tools/kong-ngx-build index 7b917a25..83b6eab3 100755 --- a/openresty-build-tools/kong-ngx-build +++ b/openresty-build-tools/kong-ngx-build @@ -15,6 +15,7 @@ FORCE=0 OPENRESTY_PATCHES=$OPENRESTY_PATCHES KONG_NGINX_MODULE=master RESTY_LMDB=master +RESTY_WEBSOCKET=${RESTY_WEBSOCKET:-0} DEBUG=0 NPROC= OS= @@ -96,6 +97,10 @@ main() { RESTY_LMDB=0 shift 1 ;; + --resty-websocket) + RESTY_WEBSOCKET=$2 + shift 1 + ;; -f|--force) FORCE=1 shift 1 @@ -280,6 +285,23 @@ main() { rm -f lua-resty-dns-0.21.tar.gz popd fi + + if [[ $RESTY_WEBSOCKET != 0 ]]; then + pushd openresty-$OPENRESTY_VER/bundle + if ! rm -rf lua-resty-websocket-*; then + fatal "Failed to find/remove upstream lua-resty-websocket component" + fi + mkdir "lua-resty-websocket-${RESTY_WEBSOCKET}" + notice "Downloading Kong/lua-resty-websocket $RESTY_WEBSOCKET" + curl -sSL \ + -o lua-resty-websocket.tar.gz \ + "https://github.com/Kong/lua-resty-websocket/archive/refs/tags/${RESTY_WEBSOCKET}.tar.gz" + tar -xzf lua-resty-websocket.tar.gz \ + -C "lua-resty-websocket-${RESTY_WEBSOCKET}" \ + --strip-components 1 + rm -f lua-resty-websocket.tar.gz + popd + fi fi fi @@ -388,6 +410,16 @@ main() { pushd $OPENRESTY_DOWNLOAD/bundle if [ ! -f .patch_applied ]; then for patch_file in $(ls -1 $OPENRESTY_PATCHES_DIR/patches/$OPENRESTY_VER/*.patch); do + # any existing patch files will surely conflict with our fork of + # lua-resty-websocket, so skip them if bundling Kong/lua-resty-websocket + if + [[ $RESTY_WEBSOCKET != 0 ]] && + [[ "$(basename "$patch_file")" = lua-resty-websocket-* ]] + then + notice "Skipping lua-resty-websocket patch: $patch_file" + continue + fi + notice "Applying OpenResty patch $patch_file" patch -p1 < $patch_file \ || fatal "failed to apply patch: $patch_file" @@ -812,6 +844,9 @@ show_usage() { echo " --resty-lmdb Specify a lua-resty-lmdb branch to use when patching and compiling." echo " (Defaults to \"master\")" echo "" + echo " --resty-websocket Specify a Kong/lua-resty-websocket tag to install in place of the" + echo " bundled version of lua-resty-websocket (Defaults to \"$RESTY_WEBSOCKET\")" + echo "" echo " --luarocks Version of LuaRocks to build, such as 3.1.2. If absent, LuaRocks" echo " will not be built." echo "" diff --git a/test/tests/01-package/run.sh b/test/tests/01-package/run.sh index 82fd8596..89b173e4 100644 --- a/test/tests/01-package/run.sh +++ b/test/tests/01-package/run.sh @@ -97,6 +97,10 @@ docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "ldd / docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "ldd /usr/local/openresty/bin/openresty | grep -q /usr/local/openresty/luajit/lib/libluajit-5.1.so.2" docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "/usr/local/openresty/bin/openresty -V 2>&1 | grep /work/pcre-${RESTY_PCRE_VERSION}" +# lua-resty-websocket library (sourced from OpenResty or Kong/lua-resty-websocket) +docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "ls -l /usr/local/openresty/lualib/resty/websocket/*.lua" +docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "grep _VERSION /usr/local/openresty/lualib/resty/websocket/*.lua" + # luarocks docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "luarocks --version | grep -q ${RESTY_LUAROCKS_VERSION}" docker run ${USE_TTY} --user=root --rm ${KONG_TEST_IMAGE_NAME} /bin/sh -c "luarocks config | grep -q /usr/local/openresty/luajit/bin/luajit"