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