Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Nginx 1.26, link against system libraries, strip nginx binary #122

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changes
- [heroku-18] Removed
- Add documentation for migrating from heroku-community/static buildpack
- Update zlib from 1.2.13 to 1.3.1
- Link against system libpcre3
- Link against system zlib
- Update nginx to 1.26.0
- Update headers-more-nginx-module to 0.37

## [1.10] - 2023-06-13
### Changes
Expand Down
Binary file modified nginx-heroku-20.tgz
Binary file not shown.
Binary file modified nginx-heroku-22.tgz
Binary file not shown.
73 changes: 34 additions & 39 deletions scripts/build_nginx
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,68 @@
# image. More information on the Heroku Stack can be found
# at https://devcenter.heroku.com/articles/stack

NGINX_VERSION=${NGINX_VERSION-1.25.1}
PCRE_VERSION=${PCRE_VERSION-8.45}
HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.34}
ZLIB_VERSION=${ZLIB_VERSION-1.3.1}
UUID4_VERSION=${UUID4_VERSION-master}
# fail hard
set -o pipefail
# fail harder
set -eu

NGINX_VERSION=${NGINX_VERSION-1.26.0}
HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.37}
UUID4_VERSION=${UUID4_VERSION-f8f7ff44e6a8c6cf75232ae4b63d011f2f3b34c1}

nginx_tarball_url=https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
pcre_tarball_url=https://ftp.exim.org/pub/pcre/pcre-${PCRE_VERSION}.tar.gz
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

temp_dir=$(mktemp -d /tmp/nginx.XXXXXXXXXX)

cd $temp_dir
echo "Temp dir: $temp_dir"
trap popd EXIT
pushd "$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 )
curl -sSL "$nginx_tarball_url" | tar xzv

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 )
curl -sSL "$headers_more_nginx_module_url" | tar xvz -C "nginx-${NGINX_VERSION}"

echo "Downloading $uuid4_url"
(cd nginx-${NGINX_VERSION} && curl -L $uuid4_url | tar xvz )
curl -sSL "$uuid4_url" | tar xvz -C "nginx-${NGINX_VERSION}"

configure_opts=(
--with-pcre
--without-pcre2
dzuelke marked this conversation as resolved.
Show resolved Hide resolved
--with-http_gzip_static_module
--with-http_realip_module
--with-http_ssl_module
--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}"
)

# This will build `nginx`
(
cd nginx-${NGINX_VERSION}
cd "nginx-${NGINX_VERSION}"
./configure \
--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}
"${configure_opts[@]}"
make install
# strip binary (but not the nginx-debug variant further down)
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
)

# This will build `nginx-debug`
(
cd nginx-${NGINX_VERSION}
cd "nginx-${NGINX_VERSION}"
./configure \
--with-debug \
--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-debug \
--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}
"${configure_opts[@]}"
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
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"