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