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

Conversation

dzuelke
Copy link
Contributor

@dzuelke dzuelke commented May 24, 2024

We should have started linking against base image versions of zlib and PCRE long ago. We are specifically linking against libpcre3 (8.x), because some regex rules have changed in the newer libpcre2 (10.x).

Also now stripping the nginx binary (but obviously not nginx-debug).

In total, we get a reasonable size reduction:

Before:

% ls -la nginx-heroku-2*.tgz
-rw-r--r--  1 dzuelke  staff  5638356 May 17 13:50 nginx-heroku-20.tgz
-rw-r--r--  1 dzuelke  staff  4559004 May 17 13:50 nginx-heroku-22.tgz
% tar tzvf nginx-heroku-20.tgz
-rw-r--r--  0 root   root     5349 Feb 21 01:58 ./mime.types
-rwxr-xr-x  0 root   root  6705408 Feb 21 01:58 ./nginx
-rwxr-xr-x  0 root   root  6870296 Feb 21 01:58 ./nginx-debug
% tar tzvf nginx-heroku-22.tgz
-rw-r--r--  0 root   root     5349 Feb 21 02:00 ./mime.types
-rwxr-xr-x  0 root   root  4937400 Feb 21 02:00 ./nginx
-rwxr-xr-x  0 root   root  5094584 Feb 21 02:00 ./nginx-debug

After:

% ls -la nginx-heroku-2*.tgz
-rw-r--r--  1 dzuelke  staff  3181649 May 17 13:51 nginx-heroku-20.tgz
-rw-r--r--  1 dzuelke  staff  2638964 May 17 13:51 nginx-heroku-22.tgz
% tar tzvf nginx-heroku-20.tgz
-rw-r--r--  0 root   root     5349 May 17 13:30 ./mime.types
-rwxr-xr-x  0 root   root   973624 May 17 13:30 ./nginx
-rwxr-xr-x  0 root   root  6746392 May 17 13:30 ./nginx-debug
% tar tzvf nginx-heroku-22.tgz
-rw-r--r--  0 root   root     5349 May 17 13:30 ./mime.types
-rwxr-xr-x  0 root   root   973592 May 17 13:30 ./nginx
-rwxr-xr-x  0 root   root  4974032 May 17 13:30 ./nginx-debug

GUS-W-15794944

Absolutely no need to compile this ourselves.

Because we have always built a custom libpcre3 (v8.x) and not the more modern PCRE2 (v10.x), we are enforcing usage of the old version for now.

This is to ensure that existing configs with regexes continue to work, as PCRE2 is more aggressive in its pattern validation.

To give a simple example, `/[\w-.]+/` now throws "Compilation failed: invalid range in character class at offset 3", and the `-` needs to be escaped, or moved to the end of the character class.
We only need debug symbols in the nginx-debug variant.

Together with the slight improvement from the now system-linked PCRE and zlib, this helps a lot with overall size.

Before:

    % ls -la nginx-heroku-2*.tgz
    -rw-r--r--  1 dzuelke  staff  5638356 May 17 13:50 nginx-heroku-20.tgz
    -rw-r--r--  1 dzuelke  staff  4559004 May 17 13:50 nginx-heroku-22.tgz
    % tar tzvf nginx-heroku-20.tgz
    -rw-r--r--  0 root   root     5349 Feb 21 01:58 ./mime.types
    -rwxr-xr-x  0 root   root  6705408 Feb 21 01:58 ./nginx
    -rwxr-xr-x  0 root   root  6870296 Feb 21 01:58 ./nginx-debug
    % tar tzvf nginx-heroku-22.tgz
    -rw-r--r--  0 root   root     5349 Feb 21 02:00 ./mime.types
    -rwxr-xr-x  0 root   root  4937400 Feb 21 02:00 ./nginx
    -rwxr-xr-x  0 root   root  5094584 Feb 21 02:00 ./nginx-debug

After:

    % ls -la nginx-heroku-2*.tgz
    -rw-r--r--  1 dzuelke  staff  3181649 May 17 13:51 nginx-heroku-20.tgz
    -rw-r--r--  1 dzuelke  staff  2638964 May 17 13:51 nginx-heroku-22.tgz
    % tar tzvf nginx-heroku-20.tgz
    -rw-r--r--  0 root   root     5349 May 17 13:30 ./mime.types
    -rwxr-xr-x  0 root   root   973624 May 17 13:30 ./nginx
    -rwxr-xr-x  0 root   root  6746392 May 17 13:30 ./nginx-debug
    % tar tzvf nginx-heroku-22.tgz
    -rw-r--r--  0 root   root     5349 May 17 13:30 ./mime.types
    -rwxr-xr-x  0 root   root   973592 May 17 13:30 ./nginx
    -rwxr-xr-x  0 root   root  4974032 May 17 13:30 ./nginx-debug
Also update headers-more-nginx-module to the latest 0.37 and pin nginx-uuid4-module to specific commit SHA
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the size reduction!

scripts/build_nginx Show resolved Hide resolved
@dzuelke dzuelke merged commit ac4cabb into main May 25, 2024
1 check passed
@dzuelke dzuelke deleted the build-cleanups branch May 25, 2024 23:03
@dzuelke dzuelke changed the title Update to Nginx 1.26, link against system images, strip nginx binary. Update to Nginx 1.26, link against system libraries, strip nginx binary May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants