Skip to content

Commit f8faae2

Browse files
authored
feat(runtime): the build & test runtime (#2)
1 parent af0f357 commit f8faae2

21 files changed

+4466
-13
lines changed

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OPENRESTY_VERSION=1.21.4.1
2+
LUAROCKS_VERSION=3.9.1
3+
PCRE_VERSION=8.45
4+
KONG_NGINX_MODULE_VERSION=0.4.0
5+
LUA_RESTY_LMDB_VERSION=1.0.0
6+
LUA_RESTY_EVENTS_VERSION=0.1.3
7+
ATC_ROUTER_VERSION=1.0.35

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ repos:
2121
hooks:
2222
- id: forbid-crlf
2323
- id: remove-crlf
24-
- id: forbid-tabs
25-
- id: remove-tabs
2624
- repo: https://github.com/Yelp/detect-secrets
2725
rev: v1.1.0
2826
hooks:

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ ARG DOCKER_REGISTRY=ghcr.io
44
ARG DOCKER_IMAGE_NAME
55

66
# List out all image permutations to trick dependabot
7-
FROM --platform=linux/amd64 kong/kong-build-tools:apk-1.8.1 as x86_64-linux-musl
8-
FROM --platform=linux/amd64 kong/kong-build-tools:rpm-1.8.1 as x86_64-linux-gnu
9-
FROM --platform=linux/arm64 kong/kong-build-tools:apk-1.8.1 as aarch64-linux-musl
10-
FROM --platform=linux/arm64 kong/kong-build-tools:rpm-1.8.1 as aarch64-linux-gnu
7+
FROM --platform=linux/amd64 ghcr.io/kong/kong-openssl:1.1.0-x86_64-linux-musl as x86_64-linux-musl
8+
FROM --platform=linux/amd64 ghcr.io/kong/kong-openssl:1.1.0-x86_64-linux-gnu as x86_64-linux-gnu
9+
FROM --platform=linux/arm64 ghcr.io/kong/kong-openssl:1.1.0-aarch64-linux-musl as aarch64-linux-musl
10+
FROM --platform=linux/arm64 ghcr.io/kong/kong-openssl:1.1.0-aarch64-linux-gnu as aarch64-linux-gnu
1111

1212

1313
# Run the build script
1414
FROM $ARCHITECTURE-$OSTYPE as build
1515

16-
COPY . /src
17-
RUN /src/build.sh && /src/test.sh
16+
COPY . /tmp
17+
WORKDIR /tmp
1818

19+
RUN /tmp/build.sh
1920

2021
# Copy the build result to scratch so we can export the result
2122
FROM scratch as package

build.sh

Lines changed: 128 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,139 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
4-
IFS=$'\n\t'
3+
set -eo pipefail
54

65
if [ -n "${DEBUG:-}" ]; then
76
set -x
87
fi
98

9+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
10+
export $(grep -v '^#' $SCRIPT_DIR/.env | xargs)
11+
1012
function main() {
11-
rm -rf /tmp/build/* && uname -a >> /tmp/build/out
13+
with_backoff curl --fail -sSLo pcre.tar.gz "https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz"
14+
tar -xzvf pcre.tar.gz
15+
ln -s pcre-${PCRE_VERSION} pcre
16+
17+
with_backoff curl --fail -sSLo openresty.tar.gz "https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz"
18+
tar -xzvf openresty.tar.gz
19+
ln -s openresty-${OPENRESTY_VERSION} openresty
20+
21+
with_backoff curl --fail -sSLo luarocks.tar.gz "https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz"
22+
tar -xzvf luarocks.tar.gz
23+
ln -s luarocks-${LUAROCKS_VERSION} luarocks
24+
25+
with_backoff git clone --single-branch --branch ${KONG_NGINX_MODULE_VERSION} https://github.com/Kong/lua-kong-nginx-module
26+
27+
with_backoff git clone --single-branch --branch ${LUA_RESTY_LMDB_VERSION} https://github.com/Kong/lua-resty-lmdb --recursive
28+
29+
with_backoff git clone --single-branch --branch ${LUA_RESTY_EVENTS_VERSION} https://github.com/Kong/lua-resty-events --recursive
30+
31+
pushd openresty-${OPENRESTY_VERSION}/bundle
32+
for patch_file in $(ls /tmp/patches/*.patch); do
33+
patch -p1 < $patch_file
34+
done
35+
36+
lj_dir=$(ls -d LuaJIT*)
37+
lj_release_date=$(echo ${lj_dir} | sed -e 's/LuaJIT-[[:digit:]]\+.[[:digit:]]\+-\([[:digit:]]\+\)/\1/')
38+
lj_version_tag="LuaJIT\ 2.1.0-${lj_release_date}"
39+
popd
40+
41+
pushd openresty-${OPENRESTY_VERSION}
42+
OPENRESTY_OPTS=(
43+
"--prefix=/usr/local/openresty"
44+
"--with-pcre-jit"
45+
"--with-http_ssl_module"
46+
"--with-http_sub_module"
47+
"--with-http_realip_module"
48+
"--with-http_stub_status_module"
49+
"--with-http_v2_module"
50+
"--without-http_encrypted_session_module"
51+
"--with-luajit-xcflags='-DLUAJIT_VERSION=\\\"${lj_version_tag}\\\"'"
52+
"-j2"
53+
)
54+
55+
OPENRESTY_OPTS+=("--add-module=/tmp/lua-kong-nginx-module")
56+
OPENRESTY_OPTS+=("--add-module=/tmp/lua-kong-nginx-module/stream")
57+
OPENRESTY_OPTS+=("--add-module=/tmp/lua-resty-lmdb")
58+
OPENRESTY_OPTS+=("--add-module=/tmp/lua-resty-events")
59+
OPENRESTY_OPTS+=('--with-stream_realip_module')
60+
OPENRESTY_OPTS+=('--with-stream_ssl_preread_module')
61+
OPENRESTY_OPTS+=('--with-pcre=/tmp/pcre')
62+
OPENRESTY_OPTS+=("--with-ld-opt='-L/tmp/build/usr/local/kong/lib -Wl,--disable-new-dtags,-rpath,/usr/local/kong/lib'")
63+
OPENRESTY_OPTS+=("--with-cc-opt='-I/tmp/build/usr/local/kong/include'")
64+
65+
eval ./configure ${OPENRESTY_OPTS[*]} || tee /tmp/00-openresty-configure.log
66+
67+
make -j2 || tee /tmp/01-openresty-build.log
68+
make -j2 install DESTDIR=/tmp/build || tee /tmp/02-openresty-install.log
69+
popd
70+
71+
pushd /tmp/lua-kong-nginx-module
72+
make install LUA_LIB_DIR=/tmp/build/usr/local/openresty/lualib
73+
popd
74+
75+
pushd /tmp/lua-resty-lmdb
76+
make install LUA_LIB_DIR=/tmp/build/usr/local/openresty/lualib
77+
popd
78+
79+
pushd /tmp/lua-resty-events
80+
make install LUA_LIB_DIR=/tmp/build/usr/local/openresty/lualib
81+
popd
82+
83+
pushd /tmp/luarocks-${LUAROCKS_VERSION}
84+
./configure \
85+
--prefix=/usr/local \
86+
--with-lua=/tmp/build/usr/local/openresty/luajit \
87+
--with-lua-include=/tmp/build/usr/local/openresty/luajit/include/luajit-2.1
88+
89+
make build -j2
90+
make install DESTDIR=/tmp/build
91+
popd
92+
93+
arch=$(uname -m)
94+
95+
package_architecture=x86_64
96+
if [ "$(arch)" == "aarch64" ]; then
97+
package_architecture=aarch64
98+
fi
99+
100+
curl -fsSLo atc-router.tar.gz https://github.com/hutchic/atc-router/releases/download/$ATC_ROUTER_VERSION/$package_architecture-unknown-$OSTYPE.tar.gz
101+
tar -C /tmp/build -xvf atc-router.tar.gz
102+
}
103+
104+
# Retries a command a configurable number of times with backoff.
105+
#
106+
# The retry count is given by ATTEMPTS (default 5), the initial backoff
107+
# timeout is given by TIMEOUT in seconds (default 1.)
108+
#
109+
# Successive backoffs double the timeout.
110+
function with_backoff {
111+
local max_attempts=${ATTEMPTS-5}
112+
local timeout=${TIMEOUT-5}
113+
local attempt=1
114+
local exitCode=0
115+
116+
while (( $attempt < $max_attempts ))
117+
do
118+
if "$@"
119+
then
120+
return 0
121+
else
122+
exitCode=$?
123+
fi
124+
125+
echo "Failure! Retrying in $timeout.." 1>&2
126+
sleep $timeout
127+
attempt=$(( attempt + 1 ))
128+
timeout=$(( timeout * 2 ))
129+
done
130+
131+
if [[ $exitCode != 0 ]]
132+
then
133+
echo "You've failed me for the last time! ($@)" 1>&2
134+
fi
135+
136+
return $exitCode
12137
}
13138

14139
main
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From f53c8fa441f4233b9a3f19fcd870207fe8795456 Mon Sep 17 00:00:00 2001
2+
From: Qi <add_sp@outlook.com>
3+
Date: Wed, 25 May 2022 18:35:08 +0800
4+
Subject: [PATCH] Patch macro `LUAJIT_VERSION`
5+
6+
---
7+
src/luajit.h | 2 ++
8+
1 file changed, 2 insertions(+)
9+
10+
diff --git a/LuaJIT-2.1-20220411/src/luajit.h b/LuaJIT-2.1-20220411/src/luajit.h
11+
index a4d33001..e35f4e7e 100644
12+
--- a/LuaJIT-2.1-20220411/src/luajit.h
13+
+++ b/LuaJIT-2.1-20220411/src/luajit.h
14+
@@ -32,7 +32,9 @@
15+
16+
#define OPENRESTY_LUAJIT
17+
18+
+#ifndef LUAJIT_VERSION
19+
#define LUAJIT_VERSION "LuaJIT 2.1.0-beta3"
20+
+#endif
21+
#define LUAJIT_VERSION_NUM 20100 /* Version 2.1.0 = 02.01.00. */
22+
#define LUAJIT_VERSION_SYM luaJIT_version_2_1_0_beta3
23+
#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2022 Mike Pall"
24+
--
25+
2.34.1
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
From dad04f1754723e76ba9dcf9f401f3134a0cd3972 Mon Sep 17 00:00:00 2001
2+
From: Mike Pall <mike>
3+
Date: Wed, 14 Sep 2022 12:26:53 +0200
4+
Subject: [PATCH] Fix trace join to BC_JLOOP originating from BC_ITERN.
5+
6+
Reported by OpenResty Inc.
7+
---
8+
src/lj_record.c | 3 ++-
9+
1 file changed, 2 insertions(+), 1 deletion(-)
10+
11+
diff --git a/LuaJIT-2.1-20220411/src/lj_record.c b/LuaJIT-2.1-20220411/src/lj_record.c
12+
index 5d02d24a1..bfd412365 100644
13+
--- a/LuaJIT-2.1-20220411/src/lj_record.c
14+
+++ b/LuaJIT-2.1-20220411/src/lj_record.c
15+
@@ -2572,7 +2572,8 @@ void lj_record_ins(jit_State *J)
16+
break;
17+
case BC_JLOOP:
18+
rec_loop_jit(J, rc, rec_loop(J, ra,
19+
- !bc_isret(bc_op(traceref(J, rc)->startins))));
20+
+ !bc_isret(bc_op(traceref(J, rc)->startins)) &&
21+
+ bc_op(traceref(J, rc)->startins) != BC_ITERN));
22+
break;
23+
24+
case BC_IFORL:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -ruN a/lua-cjson-2.1.0.8/lua_cjson.c b/lua-cjson-2.1.0.8/lua_cjson.c
2+
--- a/lua-cjson-2.1.0.10/lua_cjson.c 2022-01-11 15:11:17.495464192 +0800
3+
+++ b/lua-cjson-2.1.0.10/lua_cjson.c 2022-01-11 14:58:55.150669748 +0800
4+
@@ -800,7 +800,7 @@
5+
case LUA_TLIGHTUSERDATA:
6+
if (lua_touserdata(l, -1) == NULL) {
7+
strbuf_append_mem(json, "null", 4);
8+
- } else if (lua_touserdata(l, -1) == &json_array) {
9+
+ } else if (lua_touserdata(l, -1) == json_lightudata_mask(&json_array)) {
10+
json_append_array(l, cfg, current_depth, json, 0);
11+
}
12+
break;

0 commit comments

Comments
 (0)