From 5d4df92e790e5e435ef7216892faa1f90bc490b9 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Thu, 17 Oct 2024 15:34:52 +1000 Subject: [PATCH 1/3] Adds ngx_brotli module --- docker/Dockerfile | 6 ++++++ scripts/build-brotli | 21 +++++++++++++++++++++ scripts/build-openresty | 4 +++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 scripts/build-brotli diff --git a/docker/Dockerfile b/docker/Dockerfile index 882d97e..0bf64a6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,6 +11,7 @@ ARG LUAROCKS_VERSION RUN apt-get update \ && apt-get install -y \ build-essential \ + cmake \ ca-certificates \ libncurses-dev \ libpcre3-dev \ @@ -22,6 +23,10 @@ RUN apt-get update \ git \ libmaxminddb-dev +# brotli build +COPY ./scripts/build-brotli /tmp/build-brotli +RUN /tmp/build-brotli + # Lua build COPY ./scripts/build-lua /tmp/build-lua RUN /tmp/build-lua @@ -70,6 +75,7 @@ COPY ./files/.bashrc /root/.bashrc # Copy lua and luarocks builds from first image COPY --from=nginxbuilder /tmp/lua /tmp/lua +COPY --from=nginxbuilder /tmp/ngx_brotli /tmp/ngx_brotli COPY --from=nginxbuilder /tmp/luarocks /tmp/luarocks COPY ./scripts/install-lua /tmp/install-lua diff --git a/scripts/build-brotli b/scripts/build-brotli new file mode 100755 index 0000000..86be383 --- /dev/null +++ b/scripts/build-brotli @@ -0,0 +1,21 @@ +#!/bin/bash -e + +BLUE='\E[1;34m' +CYAN='\E[1;36m' +YELLOW='\E[1;33m' +GREEN='\E[1;32m' +RESET='\E[0m' + +echo -e "${BLUE}❯ ${CYAN}Building brotli ${YELLOW}${LUA_VERSION}...${RESET}" + +cd /tmp +git clone --recurse-submodules -j8 "https://github.com/google/ngx_brotli" +cd /tmp/ngx_brotli/deps/brotli + +mkdir -p /tmp/ngx_brotli/deps/brotli/out +cd /tmp/ngx_brotli/deps/brotli/out + +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. +cmake --build . --config Release --target brotlienc + +echo -e "${BLUE}❯ ${GREEN}brotli build completed${RESET}" diff --git a/scripts/build-openresty b/scripts/build-openresty index 9f3a1bb..8b309ff 100755 --- a/scripts/build-openresty +++ b/scripts/build-openresty @@ -12,6 +12,7 @@ cd /tmp wget "https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz" tar -xzf openresty-${OPENRESTY_VERSION}.tar.gz mv /tmp/openresty-${OPENRESTY_VERSION} /tmp/openresty + git clone https://github.com/leev/ngx_http_geoip2_module.git mv /tmp/ngx_http_geoip2_module /tmp/openresty/ngx_http_geoip2_module cd /tmp/openresty @@ -55,7 +56,8 @@ cd /tmp/openresty --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ - --add-dynamic-module=/tmp/openresty/ngx_http_geoip2_module + --add-dynamic-module=/tmp/openresty/ngx_http_geoip2_module \ + --add-module=/tmp/ngx_brotli make -j2 From 34baebfb6191c12a36931a16ea7d6fe4693db98f Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Fri, 18 Oct 2024 06:59:23 +1000 Subject: [PATCH 2/3] Switch brotli build for non-64 arch --- scripts/build-brotli | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/build-brotli b/scripts/build-brotli index 86be383..620e94a 100755 --- a/scripts/build-brotli +++ b/scripts/build-brotli @@ -8,6 +8,12 @@ RESET='\E[0m' echo -e "${BLUE}❯ ${CYAN}Building brotli ${YELLOW}${LUA_VERSION}...${RESET}" +# Determine the correct binary file for the architecture given +M64="-m64" +if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then + M64= +fi + cd /tmp git clone --recurse-submodules -j8 "https://github.com/google/ngx_brotli" cd /tmp/ngx_brotli/deps/brotli @@ -15,7 +21,7 @@ cd /tmp/ngx_brotli/deps/brotli mkdir -p /tmp/ngx_brotli/deps/brotli/out cd /tmp/ngx_brotli/deps/brotli/out -cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast $M64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. cmake --build . --config Release --target brotlienc echo -e "${BLUE}❯ ${GREEN}brotli build completed${RESET}" From 88a1005ba4ded3a2977bc2e43d2649f5d297cbd2 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Fri, 18 Oct 2024 07:05:58 +1000 Subject: [PATCH 3/3] Skip brotli module entirely for non-64bit archs --- scripts/build-brotli | 22 +++++++++++----------- scripts/build-openresty | 7 ++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/build-brotli b/scripts/build-brotli index 620e94a..2451c9b 100755 --- a/scripts/build-brotli +++ b/scripts/build-brotli @@ -11,17 +11,17 @@ echo -e "${BLUE}❯ ${CYAN}Building brotli ${YELLOW}${LUA_VERSION}...${RESET}" # Determine the correct binary file for the architecture given M64="-m64" if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then - M64= -fi - -cd /tmp -git clone --recurse-submodules -j8 "https://github.com/google/ngx_brotli" -cd /tmp/ngx_brotli/deps/brotli + echo -e "${BLUE}❯ ${YELLOW}Skipping brotli for non-64bit arch${RESET}" +else + cd /tmp + git clone --recurse-submodules -j8 "https://github.com/google/ngx_brotli" + cd /tmp/ngx_brotli/deps/brotli -mkdir -p /tmp/ngx_brotli/deps/brotli/out -cd /tmp/ngx_brotli/deps/brotli/out + mkdir -p /tmp/ngx_brotli/deps/brotli/out + cd /tmp/ngx_brotli/deps/brotli/out -cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast $M64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. -cmake --build . --config Release --target brotlienc + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. + cmake --build . --config Release --target brotlienc -echo -e "${BLUE}❯ ${GREEN}brotli build completed${RESET}" + echo -e "${BLUE}❯ ${GREEN}brotli build completed${RESET}" +fi diff --git a/scripts/build-openresty b/scripts/build-openresty index 8b309ff..d9d859d 100755 --- a/scripts/build-openresty +++ b/scripts/build-openresty @@ -17,6 +17,11 @@ git clone https://github.com/leev/ngx_http_geoip2_module.git mv /tmp/ngx_http_geoip2_module /tmp/openresty/ngx_http_geoip2_module cd /tmp/openresty +BROTI_MODULE="--add-module=/tmp/ngx_brotli" +if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then + BROTI_MODULE= +fi + ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ @@ -57,7 +62,7 @@ cd /tmp/openresty --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --add-dynamic-module=/tmp/openresty/ngx_http_geoip2_module \ - --add-module=/tmp/ngx_brotli + ${BROTI_MODULE} make -j2