forked from heroku/heroku-buildpack-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_nginx
executable file
·95 lines (72 loc) · 3.59 KB
/
build_nginx
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
#!/bin/bash
# Build NGINX and modules for Heroku.
# This script is designed to run in a Heroku Stack Docker
# image. More information on the Heroku Stack can be found
# at https://devcenter.heroku.com/articles/stack
NGINX_VERSION=${NGINX_VERSION-1.19.3}
PCRE_VERSION=${PCRE_VERSION-8.44}
HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.33}
ZLIB_VERSION=${ZLIB_VERSION-1.2.12}
UUID4_VERSION=${UUID4_VERSION-master}
LUA_JIT_VERSION=${LUA_JIT-2.1-20220411}
NGX_DEVEL_KIT=${NGX_DEVEL_KIT-0.3.1}
NGX_LUA=${NGX_LUA-0.10.20}
LUA_RESTY_CORE=${LUA_RESTY_CORE-0.1.22}
LUA_RESTY_CACHE=${LUA_RESTY_CACHE-0.11}
nginx_tarball_url=https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
pcre_tarball_url=https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz/download
headers_more_nginx_module_url=https://github.com/openresty/headers-more-nginx-module/archive/v${HEADERS_MORE_VERSION}.tar.gz
uuid4_url=https://github.com/cybozu/nginx-uuid4-module/archive/${UUID4_VERSION}.tar.gz
zlib_url=http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
lua_jit_url=https://github.com/openresty/luajit2/archive/refs/tags/v${LUA_JIT_VERSION}.tar.gz
ngx_devel_kit_url=https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v${NGX_DEVEL_KIT}.tar.gz
ngx_lua_url=https://github.com/openresty/lua-nginx-module/archive/refs/tags/v${NGX_LUA}.tar.gz
lua_resty_core_url=https://github.com/openresty/lua-resty-core/archive/refs/tags/v${LUA_RESTY_CORE}.tar.gz
lua_resty_lrucache_url=https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v${LUA_RESTY_CACHE}.tar.gz
temp_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX)
cd $temp_dir
echo "Temp dir: $temp_dir"
echo "Downloading $nginx_tarball_url"
curl -L $nginx_tarball_url | tar xzv
echo "Downloading $pcre_tarball_url"
(cd nginx-${NGINX_VERSION} && curl -L $pcre_tarball_url | tar xvz )
echo "Downloading $headers_more_nginx_module_url"
(cd nginx-${NGINX_VERSION} && curl -L $headers_more_nginx_module_url | tar xvz )
echo "Downloading $zlib_url"
(cd nginx-${NGINX_VERSION} && curl -L $zlib_url | tar xvz )
echo "Downloading $uuid4_url"
(cd nginx-${NGINX_VERSION} && curl -L $uuid4_url | tar xvz )
echo "Downloading $lua_jit_url"
(cd nginx-${NGINX_VERSION} && curl -L $lua_jit_url | tar xvz )
echo "Downloading $ngx_devel_kit_url"
(cd nginx-${NGINX_VERSION} && curl -L $ngx_devel_kit_url | tar xvz )
echo "Downloading $ngx_lua_url"
(cd nginx-${NGINX_VERSION} && curl -L $ngx_lua_url | tar xvz )
echo "Installing luajit"
(cd nginx-${NGINX_VERSION} && cd luajit2-${LUA_JIT_VERSION} && make install)
# tell nginx's build system where to find LuaJIT 2.0:
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
# This will build `nginx`
(
cd nginx-${NGINX_VERSION}
./configure \
--with-ld-opt="-Wl,-rpath,/app/lib" \
--with-pcre=pcre-${PCRE_VERSION} \
--with-zlib=zlib-${ZLIB_VERSION} \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_ssl_module \
--prefix=/tmp/nginx \
--add-module=${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION} \
--add-module=${temp_dir}/nginx-${NGINX_VERSION}/nginx-uuid4-module-${UUID4_VERSION} \
--add-module=${temp_dir}/nginx-${NGINX_VERSION}/ngx_devel_kit-${NGX_DEVEL_KIT} \
--add-module=${temp_dir}/nginx-${NGINX_VERSION}/lua-nginx-module-${NGX_LUA}
make install
)
release_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX)
cp /tmp/nginx/sbin/nginx $release_dir/nginx
cp /tmp/nginx-debug/sbin/nginx $release_dir/nginx-debug
cp /tmp/nginx/conf/mime.types $release_dir/mime.types
tar -zcvf /tmp/nginx-"${STACK}".tgz -C $release_dir .
cp /tmp/nginx-"${STACK}".tgz $1