|
4 | 4 | # image. More information on the Heroku Stack can be found
|
5 | 5 | # at https://devcenter.heroku.com/articles/stack
|
6 | 6 |
|
7 |
| -NGINX_VERSION=${NGINX_VERSION-1.25.1} |
8 |
| -PCRE_VERSION=${PCRE_VERSION-8.45} |
9 |
| -HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.34} |
10 |
| -ZLIB_VERSION=${ZLIB_VERSION-1.3.1} |
11 |
| -UUID4_VERSION=${UUID4_VERSION-master} |
| 7 | +# fail hard |
| 8 | +set -o pipefail |
| 9 | +# fail harder |
| 10 | +set -eu |
| 11 | + |
| 12 | +NGINX_VERSION=${NGINX_VERSION-1.26.0} |
| 13 | +HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.37} |
| 14 | +UUID4_VERSION=${UUID4_VERSION-f8f7ff44e6a8c6cf75232ae4b63d011f2f3b34c1} |
12 | 15 |
|
13 | 16 | nginx_tarball_url=https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
|
14 |
| -pcre_tarball_url=https://ftp.exim.org/pub/pcre/pcre-${PCRE_VERSION}.tar.gz |
15 | 17 | headers_more_nginx_module_url=https://github.com/openresty/headers-more-nginx-module/archive/v${HEADERS_MORE_VERSION}.tar.gz
|
16 | 18 | uuid4_url=https://github.com/cybozu/nginx-uuid4-module/archive/${UUID4_VERSION}.tar.gz
|
17 |
| -zlib_url=http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz |
18 | 19 |
|
19 | 20 | temp_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX)
|
20 | 21 |
|
21 |
| -cd $temp_dir |
22 |
| -echo "Temp dir: $temp_dir" |
| 22 | +trap popd EXIT |
| 23 | +pushd "$temp_dir" |
23 | 24 |
|
24 | 25 | echo "Downloading $nginx_tarball_url"
|
25 |
| -curl -L $nginx_tarball_url | tar xzv |
26 |
| - |
27 |
| -echo "Downloading $pcre_tarball_url" |
28 |
| -(cd nginx-${NGINX_VERSION} && curl -L $pcre_tarball_url | tar xvz ) |
| 26 | +curl -sSL "$nginx_tarball_url" | tar xzv |
29 | 27 |
|
30 | 28 | echo "Downloading $headers_more_nginx_module_url"
|
31 |
| -(cd nginx-${NGINX_VERSION} && curl -L $headers_more_nginx_module_url | tar xvz ) |
32 |
| - |
33 |
| -echo "Downloading $zlib_url" |
34 |
| -(cd nginx-${NGINX_VERSION} && curl -L $zlib_url | tar xvz ) |
| 29 | +curl -sSL "$headers_more_nginx_module_url" | tar xvz -C "nginx-${NGINX_VERSION}" |
35 | 30 |
|
36 | 31 | echo "Downloading $uuid4_url"
|
37 |
| -(cd nginx-${NGINX_VERSION} && curl -L $uuid4_url | tar xvz ) |
| 32 | +curl -sSL "$uuid4_url" | tar xvz -C "nginx-${NGINX_VERSION}" |
| 33 | + |
| 34 | +configure_opts=( |
| 35 | + --with-pcre |
| 36 | + --without-pcre2 |
| 37 | + --with-http_gzip_static_module |
| 38 | + --with-http_realip_module |
| 39 | + --with-http_ssl_module |
| 40 | + --add-module="${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION}" |
| 41 | + --add-module="${temp_dir}/nginx-${NGINX_VERSION}/nginx-uuid4-module-${UUID4_VERSION}" |
| 42 | +) |
38 | 43 |
|
39 | 44 | # This will build `nginx`
|
40 | 45 | (
|
41 |
| - cd nginx-${NGINX_VERSION} |
| 46 | + cd "nginx-${NGINX_VERSION}" |
42 | 47 | ./configure \
|
43 |
| - --with-pcre=pcre-${PCRE_VERSION} \ |
44 |
| - --with-zlib=zlib-${ZLIB_VERSION} \ |
45 |
| - --with-http_gzip_static_module \ |
46 |
| - --with-http_realip_module \ |
47 |
| - --with-http_ssl_module \ |
48 | 48 | --prefix=/tmp/nginx \
|
49 |
| - --add-module=${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION} \ |
50 |
| - --add-module=${temp_dir}/nginx-${NGINX_VERSION}/nginx-uuid4-module-${UUID4_VERSION} |
| 49 | + "${configure_opts[@]}" |
51 | 50 | make install
|
| 51 | + # strip binary (but not the nginx-debug variant further down) |
| 52 | + find /tmp/nginx -type f \( -executable -o -name '*.a' \) -exec sh -c "file -i '{}' | grep -Eq 'application/x-(archive|(pie-)?executable|sharedlib); charset=binary'" \; -print | xargs strip --strip-unneeded |
52 | 53 | )
|
53 | 54 |
|
54 | 55 | # This will build `nginx-debug`
|
55 | 56 | (
|
56 |
| - cd nginx-${NGINX_VERSION} |
| 57 | + cd "nginx-${NGINX_VERSION}" |
57 | 58 | ./configure \
|
58 | 59 | --with-debug \
|
59 |
| - --with-pcre=pcre-${PCRE_VERSION} \ |
60 |
| - --with-zlib=zlib-${ZLIB_VERSION} \ |
61 |
| - --with-http_gzip_static_module \ |
62 |
| - --with-http_realip_module \ |
63 |
| - --with-http_ssl_module \ |
64 | 60 | --prefix=/tmp/nginx-debug \
|
65 |
| - --add-module=${temp_dir}/nginx-${NGINX_VERSION}/headers-more-nginx-module-${HEADERS_MORE_VERSION} \ |
66 |
| - --add-module=${temp_dir}/nginx-${NGINX_VERSION}/nginx-uuid4-module-${UUID4_VERSION} |
| 61 | + "${configure_opts[@]}" |
67 | 62 | make install
|
68 | 63 | )
|
69 | 64 |
|
70 | 65 | release_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX)
|
71 | 66 |
|
72 |
| -cp /tmp/nginx/sbin/nginx $release_dir/nginx |
73 |
| -cp /tmp/nginx-debug/sbin/nginx $release_dir/nginx-debug |
74 |
| -cp /tmp/nginx/conf/mime.types $release_dir/mime.types |
75 |
| -tar -zcvf /tmp/nginx-"${STACK}".tgz -C $release_dir . |
76 |
| -cp /tmp/nginx-"${STACK}".tgz $1 |
| 67 | +cp /tmp/nginx/sbin/nginx "$release_dir/nginx" |
| 68 | +cp /tmp/nginx-debug/sbin/nginx "$release_dir/nginx-debug" |
| 69 | +cp /tmp/nginx/conf/mime.types "$release_dir/mime.types" |
| 70 | +tar -zcvf /tmp/nginx-"${STACK}".tgz -C "$release_dir" . |
| 71 | +cp /tmp/nginx-"${STACK}".tgz "$1" |
0 commit comments