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
62
73# 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="\
126 --prefix=/etc/nginx \
137 --sbin-path=/usr/sbin/nginx \
148 --modules-path=/usr/lib/nginx/modules \
@@ -40,7 +34,6 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
4034 --with-http_xslt_module=dynamic \
4135 --with-http_image_filter_module=dynamic \
4236 --with-http_geoip_module=dynamic \
43- --with-http_perl_module=dynamic \
4437 --with-threads \
4538 --with-stream \
4639 --with-stream_ssl_module \
@@ -54,10 +47,17 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
5447 --with-file-aio \
5548 --with-http_v2_module \
5649 --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 \
6161 gcc \
6262 libc-dev \
6363 make \
@@ -70,41 +70,49 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
7070 libxslt-dev \
7171 gd-dev \
7272 geoip-dev \
73- perl-dev \
7473 && apk add --no-cache --virtual .brotli-build-deps \
7574 autoconf \
7675 libtool \
7776 automake \
7877 git \
7978 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 \
8692 && cd .. \
8793 && curl -fSL https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz -o nginx.tar.gz \
8894 && curl -fSL https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz.asc -o nginx.tar.gz.asc \
8995 && sha512sum nginx.tar.gz nginx.tar.gz.asc \
9096 && export GNUPGHOME="$(mktemp -d)" \
91- && gpg --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$GPG_KEYS" \
97+ && gpg --import /tmp/nginx.pub \
9298 && gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz \
93- && rm -rf "$GNUPGHOME" nginx.tar.gz.asc \
9499 && 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 \
98104 && ./configure $CONFIG --with-debug \
99105 && make -j$(getconf _NPROCESSORS_ONLN) \
100106 && mv objs/nginx objs/nginx-debug \
101107 && mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
102108 && mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
103109 && 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 \
105110 && mv objs/ngx_stream_geoip_module.so objs/ngx_stream_geoip_module-debug.so \
106111 && ./configure $CONFIG \
107- && make -j$(getconf _NPROCESSORS_ONLN) \
112+ && make -j$(getconf _NPROCESSORS_ONLN)
113+
114+ RUN \
115+ cd /usr/src/nginx-$NGINX_VERSION \
108116 && make install \
109117 && rm -rf /etc/nginx/html/ \
110118 && mkdir /etc/nginx/conf.d/ \
@@ -115,13 +123,9 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
115123 && install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
116124 && install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
117125 && 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 \
119126 && 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 \
121127 && strip /usr/sbin/nginx* \
122128 && strip /usr/lib/nginx/modules/*.so \
123- && rm -rf /usr/src/nginx-$NGINX_VERSION \
124- && rm -rf /usr/src/ngx_brotli \
125129 \
126130 # https://tools.ietf.org/html/rfc7919
127131 # https://github.com/mozilla/ssl-config-generator/blob/master/docs/ffdhe2048.txt
@@ -132,22 +136,32 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
132136 # then move `envsubst` out of the way so `gettext` can
133137 # be deleted completely, then move `envsubst` back.
134138 && apk add --no-cache --virtual .gettext gettext \
135- && mv /usr/bin/envsubst /tmp/ \
136139 \
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 \
139141 | awk '{ gsub(/,/, "\n so:", $2); print "so:" $2 }' \
140142 | sort -u \
141143 | 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 \
150162 # 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 \
151165 && ln -sf /dev/stdout /var/log/nginx/access.log \
152166 && ln -sf /dev/stderr /var/log/nginx/error.log
153167
0 commit comments