Skip to content

Commit

Permalink
Support heroku-24 (#123)
Browse files Browse the repository at this point in the history
* fix Nginx versions in readme

* Update Ruby to 3.2.4

* cut down on some of the unnecessary copying of files

* Support heroku-24

Both amd64 and arm64.

Finally also moves Nginx to PCRE2.

GUS-W-14674582
  • Loading branch information
dzuelke authored May 28, 2024
1 parent ac4cabb commit 277ccf2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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..."
Expand All @@ -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
24 changes: 16 additions & 8 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"

Expand Down Expand Up @@ -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.'
Expand All @@ -70,6 +78,6 @@ else
fi

# cleanup
rm -r "$BUILD_DIR/nginx"
rm -r "$nginx_tmp"

exit 0
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added nginx-heroku-24-amd64.tgz
Binary file not shown.
Binary file added nginx-heroku-24-arm64.tgz
Binary file not shown.
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 11 additions & 6 deletions scripts/build_nginx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
(
Expand All @@ -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" .

0 comments on commit 277ccf2

Please sign in to comment.