Skip to content

Commit

Permalink
feat(kong-ngx-build) add atc-router library build support
Browse files Browse the repository at this point in the history
This requires rust compiler. It can be installed easily with `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`.
  • Loading branch information
dndx authored Jul 13, 2022
1 parent 0ca9c49 commit 80b87eb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ KONG_NETTLE_VERSION ?= `grep KONG_NETTLE_VERSION $(KONG_SOURCE_LOCATION)/.requir
KONG_NGINX_MODULE ?= `grep KONG_NGINX_MODULE $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
RESTY_EVENTS ?= `grep RESTY_EVENTS $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
RESTY_LMDB ?= `grep RESTY_LMDB $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
ATC_ROUTER ?= `grep ATC_ROUTER $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
LIBYAML_VERSION ?= `grep ^LIBYAML_VERSION $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
RESTY_WEBSOCKET ?= `grep RESTY_WEBSOCKET $(KONG_SOURCE_LOCATION)/.requirements | awk -F"=" '{print $$2}'`
OPENRESTY_PATCHES ?= 1
Expand Down Expand Up @@ -196,6 +197,7 @@ else
--build-arg RESTY_LMDB=$(RESTY_LMDB) \
--build-arg RESTY_WEBSOCKET=$(RESTY_WEBSOCKET) \
--build-arg RESTY_EVENTS=$(RESTY_EVENTS) \
--build-arg ATC_ROUTER=$(ATC_ROUTER) \
--build-arg OPENRESTY_PATCHES=$(OPENRESTY_PATCHES) \
--build-arg DEBUG=$(DEBUG) \
--build-arg BUILDKIT_INLINE_CACHE=1 \
Expand Down
6 changes: 6 additions & 0 deletions build-openresty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ then
RESTY_EVENTS=0
fi

if [ -z "$ATC_ROUTER" ]
then
ATC_ROUTER=0
fi

LUAROCKS_PREFIX=/usr/local \
LUAROCKS_DESTDIR=/tmp/build \
OPENRESTY_PREFIX=/usr/local/openresty \
Expand All @@ -69,6 +74,7 @@ EDITION=$EDITION \
--resty-lmdb $RESTY_LMDB \
--resty-websocket $RESTY_WEBSOCKET \
--resty-events $RESTY_EVENTS \
--atc-router $ATC_ROUTER \
--luarocks $RESTY_LUAROCKS_VERSION \
--kong-nginx-module $KONG_NGINX_MODULE \
--pcre $RESTY_PCRE_VERSION \
Expand Down
6 changes: 6 additions & 0 deletions dockerfiles/Dockerfile.openresty
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ RUN curl -fsSLo /tmp/yaml-${LIBYAML_VERSION}.tar.gz https://pyyaml.org/download/
&& make install \
&& rm -rf /tmp/yaml-${LIBYAML_VERSION}

# `rustc` for atc-router
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

COPY kong/.requirements kong/distribution/ /distribution/
WORKDIR /distribution
RUN if [ -f "/distribution/pre-install.sh" ] ; then ./pre-install.sh; fi
Expand Down Expand Up @@ -49,6 +52,9 @@ LABEL resty_websocket="${RESTY_WEBSOCKET}"
ARG RESTY_EVENTS=0
LABEL resty_events="${RESTY_EVENTS}"

ARG ATC_ROUTER=0
LABEL atc_router="${ATC_ROUTER}"

COPY openresty-build-tools /tmp/openresty-build-tools
COPY openresty-patches /tmp/openresty-patches
COPY build-openresty.sh /tmp/build-openresty.sh
Expand Down
33 changes: 32 additions & 1 deletion openresty-build-tools/kong-ngx-build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ KONG_NGINX_MODULE=master
RESTY_LMDB=master
RESTY_WEBSOCKET=${RESTY_WEBSOCKET:-0}
RESTY_EVENTS=main
ATC_ROUTER=main
DEBUG=0
NPROC=
OS=
Expand Down Expand Up @@ -106,6 +107,10 @@ main() {
RESTY_EVENTS=$2
shift 2
;;
--atc-router)
ATC_ROUTER=$2
shift 2
;;
-f|--force)
FORCE=1
shift 1
Expand Down Expand Up @@ -414,6 +419,25 @@ main() {
popd
popd
fi

# atc-router
if [ $ATC_ROUTER != 0 ]; then
if [[ $ATC_ROUTER == "main" ]]; then
ATC_ROUTER="origin/main"
fi
pushd $DOWNLOAD_CACHE
if [ ! -d atc-router ]; then
warn "atc-router source not found, cloning..."
git clone https://github.com/Kong/atc-router --recursive
fi

pushd atc-router
git fetch
# Accept both tags, branches and SHAs
git reset --hard $ATC_ROUTER || git reset --hard origin/$ATC_ROUTER
popd
popd
fi
popd

if [ ! -z "$DOWNLOAD_ONLY" ]; then
Expand Down Expand Up @@ -720,7 +744,7 @@ main() {
OPENRESTY_OPTS+=('--with-debug')
OPENRESTY_OPTS+=('--with-luajit-xcflags="-DLUAJIT_USE_VALGRIND -DLUA_USE_ASSERT -DLUA_USE_APICHECK -DLUAJIT_USE_SYSMALLOC"')
fi

eval ./configure ${OPENRESTY_OPTS[*]}

if [ -n "$BORINGSSL_VER" ]; then
Expand Down Expand Up @@ -751,6 +775,13 @@ main() {
make install LUA_LIB_DIR=$OPENRESTY_INSTALL/lualib
popd
fi

if [ $ATC_ROUTER != 0 ]; then
pushd $DOWNLOAD_CACHE/atc-router
warn "installing dynamic library and Lua files for atc-router..."
make install LUA_LIB_DIR=$OPENRESTY_INSTALL/lualib
popd
fi
popd

succ "OpenResty $OPENRESTY_VER has been built successfully!"
Expand Down

0 comments on commit 80b87eb

Please sign in to comment.