diff --git a/Makefile b/Makefile index db24855d..b41715a0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -build: build-heroku-20 build-heroku-22 +build: build-heroku-20 build-heroku-22 build-heroku-24 build-heroku-20: @echo "Building nginx in Docker for heroku-20..." @@ -8,6 +8,12 @@ build-heroku-22: @echo "Building nginx in Docker for heroku-22..." @docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-22" -w /buildpack heroku/heroku:22-build scripts/build_nginx /buildpack/nginx-heroku-22.tgz +build-heroku-24: + @echo "Building nginx in Docker for heroku-24 (amd64)..." + @docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-24" -w /buildpack --platform linux/amd64 heroku/heroku:24-build scripts/build_nginx /buildpack/nginx-heroku-24-amd64.tgz + @echo "Building nginx in Docker for heroku-24 (arm64)..." + @docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-24" -w /buildpack --platform linux/arm64 heroku/heroku:24-build scripts/build_nginx /buildpack/nginx-heroku-24-arm64.tgz + shell: @echo "Opening heroku-22 shell..." @docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-22" -e "PORT=5000" -w /buildpack heroku/heroku:22-build bash diff --git a/bin/compile b/bin/compile index aa19a089..be5dd756 100755 --- a/bin/compile +++ b/bin/compile @@ -10,12 +10,21 @@ BUILD_DIR=$1 CACHE_DIR=$2 BUILDPACK_DIR="$(dirname "$(dirname "$0")")" +ruby_version="3.2.4" +if [[ $STACK == heroku-2[02] ]]; then + nginx_tarball=nginx-${STACK}.tgz + ruby_tarball=${STACK}/ruby-${ruby_version}.tgz +else + nginx_tarball=nginx-$STACK-$(dpkg --print-architecture).tgz + ruby_tarball=${STACK}/$(dpkg --print-architecture)/ruby-${ruby_version}.tgz +fi + mkdir -p "$BUILD_DIR/bin/" -mkdir -p "$BUILD_DIR/nginx" -tar -zxvf "nginx-$STACK".tgz -C "$BUILD_DIR/nginx" +nginx_tmp=$(mktemp -d -t nginx.XXXXXXXXXX) +tar -zxvf "${nginx_tarball}" -C "$nginx_tmp" -cp "$BUILD_DIR/nginx/nginx" "$BUILD_DIR/bin/nginx" -cp "$BUILD_DIR/nginx/nginx-debug" "$BUILD_DIR/bin/nginx-debug" +mv "$nginx_tmp/nginx" "$BUILD_DIR/bin/nginx" +mv "$nginx_tmp/nginx-debug" "$BUILD_DIR/bin/nginx-debug" nginx_version=$($BUILD_DIR/bin/nginx -V 2>&1 | head -1 | awk '{ print $NF }') echo "-----> nginx-buildpack: Installed ${nginx_version} to app/bin" @@ -26,8 +35,7 @@ echo "-----> nginx-buildpack: Installed ${nginx_version} to app/bin" # our own copy of Ruby and ensure it's on PATH at runtime. if ! command -v erb &> /dev/null; then echo "-----> nginx-buildpack: An existing Ruby installation was not found (required for erb template support)" - ruby_version="3.2.2" - ruby_url="https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/${STACK}/ruby-${ruby_version}.tgz" + ruby_url="https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/${ruby_tarball}" vendored_ruby_dir=".heroku-buildpack-nginx/ruby" mkdir -p "${BUILD_DIR}/${vendored_ruby_dir}" @@ -56,7 +64,7 @@ echo '-----> nginx-buildpack: Added start-nginx-static to app/bin' mkdir -p "$BUILD_DIR/config" if [[ ! -f $BUILD_DIR/config/mime.types ]]; then - cp "$BUILD_DIR/nginx/mime.types" "$BUILD_DIR/config/" + mv "$nginx_tmp/mime.types" "$BUILD_DIR/config/" echo '-----> nginx-buildpack: Default mime.types copied to app/config/' else echo '-----> nginx-buildpack: Custom mime.types found in app/config.' @@ -70,6 +78,6 @@ else fi # cleanup -rm -r "$BUILD_DIR/nginx" +rm -r "$nginx_tmp" exit 0 diff --git a/changelog.md b/changelog.md index 8d12321e..4092fa5c 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Link against system zlib - Update nginx to 1.26.0 - Update headers-more-nginx-module to 0.37 +- Update ruby to 3.2.4 +- Support heroku-24 +- Use PCRE2 on heroku-24 and newer ## [1.10] - 2023-06-13 ### Changes diff --git a/nginx-heroku-24-amd64.tgz b/nginx-heroku-24-amd64.tgz new file mode 100644 index 00000000..e9a4a8f4 Binary files /dev/null and b/nginx-heroku-24-amd64.tgz differ diff --git a/nginx-heroku-24-arm64.tgz b/nginx-heroku-24-arm64.tgz new file mode 100644 index 00000000..5a235df3 Binary files /dev/null and b/nginx-heroku-24-arm64.tgz differ diff --git a/readme.md b/readme.md index 85e961df..6a1ac86d 100644 --- a/readme.md +++ b/readme.md @@ -17,10 +17,11 @@ Nginx-buildpack installs & runs the [Nginx web server](https://nginx.org/) insid These are auto-selected based on the app's stack at build time. -| Heroku Stack | Nginx Version | -|--------------|--------------:| -| `Heroku-20` | `1.25.1` | -| `Heroku-22` | `1.25.1` | +| Heroku Stack | Nginx Version | PCRE version | +|--------------|--------------:|-------------:| +| `Heroku-20` | `1.26.0` | PCRE1 (8.x) | +| `Heroku-22` | `1.26.0` | PCRE1 (8.x) | +| `Heroku-24` | `1.26.0` | PCRE2 (10.x) | ## Presets diff --git a/scripts/build_nginx b/scripts/build_nginx index 277bf528..b23d6fd2 100755 --- a/scripts/build_nginx +++ b/scripts/build_nginx @@ -33,13 +33,19 @@ curl -sSL "$uuid4_url" | tar xvz -C "nginx-${NGINX_VERSION}" configure_opts=( --with-pcre - --without-pcre2 --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}" ) +if [[ $STACK == heroku-2[02] ]]; then + # we used to build our own PCRE 8.x, and when moving to dynamic linking, we had to ensure all existing regexes in config files continued to work, so we enforced libpcre3 (8.x) usage instead of the newer PCRE2 (10.x), which has stricter validation for certain patterns (example: /[\w-.]/ is not allowed in PCRE2) + # but for any newer stacks, we can use the more modern PCRE2 + configure_opts+=( + --without-pcre2 + ) +fi # This will build `nginx` ( @@ -64,8 +70,7 @@ configure_opts=( 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" +mv /tmp/nginx/sbin/nginx "$release_dir/nginx" +mv /tmp/nginx-debug/sbin/nginx "$release_dir/nginx-debug" +mv /tmp/nginx/conf/mime.types "$release_dir/mime.types" +tar -zcvf "$1" -C "$release_dir" .