Skip to content

Commit

Permalink
chore(builds): Merge upstream and add heroku-22 build (#2)
Browse files Browse the repository at this point in the history
* bump zlib version

* add new builds
  • Loading branch information
Dottenpixel authored Mar 15, 2023
1 parent 14dc4f3 commit db91108
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 27 deletions.
18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
build: build-cedar-14 build-heroku-16 build-heroku-18 build-heroku-20

build-cedar-14:
@echo "Building nginx in Docker for cedar-14..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=cedar-14" -e "NGINX_VERSION=1.9.5" -e "PCRE_VERSION=8.37" -e "HEADERS_MORE_VERSION=0.261" -w /buildpack heroku/cedar:14 scripts/build_nginx /buildpack/nginx-cedar-14.tgz

build-heroku-16:
@echo "Building nginx in Docker for heroku-16..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-16" -e "NGINX_VERSION=1.9.5" -e "PCRE_VERSION=8.37" -e "HEADERS_MORE_VERSION=0.261" -w /buildpack heroku/heroku:16-build scripts/build_nginx /buildpack/nginx-heroku-16.tgz
build: build-heroku-18 build-heroku-20 build-heroku-22

build-heroku-18:
@echo "Building nginx in Docker for heroku-18..."
Expand All @@ -16,6 +8,10 @@ build-heroku-20:
@echo "Building nginx in Docker for heroku-20..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-20" -w /buildpack heroku/heroku:20-build scripts/build_nginx /buildpack/nginx-heroku-20.tgz

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

shell:
@echo "Opening heroku-18 shell..."
@docker run -v $(shell pwd):/buildpack --rm -it -e "STACK=heroku-18" -e "PORT=5000" -w /buildpack heroku/heroku:18-build bash
@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
25 changes: 25 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ cp "$BUILD_DIR/nginx/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"

# The ERB templating feature requires a Ruby install at runtime, for the `erb` command.
# As of Heroku-22, there is no system Ruby installation in the stack image, so if the
# app doesn't already have the Ruby buildpack set before this one, we have to vendor
# 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.1.2"
ruby_url="https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/${STACK}/ruby-${ruby_version}.tgz"
vendored_ruby_dir=".heroku-buildpack-nginx/ruby"
mkdir -p "${BUILD_DIR}/${vendored_ruby_dir}"

if ! curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 5 "${ruby_url}" | tar -zxC "${BUILD_DIR}/${vendored_ruby_dir}"; then
echo " ! Failed to download Ruby from '${ruby_url}'" >&2
exit 1
fi

mkdir -p "${BUILD_DIR}/.profile.d"
# Deliberately pick the same profile.d script filepath as the Ruby buildpack,
# so if the Ruby buildpack comes after this one, it will overwrite this script.
echo "export PATH=\"\${HOME}/${vendored_ruby_dir}/bin:\${PATH}\"" > "${BUILD_DIR}/.profile.d/ruby.sh"

echo "-----> nginx-buildpack: Installed Ruby ${ruby_version}"
fi

cp bin/start-nginx "$BUILD_DIR/bin/"
echo '-----> nginx-buildpack: Added start-nginx to app/bin'
cp bin/start-nginx-debug "$BUILD_DIR/bin/"
Expand Down
23 changes: 23 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.9] - 2022-06-21
### Changes
- If a Ruby installation is not found (required for the ERB templating feature), this buildpack will now install its own, to ensure it works on Heroku-22.

## [1.8] - 2022-05-19
### Changes
- [heroku-18] updated nginx to 1.20.2, bump zlib to 1.2.12, updated PCRE to 8.45
- [heroku-20] updated nginx to 1.20.2, bump zlib to 1.2.12, updated PCRE to 8.45
- [heroku-22] add support for Heroku-22

## [1.7] - 2021-06-04
### Changes
- [heroku-18] updated nginx to 1.20.1
- [heroku-20] updated nginx to 1.20.1
- [heroku-16] Removed

## [1.6] - 2021-05-27
### Changes
- [heroku-18] updated nginx to 1.20.0
- [heroku-20] updated nginx to 1.20.0
- [cedar-14] Removed
- rename master branch to main

## [1.5.2] - 2021-07-29
### Changes
- [CODEOWNERS] Add ECCN
Expand Down
1 change: 1 addition & 0 deletions config/nginx-nextjs-with-forcessl.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;
gzip_proxied any; # Heroku router sends Via header

server_tokens off;

Expand Down
1 change: 1 addition & 0 deletions config/nginx-solo-sample.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;
gzip_proxied any; # Heroku router sends Via header

server_tokens off;

