1
- FROM alpine:3.11.6
1
+ ARG DOCKER_IMAGE=fabiocicerchia/nginx-lua
2
+ ARG DOCKER_IMAGE_OS=alpine
3
+ ARG DOCKER_IMAGE_TAG=3.11.6
2
4
3
- LABEL maintainer=
"[email protected] "
5
+ # ###################################
6
+ # Build Nginx with support for LUA #
7
+ # ###################################
8
+ FROM $DOCKER_IMAGE_OS:$DOCKER_IMAGE_TAG AS builder
4
9
5
10
ARG BUILD_DATE
6
11
ARG BUILD_VERSION
7
12
ARG VCS_REF
8
13
9
- LABEL org.label-schema.schema-version="1.0"
10
- LABEL org.label-schema.build-date=$BUILD_DATE
11
- LABEL org.label-schema.name="fabiocicerchia/nginx-lua"
12
- LABEL org.label-schema.description="Nginx 1.19.0 with LUA support based on alpine 3.11.6."
13
- LABEL org.label-schema.url="https://github.com/fabiocicerchia/nginx-lua"
14
- LABEL org.label-schema.vcs-url="https://github.com/fabiocicerchia/nginx-lua"
15
- LABEL org.label-schema.vcs-ref=$VCS_REF
16
- LABEL org.label-schema.version=$BUILD_VERSION
17
- LABEL org.label-schema.docker.cmd="docker run -p 80:80 -d fabiocicerchia/nginx-lua:1.19.0-alpine3.11.6"
18
-
19
14
# https://github.com/openresty/luajit2
20
- ENV VER_LUAJIT 2.1-20200102
15
+ ARG VER_LUAJIT= 2.1-20200102
21
16
22
17
# https://github.com/openresty/lua-nginx-module
23
18
# Production ready.
24
- ENV VER_LUA_NGINX_MODULE 0.10.15
19
+ ARG VER_LUA_NGINX_MODULE= 0.10.15
25
20
26
21
# https://github.com/openresty/lua-resty-core
27
22
# This library is production ready.
28
- ENV VER_LUA_RESTY_CORE 0.1.17
29
- ENV LUA_LIB_DIR /usr/local/share/lua/5.1
23
+ ARG VER_LUA_RESTY_CORE= 0.1.17
24
+ ARG LUA_LIB_DIR= /usr/local/share/lua/5.1
30
25
31
26
# https://github.com/openresty/lua-resty-lrucache
32
27
# This library is considered production ready.
33
- ENV VER_LUA_RESTY_LRUCACHE 0.09
34
-
35
- # https://github.com/nginx/nginx
36
- ENV VER_NGINX 1.19.0
28
+ ARG VER_LUA_RESTY_LRUCACHE=0.09
37
29
38
30
# https://github.com/vision5/ngx_devel_kit
39
31
# The NDK is now considered to be stable.
40
- ENV VER_NGX_DEVEL_KIT 0.3.1
41
-
42
- # https://github.com/Yelp/dumb-init
43
- ENV VER_DUMBINIT 1.2.2
44
-
45
- ENV LUAJIT_LIB /usr/local/lib
46
- ENV LUAJIT_INC /usr/local/include/luajit-2.1
47
- ENV LD_LIBRARY_PATH /usr/local/lib/:$LD_LIBRARY_PATH
32
+ ARG VER_NGX_DEVEL_KIT=0.3.1
48
33
49
- RUN set -x \
50
- && apk update \
51
- && apk add --no-cache \
52
- geoip-dev \
53
- openssl-dev \
54
- pcre-dev \
55
- zlib-dev \
56
- && apk add --no-cache --virtual .build-deps \
57
- curl \
58
- g++ \
59
- gzip \
60
- make \
61
- tar \
62
- # OpenResty LUAJIT2
63
- # ##############################################################################
64
- && curl -Lo /luajit.tar.gz https://github.com/openresty/luajit2/archive/v${VER_LUAJIT}.tar.gz \
65
- && tar xvzf /luajit.tar.gz && rm /luajit.tar.gz \
66
- && cd /luajit2-${VER_LUAJIT} \
67
- && make -j "$(nproc)" \
68
- && make install \
69
- && cd / \
70
- # LUA Resty Core
71
- # ##############################################################################
72
- && curl -Lo /lua-resty-core.tar.gz https://github.com/openresty/lua-resty-core/archive/v${VER_LUA_RESTY_CORE}.tar.gz \
73
- && tar xvzf /lua-resty-core.tar.gz && rm /lua-resty-core.tar.gz \
74
- && cd /lua-resty-core-${VER_LUA_RESTY_CORE} \
75
- && make -j "$(nproc)" \
76
- && make install \
77
- && cd / \
78
- # LUA Resty LRUCache
79
- # ##############################################################################
80
- && curl -Lo /lua-resty-lrucache.tar.gz https://github.com/openresty/lua-resty-lrucache/archive/v${VER_LUA_RESTY_LRUCACHE}.tar.gz \
81
- && tar xvzf /lua-resty-lrucache.tar.gz && rm /lua-resty-lrucache.tar.gz \
82
- && cd /lua-resty-lrucache-${VER_LUA_RESTY_LRUCACHE} \
83
- && make -j "$(nproc)" \
84
- && make install \
85
- && cd / \
86
- # NGX Devel Kit
87
- # ##############################################################################
88
- && curl -Lo /ngx_devel_kit.tar.gz https://github.com/vision5/ngx_devel_kit/archive/v${VER_NGX_DEVEL_KIT}.tar.gz \
89
- && tar xvzf /ngx_devel_kit.tar.gz && rm /ngx_devel_kit.tar.gz \
90
- # Lua Nginx Module
91
- # ##############################################################################
92
- && curl -Lo /lua-nginx.tar.gz https://github.com/openresty/lua-nginx-module/archive/v${VER_LUA_NGINX_MODULE}.tar.gz \
93
- && tar xvzf /lua-nginx.tar.gz && rm /lua-nginx.tar.gz \
94
- # NGINX
95
- # ##############################################################################
96
- # create nginx user/group first, to be consistent throughout docker variants
97
- && addgroup -g 32548 -S nginx \
98
- && adduser -S -D -H -u 32548 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
99
- # we're on an architecture upstream doesn't officially build for
100
- # let's build binaries from the published packaging sources
101
- && apk add --no-cache --virtual .nginx-build-deps \
102
- alpine-sdk \
103
- bash \
104
- findutils \
105
- gcc \
106
- gd-dev \
107
- geoip-dev \
108
- libc-dev \
109
- libedit-dev \
110
- libxslt-dev \
111
- linux-headers \
112
- make \
113
- mercurial \
114
- openssl-dev \
115
- pcre-dev \
116
- perl-dev \
117
- zlib-dev \
118
- && curl -Lo /nginx.tar.gz https://nginx.org/download/nginx-${VER_NGINX}.tar.gz \
119
- && tar xvzf /nginx.tar.gz && rm /nginx.tar.gz \
120
- && cd /nginx-${VER_NGINX} \
121
- && mkdir -p /var/cache/nginx/client_temp \
122
- /var/cache/nginx/proxy_temp \
123
- /var/cache/nginx/fastcgi_temp \
124
- /var/cache/nginx/uwsgi_temp \
125
- /var/cache/nginx/scgi_temp \
126
- && ./configure \
34
+ # https://github.com/nginx/nginx
35
+ ARG VER_NGINX=1.19.0
36
+ ARG NGINX_BUILD_CONFIG="\
127
37
--prefix=/etc/nginx \
128
38
--sbin-path=/usr/sbin/nginx \
129
39
--modules-path=/usr/lib/nginx/modules \
@@ -133,19 +43,22 @@ RUN set -x \
133
43
--pid-path=/var/run/nginx.pid \
134
44
--lock-path=/var/run/nginx.lock \
135
45
--http-client-body-temp-path=/var/cache/nginx/client_temp \
136
- --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
137
46
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
138
- --http-uwsgi -temp-path=/var/cache/nginx/uwsgi_temp \
47
+ --http-proxy -temp-path=/var/cache/nginx/proxy_temp \
139
48
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
49
+ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
140
50
--user=nginx \
141
51
--group=nginx \
52
+ --add-module=/lua-nginx-module-${VER_LUA_NGINX_MODULE} \
53
+ --add-module=/ngx_devel_kit-${VER_NGX_DEVEL_KIT} \
142
54
--with-compat \
143
55
--with-file-aio \
144
- --with-threads \
145
56
--with-http_addition_module \
146
57
--with-http_auth_request_module \
147
58
--with-http_dav_module \
59
+ --with-http_dav_module \
148
60
--with-http_flv_module \
61
+ --with-http_geoip_module \
149
62
--with-http_gunzip_module \
150
63
--with-http_gzip_static_module \
151
64
--with-http_mp4_module \
@@ -163,34 +76,155 @@ RUN set -x \
163
76
--with-stream_realip_module \
164
77
--with-stream_ssl_module \
165
78
--with-stream_ssl_preread_module \
166
- --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
167
- --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
168
- --add-module=/lua-nginx-module-${VER_LUA_NGINX_MODULE} \
169
- --add-module=/ngx_devel_kit-${VER_NGX_DEVEL_KIT} \
170
- --with-http_dav_module \
171
- --with-http_geoip_module \
172
- && make -j "$(nproc)" build \
173
- && make install \
79
+ --with-threads \
80
+ "
81
+
82
+ ARG LUAJIT_LIB=/usr/local/lib
83
+ ARG LUAJIT_INC=/usr/local/include/luajit-2.1
84
+ ARG LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
85
+
86
+ ARG BUILD_DEPS="\
87
+ curl \
88
+ g++ \
89
+ geoip-dev \
90
+ gzip \
91
+ make \
92
+ openssl-dev \
93
+ pcre-dev \
94
+ tar \
95
+ zlib-dev"
96
+
97
+ ARG NGINX_BUILD_DEPS="\
98
+ alpine-sdk \
99
+ bash \
100
+ findutils \
101
+ gcc \
102
+ gd-dev \
103
+ geoip-dev \
104
+ libc-dev \
105
+ libedit-dev \
106
+ libxslt-dev \
107
+ linux-headers \
108
+ make \
109
+ mercurial \
110
+ openssl-dev \
111
+ pcre-dev \
112
+ perl-dev \
113
+ zlib-dev"
114
+
115
+ RUN set -eux \
116
+ && apk update \
117
+ && apk add --no-cache \
118
+ $BUILD_DEPS \
119
+ $NGINX_BUILD_DEPS
120
+
121
+ RUN set -eux \
122
+ # OpenResty LUAJIT2
123
+ # ##############################################################################
124
+ && curl -Lo /luajit.tar.gz https://github.com/openresty/luajit2/archive/v${VER_LUAJIT}.tar.gz \
125
+ && tar -C / -xvzf /luajit.tar.gz && rm /luajit.tar.gz \
126
+ && cd /luajit2-${VER_LUAJIT} \
127
+ && make -j "$(nproc)" \
128
+ && make install \
129
+ \
130
+ # LUA Resty Core
131
+ # ##############################################################################
132
+ && curl -Lo /lua-resty-core.tar.gz https://github.com/openresty/lua-resty-core/archive/v${VER_LUA_RESTY_CORE}.tar.gz \
133
+ && tar -C / -xvzf /lua-resty-core.tar.gz && rm /lua-resty-core.tar.gz \
134
+ && cd /lua-resty-core-${VER_LUA_RESTY_CORE} \
135
+ && make -j "$(nproc)" \
136
+ && make install \
137
+ \
138
+ # LUA Resty LRUCache
139
+ # ##############################################################################
140
+ && curl -Lo /lua-resty-lrucache.tar.gz https://github.com/openresty/lua-resty-lrucache/archive/v${VER_LUA_RESTY_LRUCACHE}.tar.gz \
141
+ && tar -C / -xvzf /lua-resty-lrucache.tar.gz && rm /lua-resty-lrucache.tar.gz \
142
+ && cd /lua-resty-lrucache-${VER_LUA_RESTY_LRUCACHE} \
143
+ && make -j "$(nproc)" \
144
+ && make install \
145
+ \
146
+ # NGX Devel Kit
147
+ # ##############################################################################
148
+ && curl -Lo /ngx_devel_kit.tar.gz https://github.com/vision5/ngx_devel_kit/archive/v${VER_NGX_DEVEL_KIT}.tar.gz \
149
+ && tar -C / -xvzf /ngx_devel_kit.tar.gz && rm /ngx_devel_kit.tar.gz \
150
+ \
151
+ # Lua Nginx Module
152
+ # ##############################################################################
153
+ && curl -Lo /lua-nginx.tar.gz https://github.com/openresty/lua-nginx-module/archive/v${VER_LUA_NGINX_MODULE}.tar.gz \
154
+ && tar -C / -xvzf /lua-nginx.tar.gz && rm /lua-nginx.tar.gz
155
+
156
+ RUN set -eux \
157
+ # NGINX
158
+ # ##############################################################################
159
+ # we're on an architecture upstream doesn't officially build for
160
+ # let's build binaries from the published packaging sources
161
+ && curl -Lo /nginx.tar.gz https://nginx.org/download/nginx-${VER_NGINX}.tar.gz \
162
+ && tar -C / -xvzf /nginx.tar.gz && rm /nginx.tar.gz \
163
+ && cd /nginx-${VER_NGINX} \
164
+ && mkdir -p /var/cache/nginx/client_temp \
165
+ /var/cache/nginx/proxy_temp \
166
+ /var/cache/nginx/fastcgi_temp \
167
+ /var/cache/nginx/uwsgi_temp \
168
+ /var/cache/nginx/scgi_temp \
169
+ && ./configure \
170
+ ${NGINX_BUILD_CONFIG} \
171
+ --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
172
+ --with-ld-opt='-Wl,-rpath,/usr/local/lib -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
173
+ && make -j "$(nproc)" build \
174
+ && make install
175
+
176
+ # #########################################
177
+ # Combine everything with minimal layers #
178
+ # #########################################
179
+ FROM $DOCKER_IMAGE_OS:$DOCKER_IMAGE_TAG
180
+
181
+ # http://label-schema.org/rc1/
182
+ LABEL maintainer=
"Fabio Cicerchia <[email protected] >" \
183
+ org.label-schema.build-date=$BUILD_DATE \
184
+ org.label-schema.description="Nginx $VER_NGINX with LUA support based on $DOCKER_IMAGE_OS $DOCKER_IMAGE_TAG." \
185
+ org.label-schema.docker.cmd="docker run -p 80:80 -d $DOCKER_IMAGE:$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG" \
186
+ org.label-schema.name="$DOCKER_IMAGE" \
187
+ org.label-schema.schema-version="1.0" \
188
+ org.label-schema.url="https://github.com/$DOCKER_IMAGE" \
189
+ org.label-schema.vcs-ref=$VCS_REF \
190
+ org.label-schema.vcs-url="https://github.com/$DOCKER_IMAGE" \
191
+ org.label-schema.version="$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG"
192
+
193
+ # https://github.com/Yelp/dumb-init
194
+ ARG VER_DUMBINIT=1.2.2
195
+
196
+ ARG PKG_DEPS="\
197
+ geoip-dev \
198
+ openssl-dev \
199
+ pcre-dev \
200
+ zlib-dev"
201
+
202
+ COPY --from=builder /etc/nginx /etc/nginx
203
+ COPY --from=builder /usr/local/lib /usr/local/lib
204
+ COPY --from=builder /usr/local/share/lua /usr/local/share/lua
205
+ COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx
206
+ COPY --from=builder /var/cache/nginx /var/cache/nginx
207
+
208
+ RUN set -eux \
209
+ && apk update \
210
+ && apk add --no-cache \
211
+ $PKG_DEPS \
174
212
# Bring in tzdata so users could set the timezones through the environment
175
213
# variables
176
- && apk add --no-cache tzdata \
214
+ && apk add --no-cache tzdata \
177
215
# Bring in curl and ca-certificates to make registering on DNS SD easier
178
- && apk add --no-cache curl ca-certificates \
216
+ && apk add --no-cache curl ca-certificates \
179
217
# forward request and error logs to docker log collector
180
- && ln -sf /dev/stdout /var/log/nginx/access.log \
181
- && ln -sf /dev/stderr /var/log/nginx/error.log \
218
+ && mkdir -p /var/log/nginx \
219
+ && ln -sf /dev/stdout /var/log/nginx/access.log \
220
+ && ln -sf /dev/stderr /var/log/nginx/error.log \
182
221
# dumb-init
183
222
# ##############################################################################
184
- && apk add --no-cache dumb-init \
185
- # Cleanup
186
- # ##############################################################################
187
- && rm -rf /lua-nginx-module-${VER_LUA_NGINX_MODULE} \
188
- && rm -rf /lua-resty-core-${VER_LUA_RESTY_CORE} \
189
- && rm -rf /lua-resty-lrucache-${VER_LUA_RESTY_LRUCACHE} \
190
- && rm -rf /luajit2-${VER_LUAJIT} \
191
- && rm -rf /nginx-${VER_NGINX} \
192
- && rm -rf /ngx_devel_kit-${VER_NGX_DEVEL_KIT} \
193
- && apk del .build-deps .nginx-build-deps
223
+ && curl -Lo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${VER_DUMBINIT}/dumb-init_${VER_DUMBINIT}_x86_64 \
224
+ && chmod +x /usr/bin/dumb-init \
225
+ # create nginx user/group first, to be consistent throughout docker variants
226
+ && addgroup -g 32548 -S nginx \
227
+ && adduser -S -D -H -u 32548 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx
194
228
195
229
HEALTHCHECK --interval=30s --timeout=3s CMD curl --fail http://localhost/ || exit 1
196
230
0 commit comments