-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
289 lines (265 loc) · 10.4 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
FROM php:7.4.6-fpm-alpine
MAINTAINER Jing Lin <[email protected]>
ENV NGINX_VERSION 1.12.1
ENV OPENSSL_VERSION 1.0.2l
ENV OPENSSL_CHACHA https://raw.githubusercontent.com/cloudflare/sslconfig/master/patches/openssl__chacha20_poly1305_draft_and_rfc_ossl102j.patch
ENV NGX_VERSION_TRANSPARENCY=1.3.2
ENV NGX_VERSION_BROTLI=1.0.2
ENV php_conf /usr/local/etc/php-fpm.conf
ENV fpm_conf /usr/local/etc/php-fpm.d/www.conf
ENV php_vars /usr/local/etc/php/conf.d/docker-vars.ini
###################################
# OPENSSL #
###################################
RUN apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
pcre-dev \
zlib-dev \
linux-headers \
curl \
gnupg \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
wget \
ca-certificates \
g++ \
zip \
&& mkdir -p /usr/src \
&& wget https://openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz \
&& tar zxvf openssl-$OPENSSL_VERSION.tar.gz -C /usr/src \
&& rm openssl-$OPENSSL_VERSION.tar.gz \
&& wget -O /usr/src/chacha.patch $OPENSSL_CHACHA \
&& cd /usr/src/openssl-$OPENSSL_VERSION \
&& patch -p1 < ../chacha.patch \
&& ./config \
&& make depend
###################################
# CERTIFICATE TRANSPARENCY #
###################################
COPY nginx-ct-1.3.2.zip /tmp/
RUN unzip /tmp/nginx-ct-1.3.2.zip -d /usr/src \
&& rm /tmp/nginx-ct-1.3.2.zip \
&& echo "CT copyed and unzipped"
###################################
# GOOGLE BROTLI #
###################################
COPY ngx_brotli-1.0.2.zip /tmp/
RUN unzip /tmp/ngx_brotli-1.0.2.zip -d /usr/src \
&& rm /tmp/ngx_brotli-1.0.2.zip \
&& echo "BROTILI copyed and unzipped"
###################################
# TLS Dynamic Reord Sizing #
# Patch for NGINX #
###################################
RUN wget -O /usr/src/nginx-dynamic_tls.patch https://raw.githubusercontent.com/cloudflare/sslconfig/master/patches/nginx__1.11.5_dynamic_tls_records.patch \
&& echo "TLS Dynamic Reord Sizing patch downloaded"
###################################
# NGINX #
###################################
ENV GPG_KEYS B0F4253373F8F6F510D42178520A9993A1C052F8
ENV CONFIG "\
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/usr/local/nginx/conf/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-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_perl_module=dynamic \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-file-aio \
--with-http_v2_module \
--with-compat \
--with-openssl=/usr/src/openssl-$OPENSSL_VERSION \
--add-module=/usr/src/nginx-ct-${NGX_VERSION_TRANSPARENCY} \
--add-module=/usr/src/ngx_brotli-${NGX_VERSION_BROTLI} \
"
RUN \
addgroup -S www \
&& adduser -D -S -h /var/cache/www -s /sbin/nologin -G www www \
&& curl -fSL http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz -o nginx.tar.gz \
&& tar -zxC /usr/src -f nginx.tar.gz \
&& rm nginx.tar.gz \
&& cd /usr/src/nginx-$NGINX_VERSION \
&& patch -p1 < /usr/src/nginx-dynamic_tls.patch \
&& echo "Dynamic TLS size recording pathed for nginx" \
&& ./configure $CONFIG --with-debug \
&& sed -i "s/-Werror//g" /usr/src/nginx-$NGINX_VERSION/objs/Makefile \
&& make \
&& mv objs/nginx objs/nginx-debug \
&& mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
&& mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
&& mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so \
&& mv objs/ngx_http_perl_module.so objs/ngx_http_perl_module-debug.so \
&& ./configure $CONFIG \
&& sed -i "s/-Werror//g" /usr/src/nginx-$NGINX_VERSION/objs/Makefile \
&& make \
&& make install \
&& rm -rf /usr/local/nginx/html/ \
&& mkdir /usr/local/nginx/vhost/ \
&& mkdir /usr/local/nginx/ssl/ \
&& mkdir -p /var/cache/nginx/client_temp \
&& mkdir -p /var/cache/nginx/proxy_temp \
&& mkdir -p /var/cache/nginx/fastcgi_temp \
&& mkdir -p /var/cache/nginx/uwsgi_temp \
&& mkdir -p /var/cache/nginx/scgi_temp \
&& mkdir -p /home/wwwlogs/ \
&& mkdir -p /home/wwwroot/myf5/ \
&& mkdir -p /etc/letsencrypt/sct/ \
&& install -m644 html/index.html /home/wwwroot/myf5/ \
&& install -m644 html/50x.html /home/wwwroot/myf5/ \
&& install -m755 objs/nginx-debug /usr/sbin/nginx-debug \
&& install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
&& install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
&& install -m755 objs/ngx_http_geoip_module-debug.so /usr/lib/nginx/modules/ngx_http_geoip_module-debug.so \
&& install -m755 objs/ngx_http_perl_module-debug.so /usr/lib/nginx/modules/ngx_http_perl_module-debug.so \
&& ln -s ../../usr/lib/nginx/modules /usr/local/nginx/modules \
&& strip /usr/sbin/nginx* \
&& strip /usr/lib/nginx/modules/*.so \
&& runDeps="$( \
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .nginx-rundeps $runDeps \
&& apk del .build-deps \
&& rm -rf /usr/src/openssl-$OPENSSL_VERSION \
&& rm -rf /usr/src/nginx-ct-$GX_VERSION_TRANSPARENCY \
&& rm -rf /usr/src/ngx_brotli-$NGX_VERSION_BROTLI \
&& rm -rf /usr/src/nginx-dynamic_tls.patch \
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
&& apk add --no-cache gettext \
\
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
# COPY pre defined file, make sure there is correct nginx configuration files, these files are based my own nginx.
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
COPY enable-php.conf /usr/local/nginx/conf/enable-php.conf
COPY fastcgi.conf /usr/local/nginx/conf/fastcgi.conf
COPY wordpress.conf /usr/local/nginx/conf/wordpress.conf
COPY ./vhost/nginx.vh.default.conf /usr/local/nginx/conf/vhost/default.conf
COPY ./ssl/* /usr/local/nginx/conf/ssl/
COPY digicert.sct /etc/letsencrypt/sct/digicert.sct
COPY icarus.sct /etc/letsencrypt/sct/icarus.sct
COPY Shanghai /etc/localtime
########Start PHP##########
RUN echo @testing >> /etc/apk/repositories && \
echo /etc/apk/respositories && \
apk update && \
apk add --no-cache bash \
openssh-client \
wget \
supervisor \
curl \
libcurl \
git \
python \
python-dev \
py-pip \
augeas-dev \
openssl-dev \
ca-certificates \
dialog \
gcc \
musl-dev \
linux-headers \
libmcrypt-dev \
libpng-dev \
icu-dev \
libpq \
libzip \
libzip-dev \
libxslt-dev \
libffi-dev \
libmemcached-dev \
cyrus-sasl-dev \
freetype-dev \
sqlite-dev \
libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/ && \
#curl iconv session
curl -L -o /tmp/memcached.tar.gz http://pecl.php.net/get/memcached-3.1.5.tgz &&\
tar -xzvf /tmp/memcached.tar.gz &&\
mv memcached-3.1.5 /usr/src/php/ext/memcached &&\
rm /tmp/memcached.tar.gz &&\
docker-php-ext-install pdo_mysql pdo_sqlite mysqli gd exif intl xsl json soap dom zip opcache memcached && \
docker-php-source delete && \
mkdir -p /var/log/supervisor && \
echo "Asia/Shanghai" > /etc/timezone &&\
EXPECTED_COMPOSER_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '${EXPECTED_COMPOSER_SIGNATURE}') { echo 'Composer.phar Installer verified'; } else { echo 'Composer.phar Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
php -r "unlink('composer-setup.php');" && \
#pip install -U pip && \
#pip install -U certbot && \
#mkdir -p /etc/letsencrypt/webrootauth && \
apk del gcc musl-dev linux-headers libffi-dev augeas-dev python-dev &&\
rm -rf /usr/src
#############3 tweak php-fpm config##################
RUN echo "cgi.fix_pathinfo=0" > ${php_vars} &&\
echo "upload_max_filesize = 100M" >> ${php_vars} &&\
echo "post_max_size = 100M" >> ${php_vars} &&\
echo "variables_order = \"EGPCS\"" >> ${php_vars} && \
echo "memory_limit = 128M" >> ${php_vars} && \
sed -i \
-e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" \
-e "s/pm.max_children = 5/pm.max_children = 20/g" \
-e "s/pm.start_servers = 2/pm.start_servers = 10/g" \
-e "s/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g" \
-e "s/pm.max_spare_servers = 3/pm.max_spare_servers = 20/g" \
-e "s/;pm.max_requests = 500/pm.max_requests = 200/g" \
-e "s/user = www-data/user = www/g" \
-e "s/group = www-data/group = www/g" \
-e "s/;listen.mode = 0660/listen.mode = 0666/g" \
-e "s/;listen.owner = www-data/listen.owner = www/g" \
-e "s/;listen.group = www-data/listen.group = www/g" \
-e "s/listen = 127.0.0.1:9000/listen = \/tmp\/php-cgi.sock/g" \
-e "s/^;clear_env = no$/clear_env = no/" \
${fpm_conf}
ADD start.sh /start.sh
ADD supervisord.conf /etc/supervisord.conf
RUN chmod 755 /start.sh
EXPOSE 80/tcp 443/tcp
CMD ["/start.sh"]