Expand Down
1 change: 1 addition & 0 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ http {
gzip on;
gzip_comp_level 2;
gzip_min_length 512;
gzip_proxied any; # Heroku router sends Via header

server_tokens off;

Expand Down
Binary file removed nginx-cedar-14.tgz
Binary file not shown.
Binary file removed nginx-heroku-16.tgz
Binary file not shown.
Binary file modified nginx-heroku-18.tgz
Binary file not shown.
Binary file modified nginx-heroku-20.tgz
Binary file not shown.
Binary file added nginx-heroku-22.tgz
Binary file not shown.
22 changes: 10 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ Nginx-buildpack vendors NGINX inside a dyno and connects NGINX to an app server

## Motivation

Some application servers (e.g. Ruby's Unicorn) halt progress when dealing with network I/O. Heroku's Cedar routing stack [buffers only the headers](https://devcenter.heroku.com/articles/http-routing#request-buffering) of inbound requests. (The Cedar router will buffer the headers and body of a response up to 1MB) Thus, the Heroku router engages the dyno during the entire body transfer –from the client to dyno. For applications servers with blocking I/O, the latency per request will be degraded by the content transfer. By using NGINX in front of the application server, we can eliminate a great deal of transfer time from the application server. In addition to making request body transfers more efficient, all other I/O should be improved since the application server need only communicate with a UNIX socket on localhost. Basically, for webservers that are not designed for efficient, non-blocking I/O, we will benefit from having NGINX to handle all I/O operations.
Some application servers (e.g. Ruby's Unicorn) halt progress when dealing with network I/O. Heroku's routing stack [buffers only the headers](https://devcenter.heroku.com/articles/http-routing#request-buffering) of inbound requests. (The router will buffer the headers and body of a response up to 1MB) Thus, the Heroku router engages the dyno during the entire body transfer –from the client to dyno. For applications servers with blocking I/O, the latency per request will be degraded by the content transfer. By using NGINX in front of the application server, we can eliminate a great deal of transfer time from the application server. In addition to making request body transfers more efficient, all other I/O should be improved since the application server need only communicate with a UNIX socket on localhost. Basically, for webservers that are not designed for efficient, non-blocking I/O, we will benefit from having NGINX to handle all I/O operations.

## Versions

### Cedar-14 (deprecated)
* NGINX Version: 1.9.5
### Heroku 16
* NGINX Version: 1.9.5
### Heroku 18
* NGINX Version: 1.18.0
* NGINX Version: 1.20.1
### Heroku 20
* NGINX Version: 1.18.0
* NGINX Version: 1.20.1
### Heroku 22
* NGINX Version: 1.20.1

## Requirements (Proxy Mode)

Expand Down Expand Up @@ -80,7 +78,7 @@ web: bin/start-nginx-debug bundle exec unicorn -c config/unicorn.rb

nginx-buildpack provides a command named `bin/start-nginx-solo`. This is for you if you don't want to run an additional app server on the Dyno.
This mode requires you to put a `config/nginx.conf.erb` in your app code. You can start by coping the [sample config for nginx solo mode](config/nginx-solo-sample.conf.erb).
For example, to get NGINX and Unicorn up and running:
To get NGINX Solo Mode running:

```bash
$ cat Procfile
Expand Down Expand Up @@ -152,7 +150,7 @@ The buildpack will not start NGINX until a file has been written to `/tmp/app-in

## Setup

Here are 2 setup examples. One example for a new app, another for an existing app. In both cases, we are working with ruby & unicorn. Keep in mind that this buildpack is not ruby specific.
Here are 2 setup examples. One example for a new app, another for an existing app. In both cases, we are working with ruby & unicorn. Keep in mind that this buildpack is not ruby specific. However if your app does happen to use Ruby, make sure to add the NGINX buildpack **after** the Ruby buildpack, so the NGINX buildpack doesn't have to install its own redundant copy of Ruby for the ERB templating feature.

### Existing App

Expand Down Expand Up @@ -184,7 +182,7 @@ $ git commit -m 'Update unicorn config to listen on NGINX socket.'
```
Deploy Changes
```bash
$ git push heroku master
$ git push heroku main
```

### New App
Expand Down Expand Up @@ -229,10 +227,10 @@ Create & Push Heroku App:
```bash
$ heroku create
$ heroku buildpacks:add heroku/ruby
$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-nginx
$ heroku buildpacks:add heroku-community/nginx
$ git add .
$ git commit -am "init"
$ git push heroku master
$ git push heroku main
$ heroku logs -t
```
Visit App
Expand Down
8 changes: 4 additions & 4 deletions scripts/build_nginx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# image. More information on the Heroku Stack can be found
# at https://devcenter.heroku.com/articles/stack

NGINX_VERSION=${NGINX_VERSION-1.18.0}
PCRE_VERSION=${PCRE_VERSION-8.44}
NGINX_VERSION=${NGINX_VERSION-1.20.2}
PCRE_VERSION=${PCRE_VERSION-8.45}
HEADERS_MORE_VERSION=${HEADERS_MORE_VERSION-0.33}
ZLIB_VERSION=${ZLIB_VERSION-1.2.11}
ZLIB_VERSION=${ZLIB_VERSION-1.2.13}
UUID4_VERSION=${UUID4_VERSION-master}

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

0 comments on commit db91108

Please sign in to comment.