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..2451c9b --- /dev/null +++ b/scripts/build-brotli @@ -0,0 +1,27 @@ +#!/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}" + +# Determine the correct binary file for the architecture given +M64="-m64" +if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then + 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 + + 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}" +fi diff --git a/scripts/build-openresty b/scripts/build-openresty index 9f3a1bb..d9d859d 100755 --- a/scripts/build-openresty +++ b/scripts/build-openresty @@ -12,10 +12,16 @@ 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 +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 \ @@ -55,7 +61,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 \ + ${BROTI_MODULE} make -j2