-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
205 lines (185 loc) · 7.79 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
FROM ubuntu:18.04
LABEL Alexander Radyushin <alexander@fjedi.com>
ENV NGX_BROTLI_COMMIT="bcceaab88e555f686d5ed39dfb238f898df2788c" \
NGX_PAGESPEED_VERSION="1.13.35.2" \
RUNTIME_DEPS="curl bash mc nano sed gcc make openssl iputils-ping net-tools" \
PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
# Docker Build Arguments
ARG OPENRESTY_VERSION="1.19.9.1"
ARG OPENRESTY_LUAROCKS_VERSION="2.4.4"
ARG OPENRESTY_OPENSSL_VERSION="1.1.1l"
ARG OPENRESTY_PCRE_VERSION="8.42"
ARG OPENRESTY_J="2"
ARG OPENRESTY_CONFIG_OPTIONS="\
--with-file-aio \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--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-http_xslt_module=dynamic \
--with-ipv6 \
--with-mail \
--with-mail_ssl_module \
--with-md5-asm \
--with-pcre-jit \
--with-sha1-asm \
--with-stream \
--with-stream_ssl_module \
--with-threads \
--add-module=/usr/src/ngx_brotli \
--add-module=/usr/src/incubator-pagespeed-ngx-${NGX_PAGESPEED_VERSION}-stable \
"
ARG OPENRESTY_CONFIG_OPTIONS_MORE=""
# These are not intended to be user-specified
ARG _OPENRESTY_CONFIG_DEPS="--with-openssl=/tmp/openssl-${OPENRESTY_OPENSSL_VERSION} --with-pcre=/tmp/pcre-${OPENRESTY_PCRE_VERSION}"
# 1) Install apt dependencies
# 2) Download and untar OpenSSL, PCRE, and OpenResty
# 3) Build OpenResty
# 4) Cleanup
RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y $RUNTIME_DEPS \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
gettext-base \
libgd-dev \
libgeoip-dev \
libncurses5-dev \
libperl-dev \
libreadline-dev \
libxslt1-dev \
make \
perl \
unzip \
zlib1g-dev \
git \
autoconf \
libtool \
automake \
# Required to build ngx_pagespeed module
uuid-dev \
# Packages required for graceful nginx-reload on configuration changes
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
inotify-tools \
supervisor \
&& cd /tmp \
&& curl -fSL https://www.openssl.org/source/openssl-${OPENRESTY_OPENSSL_VERSION}.tar.gz -o openssl-${OPENRESTY_OPENSSL_VERSION}.tar.gz \
&& tar xzf openssl-${OPENRESTY_OPENSSL_VERSION}.tar.gz \
&& curl -fSL https://ftp.pcre.org/pub/pcre/pcre-${OPENRESTY_PCRE_VERSION}.tar.gz -o pcre-${OPENRESTY_PCRE_VERSION}.tar.gz \
&& tar xzf pcre-${OPENRESTY_PCRE_VERSION}.tar.gz \
&& curl -fSL https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz -o openresty-${OPENRESTY_VERSION}.tar.gz \
&& tar xzf openresty-${OPENRESTY_VERSION}.tar.gz \
&& cd /usr/local/lib \
&& git clone https://github.com/bagder/libbrotli \
&& cd /usr/local/lib/libbrotli \
&& ./autogen.sh \
&& ./configure \
&& make install \
# Remove "RANDFILE" setting from openssl config to avoid "Can't load ./.rnd into RNG" error
&& cat /etc/ssl/openssl.cnf | sed "s/RANDFILE\s*=\s*\$ENV::HOME\/\.rnd/#/" > /etc/ssl/openssl.cnf \
# Download Brotli
&& cd /usr/src \
&& echo "Downloading Brotli compression plugin..." \
&& git clone --recursive https://github.com/google/ngx_brotli.git \
&& cd ngx_brotli \
&& git checkout -b $NGX_BROTLI_COMMIT $NGX_BROTLI_COMMIT \
# Download PageSpeed
&& cd /usr/src \
&& echo "Downloading PageSpeed..." \
&& curl -L https://github.com/pagespeed/ngx_pagespeed/archive/v${NGX_PAGESPEED_VERSION}-stable.tar.gz | tar -zx \
# psol needs to be inside ngx_pagespeed module
# Download PageSpeed Optimization Library and extract it to nginx source dir
&& cd /usr/src/incubator-pagespeed-ngx-${NGX_PAGESPEED_VERSION}-stable/ \
&& echo "Downloading PSOL..." \
&& curl -L https://dl.google.com/dl/page-speed/psol/${NGX_PAGESPEED_VERSION}-x64.tar.gz | tar -zx \
&& ls -la /usr/src/incubator-pagespeed-ngx-${NGX_PAGESPEED_VERSION}-stable/ \
&& mkdir -p /tmp/nginx/pagespeed/images/ \
# Building openresty from sources
&& cd /tmp/openresty-${OPENRESTY_VERSION} \
&& ./configure -j${OPENRESTY_J} ${_OPENRESTY_CONFIG_DEPS} ${OPENRESTY_CONFIG_OPTIONS} ${OPENRESTY_CONFIG_OPTIONS_MORE} \
&& make -j${OPENRESTY_J} \
&& make -j${OPENRESTY_J} install \
&& cd /tmp \
&& rm -rf \
openssl-${OPENRESTY_OPENSSL_VERSION} \
openssl-${OPENRESTY_OPENSSL_VERSION}.tar.gz \
openresty-${OPENRESTY_VERSION}.tar.gz openresty-${OPENRESTY_VERSION} \
pcre-${OPENRESTY_PCRE_VERSION}.tar.gz pcre-${OPENRESTY_PCRE_VERSION} \
&& curl -fSL https://github.com/luarocks/luarocks/archive/${OPENRESTY_LUAROCKS_VERSION}.tar.gz -o luarocks-${OPENRESTY_LUAROCKS_VERSION}.tar.gz \
&& tar xzf luarocks-${OPENRESTY_LUAROCKS_VERSION}.tar.gz \
&& cd luarocks-${OPENRESTY_LUAROCKS_VERSION} \
&& ./configure \
--prefix=/usr/local/openresty/luajit \
--with-lua=/usr/local/openresty/luajit \
--lua-suffix=jit-2.1.0-beta3 \
--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 \
&& make build \
&& make install \
&& cd /tmp \
&& rm -rf luarocks-${OPENRESTY_LUAROCKS_VERSION} luarocks-${OPENRESTY_LUAROCKS_VERSION}.tar.gz \
&& DEBIAN_FRONTEND=noninteractive apt-get autoremove -y \
&& ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log \
&& ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log
RUN groupadd nginx \
&& useradd -g nginx nginx \
&& usermod -s /bin/false nginx \
&& echo 'nginx ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
#
RUN luarocks install lua-resty-auto-ssl
RUN mkdir /etc/resty-auto-ssl && chown -cR nginx.nginx /etc/resty-auto-ssl && chmod 777 -cR /etc/resty-auto-ssl
COPY openssl.cnf /etc/ssl/openssl.cnf
RUN openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 \
-keyout /etc/ssl/resty-auto-ssl-fallback.key \
-out /etc/ssl/resty-auto-ssl-fallback.crt
# Create folders required by pagespeed module
RUN mkdir -p /var/cache/nginx/pagespeed \
&& chown nginx:root /var/cache/nginx/pagespeed \
&& chmod 700 /var/cache/nginx/pagespeed \
&& mkdir /var/log/pagespeed \
&& chown nginx. /var/log/pagespeed
# Get GeoIP database
RUN mkdir -p /usr/local/openresty/nginx/data/geoip
# We use pre-downloaded files, if you need latest versions of *.dat files
# you may download them from https://www.miyuru.lk/geoiplegacy
COPY data/geoip/*.dat /usr/local/openresty/nginx/data/geoip/
# Map default nginx-conf directory to openresty
RUN mkdir -p /etc/nginx/conf.d/ \
&& chown -cR nginx.nginx /etc/nginx/conf.d/ \
&& chmod 770 -cR /etc/nginx/conf.d/ \
&& ln -s /etc/nginx/conf.d /usr/local/openresty/nginx/conf/
# Adding custom 403, 404 and 50x error-pages
ADD error_pages /etc/nginx/error_pages
RUN chown -cR nginx.nginx /etc/nginx/error_pages/ \
&& ln -s /etc/nginx/error_pages /usr/local/openresty/nginx/conf/
# Remove default nginx.conf
RUN rm /usr/local/openresty/nginx/conf/nginx.conf
# Copy config that includes recommended ssl/security rules
COPY nginx.ssl.default.conf /usr/local/openresty/nginx/conf/nginx.ssl.default.conf
# Copy config with core-settings for pagespeed module
COPY nginx.pagespeed.core.conf /usr/local/openresty/nginx/conf/nginx.pagespeed.core.conf
#
ADD presets /usr/local/openresty/nginx/conf/presets
# Create folder to store nginx logs
RUN mkdir -p /var/log/nginx
#
EXPOSE 80 443
#
VOLUME ["/etc/nginx/error_pages", "/etc/nginx/conf.d", "/etc/resty-auto-ssl"]
COPY nginx.supervisor.conf /etc/supervisor/conf.d/nginx.conf
#
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
RUN chmod a+x /usr/local/bin/docker_entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"]