|
| 1 | +ARG DOCKER_IMAGE=fabiocicerchia/nginx-lua |
| 2 | +ARG DOCKER_IMAGE_OS=alpine |
| 3 | +ARG DOCKER_IMAGE_TAG=3.12.0 |
| 4 | + |
| 5 | +#################################### |
| 6 | +# Build Nginx with support for LUA # |
| 7 | +#################################### |
| 8 | +FROM $DOCKER_IMAGE_OS:$DOCKER_IMAGE_TAG AS builder |
| 9 | + |
| 10 | +# https://github.com/openresty/luajit2 |
| 11 | +ARG VER_LUAJIT=2.1-20200102 |
| 12 | + |
| 13 | +# https://github.com/openresty/lua-nginx-module |
| 14 | +# Production ready. |
| 15 | +ARG VER_LUA_NGINX_MODULE=0.10.15 |
| 16 | + |
| 17 | +# https://github.com/openresty/lua-resty-core |
| 18 | +# This library is production ready. |
| 19 | +ARG VER_LUA_RESTY_CORE=0.1.17 |
| 20 | +ARG LUA_LIB_DIR=/usr/local/share/lua/5.1 |
| 21 | + |
| 22 | +# https://github.com/openresty/lua-resty-lrucache |
| 23 | +# This library is considered production ready. |
| 24 | +ARG VER_LUA_RESTY_LRUCACHE=0.09 |
| 25 | + |
| 26 | +# https://github.com/vision5/ngx_devel_kit |
| 27 | +# The NDK is now considered to be stable. |
| 28 | +ARG VER_NGX_DEVEL_KIT=0.3.1 |
| 29 | + |
| 30 | +# https://github.com/openresty/lua-resty-redis |
| 31 | +ARG VER_OPENRESTY_REDIS=0.27 |
| 32 | + |
| 33 | +# https://github.com/openresty/lua-resty-mysql |
| 34 | +ARG VER_OPENRESTY_MYSQL=0.22 |
| 35 | + |
| 36 | +#=https://github.com/openresty/lua-resty-websocket |
| 37 | +ARG VER_OPENRESTY_WEBSOCKET=0.07 |
| 38 | + |
| 39 | +# https://github.com/openresty/lua-resty-dns |
| 40 | +ARG VER_OPENRESTY_DNS=0.21 |
| 41 | + |
| 42 | +# https://github.com/openresty/lua-resty-memcached |
| 43 | +ARG VER_OPENRESTY_MEMCACHED=0.15 |
| 44 | + |
| 45 | +#=https://github.com/openresty/lua-resty-shell |
| 46 | +ARG VER_OPENRESTY_SHELL=0.02 |
| 47 | + |
| 48 | +#=https://github.com/openresty/headers-more-nginx-module |
| 49 | +ARG VER_OPENRESTY_HEADERS=743a4bb1a253325d17a4f4ce8ee61ea0d8e0cc19 |
| 50 | + |
| 51 | +#=https://github.com/openresty/stream-lua-nginx-module |
| 52 | +ARG VER_OPENRESTY_STREAMLUA=0.0.8rc3 |
| 53 | + |
| 54 | +#=https://github.com/cloudflare/lua-resty-cookie |
| 55 | +ARG VER_CLOUDFLARE_COOKIE=c54865bdcfc3c42cbd6dbbceb654ba73871d07f6 |
| 56 | + |
| 57 | +#=https://github.com/cloudflare/raven-lua |
| 58 | +ARG VER_CLOUDFLARE_RAVENLUA=ec3614daffaab4e154dd0b70ce40de24de845477 |
| 59 | + |
| 60 | +#=https://github.com/knyar/nginx-lua-prometheus |
| 61 | +ARG VER_PROMETHEUS=0.20200523 |
| 62 | + |
| 63 | +#=https://github.com/google/ngx_brotli |
| 64 | +ARG VER_GOOGLE_BROTLI=1.0.0rc |
| 65 | + |
| 66 | +#=https://www.modsecurity.org |
| 67 | + |
| 68 | +#=https://www.ngxpagespeed.com |
| 69 | +ARG NPS_VERSION=1.13.35.2-stable |
| 70 | +ARG NPS_RELEASE_NUMBER=1.13.35.2 |
| 71 | + |
| 72 | +# https://github.com/nginx/nginx |
| 73 | +ARG VER_NGINX=1.19.0 |
| 74 | +ARG NGINX_BUILD_CONFIG="\ |
| 75 | + --prefix=/etc/nginx \ |
| 76 | + --sbin-path=/usr/sbin/nginx \ |
| 77 | + --modules-path=/usr/lib/nginx/modules \ |
| 78 | + --conf-path=/etc/nginx/nginx.conf \ |
| 79 | + --error-log-path=/var/log/nginx/error.log \ |
| 80 | + --http-log-path=/var/log/nginx/access.log \ |
| 81 | + --pid-path=/var/run/nginx.pid \ |
| 82 | + --lock-path=/var/run/nginx.lock \ |
| 83 | + --http-client-body-temp-path=/var/cache/nginx/client_temp \ |
| 84 | + --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ |
| 85 | + --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ |
| 86 | + --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ |
| 87 | + --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ |
| 88 | + --user=nginx \ |
| 89 | + --group=nginx \ |
| 90 | + --add-module=/lua-nginx-module-${VER_LUA_NGINX_MODULE} \ |
| 91 | + --add-module=/ngx_devel_kit-${VER_NGX_DEVEL_KIT} \ |
| 92 | + --with-compat \ |
| 93 | + --with-file-aio \ |
| 94 | + --with-http_addition_module \ |
| 95 | + --with-http_auth_request_module \ |
| 96 | + --with-http_dav_module \ |
| 97 | + --with-http_dav_module \ |
| 98 | + --with-http_flv_module \ |
| 99 | + --with-http_geoip_module \ |
| 100 | + --with-http_gunzip_module \ |
| 101 | + --with-http_gzip_static_module \ |
| 102 | + --with-http_mp4_module \ |
| 103 | + --with-http_random_index_module \ |
| 104 | + --with-http_realip_module \ |
| 105 | + --with-http_secure_link_module \ |
| 106 | + --with-http_slice_module \ |
| 107 | + --with-http_ssl_module \ |
| 108 | + --with-http_stub_status_module \ |
| 109 | + --with-http_sub_module \ |
| 110 | + --with-http_v2_module \ |
| 111 | + --with-mail \ |
| 112 | + --with-mail_ssl_module \ |
| 113 | + --with-stream \ |
| 114 | + --with-stream_realip_module \ |
| 115 | + --with-stream_ssl_module \ |
| 116 | + --with-stream_ssl_preread_module \ |
| 117 | + --with-threads \ |
| 118 | + --add-module=/headers-more-nginx-module-${VER_OPENRESTY_HEADERS} \ |
| 119 | + --add-module=/stream-lua-nginx-module-${VER_OPENRESTY_STREAMLUA} \ |
| 120 | + " |
| 121 | +# --add-module=/ngx_brotli-${VER_GOOGLE_BROTLI} \ |
| 122 | +# --add-module=/incubator-pagespeed-ngx-${NPS_VERSION} \ |
| 123 | + |
| 124 | +ARG LUAJIT_LIB=/usr/local/lib |
| 125 | +ARG LUAJIT_INC=/usr/local/include/luajit-2.1 |
| 126 | +ARG LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH |
| 127 | + |
| 128 | +ARG BUILD_DEPS="\ |
| 129 | + curl \ |
| 130 | + g++ \ |
| 131 | + geoip-dev \ |
| 132 | + gzip \ |
| 133 | + make \ |
| 134 | + openssl-dev \ |
| 135 | + pcre-dev \ |
| 136 | + tar \ |
| 137 | + zlib-dev" |
| 138 | + |
| 139 | +ARG NGINX_BUILD_DEPS="\ |
| 140 | + alpine-sdk \ |
| 141 | + bash \ |
| 142 | + findutils \ |
| 143 | + gcc \ |
| 144 | + gd-dev \ |
| 145 | + geoip-dev \ |
| 146 | + libc-dev \ |
| 147 | + libedit-dev \ |
| 148 | + libxslt-dev \ |
| 149 | + linux-headers \ |
| 150 | + make \ |
| 151 | + mercurial \ |
| 152 | + openssl-dev \ |
| 153 | + pcre-dev \ |
| 154 | + perl-dev \ |
| 155 | + zlib-dev" |
| 156 | + |
| 157 | +RUN set -eux \ |
| 158 | + && apk update \ |
| 159 | + && apk add --no-cache \ |
| 160 | + $BUILD_DEPS \ |
| 161 | + $NGINX_BUILD_DEPS |
| 162 | + |
| 163 | +RUN set -eux \ |
| 164 | +# OpenResty LUAJIT2 |
| 165 | +# ############################################################################## |
| 166 | + && curl -Lo /luajit.tar.gz https://github.com/openresty/luajit2/archive/v${VER_LUAJIT}.tar.gz \ |
| 167 | + && tar -C / -xvzf /luajit.tar.gz && rm /luajit.tar.gz \ |
| 168 | + && cd /luajit2-${VER_LUAJIT} \ |
| 169 | + && make -j "$(nproc)" \ |
| 170 | + && make install \ |
| 171 | + \ |
| 172 | +# LUA Resty Core |
| 173 | +# ############################################################################## |
| 174 | + && curl -Lo /lua-resty-core.tar.gz https://github.com/openresty/lua-resty-core/archive/v${VER_LUA_RESTY_CORE}.tar.gz \ |
| 175 | + && tar -C / -xvzf /lua-resty-core.tar.gz && rm /lua-resty-core.tar.gz \ |
| 176 | + && cd /lua-resty-core-${VER_LUA_RESTY_CORE} \ |
| 177 | + && make -j "$(nproc)" \ |
| 178 | + && make install \ |
| 179 | + \ |
| 180 | +# LUA Resty LRUCache |
| 181 | +# ############################################################################## |
| 182 | + && curl -Lo /lua-resty-lrucache.tar.gz https://github.com/openresty/lua-resty-lrucache/archive/v${VER_LUA_RESTY_LRUCACHE}.tar.gz \ |
| 183 | + && tar -C / -xvzf /lua-resty-lrucache.tar.gz && rm /lua-resty-lrucache.tar.gz \ |
| 184 | + && cd /lua-resty-lrucache-${VER_LUA_RESTY_LRUCACHE} \ |
| 185 | + && make -j "$(nproc)" \ |
| 186 | + && make install \ |
| 187 | + \ |
| 188 | +# NGX Devel Kit |
| 189 | +# ############################################################################## |
| 190 | + && curl -Lo /ngx_devel_kit.tar.gz https://github.com/vision5/ngx_devel_kit/archive/v${VER_NGX_DEVEL_KIT}.tar.gz \ |
| 191 | + && tar -C / -xvzf /ngx_devel_kit.tar.gz && rm /ngx_devel_kit.tar.gz \ |
| 192 | + \ |
| 193 | +# Lua Nginx Module |
| 194 | +# ############################################################################## |
| 195 | + && curl -Lo /lua-nginx.tar.gz https://github.com/openresty/lua-nginx-module/archive/v${VER_LUA_NGINX_MODULE}.tar.gz \ |
| 196 | + && tar -C / -xvzf /lua-nginx.tar.gz && rm /lua-nginx.tar.gz \ |
| 197 | +# OpenResty Redis |
| 198 | +# ############################################################################## |
| 199 | + && curl -Lo /lua-openresty-redis.tar.gz https://github.com/openresty/lua-resty-redis/archive/v${VER_OPENRESTY_REDIS}.tar.gz \ |
| 200 | + && tar xvzf /lua-openresty-redis.tar.gz && rm /lua-openresty-redis.tar.gz \ |
| 201 | + && cd /lua-resty-redis-${VER_OPENRESTY_REDIS} \ |
| 202 | + && make -j "$(nproc)" \ |
| 203 | + && make install \ |
| 204 | + && cd / \ |
| 205 | +# OpenResty Mysql |
| 206 | +# ############################################################################## |
| 207 | + && curl -Lo /lua-openresty-mysql.tar.gz https://github.com/openresty/lua-resty-mysql/archive/v${VER_OPENRESTY_MYSQL}.tar.gz \ |
| 208 | + && tar xvzf /lua-openresty-mysql.tar.gz && rm /lua-openresty-mysql.tar.gz \ |
| 209 | + && cd /lua-resty-mysql-${VER_OPENRESTY_MYSQL} \ |
| 210 | + && make -j "$(nproc)" \ |
| 211 | + && make install \ |
| 212 | + && cd / \ |
| 213 | +# OpenResty Websocket |
| 214 | +# ############################################################################## |
| 215 | + && curl -Lo /lua-openresty-websocket.tar.gz https://github.com/openresty/lua-resty-websocket/archive/v${VER_OPENRESTY_WEBSOCKET}.tar.gz \ |
| 216 | + && tar xvzf /lua-openresty-websocket.tar.gz && rm /lua-openresty-websocket.tar.gz \ |
| 217 | + && cd /lua-resty-websocket-${VER_OPENRESTY_WEBSOCKET} \ |
| 218 | + && make -j "$(nproc)" \ |
| 219 | + && make install \ |
| 220 | + && cd / \ |
| 221 | +# OpenResty Dns |
| 222 | +# ############################################################################## |
| 223 | + && curl -Lo /lua-openresty-dns.tar.gz https://github.com/openresty/lua-resty-dns/archive/v${VER_OPENRESTY_DNS}.tar.gz \ |
| 224 | + && tar xvzf /lua-openresty-dns.tar.gz && rm /lua-openresty-dns.tar.gz \ |
| 225 | + && cd /lua-resty-dns-${VER_OPENRESTY_DNS} \ |
| 226 | + && make -j "$(nproc)" \ |
| 227 | + && make install \ |
| 228 | + && cd / \ |
| 229 | +# OpenResty Memcached |
| 230 | +# ############################################################################## |
| 231 | + && curl -Lo /lua-openresty-memcached.tar.gz https://github.com/openresty/lua-resty-memcached/archive/v${VER_OPENRESTY_MEMCACHED}.tar.gz \ |
| 232 | + && tar xvzf /lua-openresty-memcached.tar.gz && rm /lua-openresty-memcached.tar.gz \ |
| 233 | + && cd /lua-resty-memcached-${VER_OPENRESTY_MEMCACHED} \ |
| 234 | + && make -j "$(nproc)" \ |
| 235 | + && make install \ |
| 236 | + && cd / \ |
| 237 | +# OpenResty Shell |
| 238 | +# ############################################################################## |
| 239 | + && curl -Lo /lua-openresty-shell.tar.gz https://github.com/openresty/lua-resty-shell/archive/v${VER_OPENRESTY_SHELL}.tar.gz \ |
| 240 | + && tar xvzf /lua-openresty-shell.tar.gz && rm /lua-openresty-shell.tar.gz \ |
| 241 | + && cd /lua-resty-shell-${VER_OPENRESTY_SHELL} \ |
| 242 | + && make -j "$(nproc)" \ |
| 243 | + && make install \ |
| 244 | + && cd / \ |
| 245 | +# OpenResty Headers |
| 246 | +# ############################################################################## |
| 247 | + && curl -Lo /headers-more-nginx-module.zip https://github.com/openresty/headers-more-nginx-module/archive/${VER_OPENRESTY_HEADERS}.zip \ |
| 248 | + && unzip /headers-more-nginx-module.zip && rm /headers-more-nginx-module.zip \ |
| 249 | +# OpenResty Stream Lua |
| 250 | +# ############################################################################## |
| 251 | + && curl -Lo /stream-lua-nginx-module.zip https://github.com/openresty/stream-lua-nginx-module/archive/v${VER_OPENRESTY_STREAMLUA}.zip \ |
| 252 | + && unzip /stream-lua-nginx-module.zip && rm /stream-lua-nginx-module.zip \ |
| 253 | +# Cloudflare Cookie |
| 254 | +# ############################################################################## |
| 255 | + && curl -Lo /lua-resty-cookie.tar.gz https://github.com/cloudflare/lua-resty-cookie/archive/${VER_CLOUDFLARE_COOKIE}.tar.gz \ |
| 256 | + && tar xvzf /lua-resty-cookie.tar.gz && rm /lua-resty-cookie.tar.gz \ |
| 257 | + && cd /lua-resty-cookie-${VER_CLOUDFLARE_COOKIE} \ |
| 258 | + && make -j "$(nproc)" \ |
| 259 | + && make install \ |
| 260 | + && cd / \ |
| 261 | +# Cloudflare Raven Lua |
| 262 | +# ############################################################################## |
| 263 | +# && curl -Lo /raven-lua.tar.gz https://github.com/cloudflare/raven-lua/archive/${VER_CLOUDFLARE_RAVENLUA}.tar.gz \ |
| 264 | +# && tar xvzf /raven-lua.tar.gz && rm /raven-lua.tar.gz \ |
| 265 | +# && cd /raven-lua-${VER_CLOUDFLARE_RAVENLUA} \ |
| 266 | +# && make -j "$(nproc)" \ |
| 267 | +# && make install \ |
| 268 | +# && cd / \ |
| 269 | +# Prometheus |
| 270 | +# ############################################################################## |
| 271 | + && curl -Lo /nginx-lua-prometheus.tar.gz https://github.com/knyar/nginx-lua-prometheus/archive/${VER_PROMETHEUS}.tar.gz \ |
| 272 | + && tar xvzf /nginx-lua-prometheus.tar.gz && rm /nginx-lua-prometheus.tar.gz \ |
| 273 | + && mv nginx-lua-prometheus-${VER_PROM_LUA}/prometheus.lua nginx-lua-prometheus-${VER_PROM_LUA}/prometheus_keys.lua nginx-lua-prometheus-${VER_PROM_LUA}/prometheus_resty_counter.lua ${LUA_LIB_DIR}/ \ |
| 274 | + && rm -rf /prom-lua* \ |
| 275 | +# Google Brotli |
| 276 | +# ############################################################################## |
| 277 | + && curl -Lo /ngx_brotli.tar.gz https://github.com/google/ngx_brotli/archive/v${VER_GOOGLE_BROTLI}.tar.gz \ |
| 278 | + && tar xvzf /ngx_brotli.tar.gz && rm /ngx_brotli.tar.gz \ |
| 279 | + |
| 280 | +RUN set -eux \ |
| 281 | +# NGINX |
| 282 | +# ############################################################################## |
| 283 | +# we're on an architecture upstream doesn't officially build for |
| 284 | +# let's build binaries from the published packaging sources |
| 285 | + && curl -Lo /nginx.tar.gz https://nginx.org/download/nginx-${VER_NGINX}.tar.gz \ |
| 286 | + && tar -C / -xvzf /nginx.tar.gz && rm /nginx.tar.gz \ |
| 287 | + && cd /nginx-${VER_NGINX} \ |
| 288 | + && mkdir -p /var/cache/nginx/client_temp \ |
| 289 | + /var/cache/nginx/proxy_temp \ |
| 290 | + /var/cache/nginx/fastcgi_temp \ |
| 291 | + /var/cache/nginx/uwsgi_temp \ |
| 292 | + /var/cache/nginx/scgi_temp \ |
| 293 | + && ./configure \ |
| 294 | + ${NGINX_BUILD_CONFIG} \ |
| 295 | + --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \ |
| 296 | + --with-ld-opt='-Wl,-rpath,/usr/local/lib -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \ |
| 297 | + && make -j "$(nproc)" build \ |
| 298 | + && make install |
| 299 | + |
| 300 | +########################################## |
| 301 | +# Combine everything with minimal layers # |
| 302 | +########################################## |
| 303 | +FROM $DOCKER_IMAGE_OS:$DOCKER_IMAGE_TAG |
| 304 | + |
| 305 | +ARG DOCKER_IMAGE=fabiocicerchia/nginx-lua |
| 306 | +ARG DOCKER_IMAGE_OS=alpine |
| 307 | +ARG DOCKER_IMAGE_TAG=3.12.0 |
| 308 | +ARG VER_NGINX=1.19.0 |
| 309 | +ARG BUILD_DATE |
| 310 | +ARG VCS_REF |
| 311 | + |
| 312 | +# http://label-schema.org/rc1/ |
| 313 | +LABEL maintainer="Fabio Cicerchia < [email protected]>" \ |
| 314 | + org.label-schema.build-date=$BUILD_DATE \ |
| 315 | + org.label-schema.description="Nginx $VER_NGINX with LUA support based on $DOCKER_IMAGE_OS $DOCKER_IMAGE_TAG." \ |
| 316 | + org.label-schema.docker.cmd="docker run -p 80:80 -d $DOCKER_IMAGE:$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG" \ |
| 317 | + org.label-schema.name="$DOCKER_IMAGE" \ |
| 318 | + org.label-schema.schema-version="1.0" \ |
| 319 | + org.label-schema.url="https://github.com/$DOCKER_IMAGE" \ |
| 320 | + org.label-schema.vcs-ref=$VCS_REF \ |
| 321 | + org.label-schema.vcs-url="https://github.com/$DOCKER_IMAGE" \ |
| 322 | + org.label-schema.version="$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG" |
| 323 | + |
| 324 | +# https://github.com/Yelp/dumb-init |
| 325 | +ARG VER_DUMBINIT=1.2.2 |
| 326 | + |
| 327 | +ARG PKG_DEPS="\ |
| 328 | + geoip-dev \ |
| 329 | + openssl-dev \ |
| 330 | + pcre-dev \ |
| 331 | + zlib-dev" |
| 332 | + |
| 333 | +COPY --from=builder /etc/nginx /etc/nginx |
| 334 | +COPY --from=builder /usr/local/lib /usr/local/lib |
| 335 | +COPY --from=builder /usr/local/share/lua /usr/local/share/lua |
| 336 | +COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx |
| 337 | +COPY --from=builder /var/cache/nginx /var/cache/nginx |
| 338 | + |
| 339 | +RUN set -eux \ |
| 340 | + && apk update \ |
| 341 | + && apk add --no-cache \ |
| 342 | + $PKG_DEPS \ |
| 343 | +# Bring in tzdata so users could set the timezones through the environment |
| 344 | +# variables |
| 345 | + && apk add --no-cache tzdata \ |
| 346 | +# Bring in curl and ca-certificates to make registering on DNS SD easier |
| 347 | + && apk add --no-cache curl ca-certificates \ |
| 348 | +# forward request and error logs to docker log collector |
| 349 | + && mkdir -p /var/log/nginx \ |
| 350 | + && ln -sf /dev/stdout /var/log/nginx/access.log \ |
| 351 | + && ln -sf /dev/stderr /var/log/nginx/error.log \ |
| 352 | +# dumb-init |
| 353 | +# ############################################################################## |
| 354 | + && curl -Lo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${VER_DUMBINIT}/dumb-init_${VER_DUMBINIT}_x86_64 \ |
| 355 | + && chmod +x /usr/bin/dumb-init \ |
| 356 | +# create nginx user/group first, to be consistent throughout docker variants |
| 357 | + && addgroup -g 32548 -S nginx \ |
| 358 | + && adduser -S -D -H -u 32548 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx |
| 359 | + |
| 360 | +HEALTHCHECK --interval=30s --timeout=3s CMD curl --fail http://localhost/ || exit 1 |
| 361 | + |
| 362 | +EXPOSE 80 |
| 363 | +EXPOSE 443 |
| 364 | + |
| 365 | +STOPSIGNAL SIGTERM |
| 366 | + |
| 367 | +ENTRYPOINT ["dumb-init"] |
| 368 | + |
| 369 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments