1
- FROM alpine:3.12
2
-
3
- LABEL maintainer=
"NGINX Docker Maintainers <[email protected] >"
4
-
5
- ENV NGINX_VERSION 1.19.2
1
+ ARG NGINX_VERSION=1.19.2
6
2
7
3
# https://github.com/google/ngx_brotli
8
- ENV NGX_BROTLI_COMMIT 25f86f0bac1101b6512135eac5f93c49c63609e3
9
-
10
- RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
11
- && CONFIG="\
4
+ ARG NGX_BROTLI_COMMIT=25f86f0bac1101b6512135eac5f93c49c63609e3
5
+ ARG CONFIG="\
12
6
--prefix=/etc/nginx \
13
7
--sbin-path=/usr/sbin/nginx \
14
8
--modules-path=/usr/lib/nginx/modules \
@@ -40,7 +34,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
40
34
--with-http_xslt_module=dynamic \
41
35
--with-http_image_filter_module=dynamic \
42
36
--with-http_geoip_module=dynamic \
43
- --with-http_perl_module=dynamic \
44
37
--with-threads \
45
38
--with-stream \
46
39
--with-stream_ssl_module \
@@ -54,10 +47,17 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
54
47
--with-file-aio \
55
48
--with-http_v2_module \
56
49
--add-module=/usr/src/ngx_brotli \
57
- " \
58
- && addgroup -S nginx \
59
- && adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
60
- && apk add --no-cache --virtual .build-deps \
50
+ "
51
+
52
+ FROM alpine:3.12
53
+ LABEL maintainer=
"NGINX Docker Maintainers <[email protected] >"
54
+
55
+ ARG NGINX_VERSION
56
+ ARG NGX_BROTLI_COMMIT
57
+ ARG CONFIG
58
+
59
+ RUN \
60
+ apk add --no-cache --virtual .build-deps \
61
61
gcc \
62
62
libc-dev \
63
63
make \
@@ -70,41 +70,49 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
70
70
libxslt-dev \
71
71
gd-dev \
72
72
geoip-dev \
73
- perl-dev \
74
73
&& apk add --no-cache --virtual .brotli-build-deps \
75
74
autoconf \
76
75
libtool \
77
76
automake \
78
77
git \
79
78
g++ \
80
- cmake \
81
- && mkdir -p /usr/src \
82
- && cd /usr/src \
83
- && git clone --recursive https://github.com/google/ngx_brotli.git \
84
- && cd ngx_brotli \
85
- && git checkout -b $NGX_BROTLI_COMMIT $NGX_BROTLI_COMMIT \
79
+ cmake
80
+
81
+ COPY nginx.pub /tmp/nginx.pub
82
+
83
+ RUN \
84
+ echo "Compiling nginx $NGINX_VERSION with brotli $NGX_BROTLI_COMMIT" \
85
+ && mkdir -p /usr/src/ngx_brotli \
86
+ && cd /usr/src/ngx_brotli \
87
+ && git init \
88
+ && git remote add origin https://github.com/google/ngx_brotli.git \
89
+ && git fetch --depth 1 origin $NGX_BROTLI_COMMIT \
90
+ && git checkout --recurse-submodules -q FETCH_HEAD \
91
+ && git submodule update --init --depth 1 \
86
92
&& cd .. \
87
93
&& curl -fSL https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz -o nginx.tar.gz \
88
94
&& curl -fSL https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz.asc -o nginx.tar.gz.asc \
89
95
&& sha512sum nginx.tar.gz nginx.tar.gz.asc \
90
96
&& export GNUPGHOME="$(mktemp -d)" \
91
- && gpg --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$GPG_KEYS" \
97
+ && gpg --import /tmp/nginx.pub \
92
98
&& gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz \
93
- && rm -rf "$GNUPGHOME" nginx.tar.gz.asc \
94
99
&& mkdir -p /usr/src \
95
- && tar -zxC /usr/src -f nginx.tar.gz \
96
- && rm nginx.tar.gz \
97
- && cd /usr/src/nginx-$NGINX_VERSION \
100
+ && tar -zxC /usr/src -f nginx.tar.gz
101
+
102
+ RUN \
103
+ cd /usr/src/nginx-$NGINX_VERSION \
98
104
&& ./configure $CONFIG --with-debug \
99
105
&& make -j$(getconf _NPROCESSORS_ONLN) \
100
106
&& mv objs/nginx objs/nginx-debug \
101
107
&& mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
102
108
&& mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
103
109
&& mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so \
104
- && mv objs/ngx_http_perl_module.so objs/ngx_http_perl_module-debug.so \
105
110
&& mv objs/ngx_stream_geoip_module.so objs/ngx_stream_geoip_module-debug.so \
106
111
&& ./configure $CONFIG \
107
- && make -j$(getconf _NPROCESSORS_ONLN) \
112
+ && make -j$(getconf _NPROCESSORS_ONLN)
113
+
114
+ RUN \
115
+ cd /usr/src/nginx-$NGINX_VERSION \
108
116
&& make install \
109
117
&& rm -rf /etc/nginx/html/ \
110
118
&& mkdir /etc/nginx/conf.d/ \
@@ -115,13 +123,9 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
115
123
&& install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
116
124
&& install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
117
125
&& install -m755 objs/ngx_http_geoip_module-debug.so /usr/lib/nginx/modules/ngx_http_geoip_module-debug.so \
118
- && install -m755 objs/ngx_http_perl_module-debug.so /usr/lib/nginx/modules/ngx_http_perl_module-debug.so \
119
126
&& install -m755 objs/ngx_stream_geoip_module-debug.so /usr/lib/nginx/modules/ngx_stream_geoip_module-debug.so \
120
- && ln -s ../../usr/lib/nginx/modules /etc/nginx/modules \
121
127
&& strip /usr/sbin/nginx* \
122
128
&& strip /usr/lib/nginx/modules/*.so \
123
- && rm -rf /usr/src/nginx-$NGINX_VERSION \
124
- && rm -rf /usr/src/ngx_brotli \
125
129
\
126
130
# https://tools.ietf.org/html/rfc7919
127
131
# https://github.com/mozilla/ssl-config-generator/blob/master/docs/ffdhe2048.txt
@@ -132,22 +136,32 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
132
136
# then move `envsubst` out of the way so `gettext` can
133
137
# be deleted completely, then move `envsubst` back.
134
138
&& apk add --no-cache --virtual .gettext gettext \
135
- && mv /usr/bin/envsubst /tmp/ \
136
139
\
137
- && runDeps="$( \
138
- scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
140
+ && scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so /usr/bin/envsubst \
139
141
| awk '{ gsub(/,/, "\n so:", $2); print "so:" $2 }' \
140
142
| sort -u \
141
143
| xargs -r apk info --installed \
142
- | sort -u \
143
- )" \
144
- && apk add --no-cache --virtual .nginx-rundeps tzdata $runDeps \
145
- && apk del .build-deps \
146
- && apk del .brotli-build-deps \
147
- && apk del .gettext \
148
- && mv /tmp/envsubst /usr/local/bin/ \
149
- \
144
+ | sort -u > /tmp/runDeps.txt
145
+
146
+ FROM alpine:3.12
147
+ ARG NGINX_VERSION
148
+
149
+ COPY --from=0 /tmp/runDeps.txt /tmp/runDeps.txt
150
+ COPY --from=0 /etc/nginx /etc/nginx
151
+ COPY --from=0 /usr/lib/nginx/modules/*.so /usr/lib/nginx/modules/
152
+ COPY --from=0 /usr/sbin/nginx /usr/sbin/nginx-debug /usr/sbin/
153
+ COPY --from=0 /usr/share/nginx/html/* /usr/share/nginx/html/
154
+ COPY --from=0 /usr/bin/envsubst /usr/local/bin/envsubst
155
+
156
+ RUN \
157
+ addgroup -S nginx \
158
+ && adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
159
+ && apk add --no-cache --virtual .nginx-rundeps tzdata $(cat /tmp/runDeps.txt) \
160
+ && rm /tmp/runDeps.txt \
161
+ && ln -s /usr/lib/nginx/modules /etc/nginx/modules \
150
162
# forward request and error logs to docker log collector
163
+ && mkdir /var/log/nginx \
164
+ && touch /var/log/nginx/access.log /var/log/nginx/error.log \
151
165
&& ln -sf /dev/stdout /var/log/nginx/access.log \
152
166
&& ln -sf /dev/stderr /var/log/nginx/error.log
153
167
0 commit comments