Skip to content

Commit d54d200

Browse files
mattrobenoltthresheek
authored andcommitted
Extract only envsubst out of gettext
This results in a reduction of ~5.5MB from the image. Before: 59688904 bytes After: 54104509 bytes
1 parent 8456df2 commit d54d200

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

mainline/alpine/Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,26 @@ RUN \
9999
&& ln -s ../../usr/lib/nginx/modules /etc/nginx/modules \
100100
&& strip /usr/sbin/nginx* \
101101
&& strip /usr/lib/nginx/modules/*.so \
102+
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
103+
\
104+
# Bring in gettext so we can get `envsubst`, then throw
105+
# the rest away. To do this, we need to install `gettext`
106+
# then move `envsubst` out of the way so `gettext` can
107+
# be deleted completely, then move `envsubst` back.
108+
&& apk add --no-cache --virtual .gettext gettext \
109+
&& mv /usr/bin/envsubst /tmp/ \
110+
\
102111
&& runDeps="$( \
103-
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so \
112+
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
104113
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
105114
| sort -u \
106115
| xargs -r apk info --installed \
107116
| sort -u \
108117
)" \
109-
&& apk add --virtual .nginx-rundeps $runDeps \
118+
&& apk add --no-cache --virtual .nginx-rundeps $runDeps \
110119
&& apk del .build-deps \
111-
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
112-
&& apk add --no-cache gettext \
120+
&& apk del .gettext \
121+
&& mv /tmp/envsubst /usr/bin/ \
113122
\
114123
# forward request and error logs to docker log collector
115124
&& ln -sf /dev/stdout /var/log/nginx/access.log \

stable/alpine/Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,26 @@ RUN \
9999
&& ln -s ../../usr/lib/nginx/modules /etc/nginx/modules \
100100
&& strip /usr/sbin/nginx* \
101101
&& strip /usr/lib/nginx/modules/*.so \
102+
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
103+
\
104+
# Bring in gettext so we can get `envsubst`, then throw
105+
# the rest away. To do this, we need to install `gettext`
106+
# then move `envsubst` out of the way so `gettext` can
107+
# be deleted completely, then move `envsubst` back.
108+
&& apk add --no-cache --virtual .gettext gettext \
109+
&& mv /usr/bin/envsubst /tmp/ \
110+
\
102111
&& runDeps="$( \
103-
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so \
112+
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
104113
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
105114
| sort -u \
106115
| xargs -r apk info --installed \
107116
| sort -u \
108117
)" \
109-
&& apk add --virtual .nginx-rundeps $runDeps \
118+
&& apk add --no-cache --virtual .nginx-rundeps $runDeps \
110119
&& apk del .build-deps \
111-
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
112-
&& apk add --no-cache gettext \
120+
&& apk del .gettext \
121+
&& mv /tmp/envsubst /usr/bin/ \
113122
\
114123
# forward request and error logs to docker log collector
115124
&& ln -sf /dev/stdout /var/log/nginx/access.log \

0 commit comments

Comments
 (0)