Skip to content

Commit 7bf57de

Browse files
committed
Remove unused OpenSSL headers to save ~34MB of image size
1 parent c32b80c commit 7bf57de

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Dockerfile-slim.template

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ RUN groupadd --gid 1000 node \
55

66
ENV NODE_VERSION 0.0.0
77

8-
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
8+
RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
99
&& case "${dpkgArch##*-}" in \
10-
amd64) ARCH='x64';; \
11-
ppc64el) ARCH='ppc64le';; \
12-
s390x) ARCH='s390x';; \
13-
arm64) ARCH='arm64';; \
14-
armhf) ARCH='armv7l';; \
15-
i386) ARCH='x86';; \
10+
amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \
11+
ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \
12+
s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \
13+
arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \
14+
armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \
15+
i386) ARCH='x86' OPENSSL_ARCH='linux-elf';; \
1616
*) echo "unsupported architecture"; exit 1 ;; \
1717
esac \
1818
&& set -ex \
@@ -31,6 +31,8 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
3131
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
3232
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
3333
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
34+
# Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451
35+
&& find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \
3436
&& apt-mark auto '.*' > /dev/null \
3537
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
3638
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \

0 commit comments

Comments
 (0)