From 5caeeaeb12e6c130e49d9cdc1cfdf4341a4138e5 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Fri, 11 Dec 2020 12:54:40 +0800 Subject: [PATCH] Dockerfile: cleanup unused files after installation --- Dockerfile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2a5e97b4..6ff4e2a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,28 +18,39 @@ RUN apk --no-cache add \ python build-base # Fetch dependencies from npm -RUN npm set unsafe-perm true -RUN npm install +RUN npm ci --no-optional # Build package RUN cp config.cli.js config.js -RUN npm run build -RUN npm pack --ignore-scripts +RUN npm pack # Now get the clean image FROM ${NODE_IMAGE} as flood # Copy package built -COPY --from=nodebuild /usr/src/app/*.tgz /tmp/ +COPY --from=nodebuild /usr/src/app/flood-*.tgz /tmp/ # Install package -RUN npm i -g /tmp/*.tgz --unsafe-perm -RUN rm /tmp/*.tgz +RUN npm i -g /tmp/flood-*.tgz # Install runtime dependencies RUN apk --no-cache add \ mediainfo +# Remove temporary files and caches +RUN rm -rf /tmp/* /root/* + +# Cleanups below are destructive +# Let the maintainer know if there is a usecase that requires extension to this image + +# Remove apk, npm and yarn +RUN rm -rf /lib/apk /sbin/apk +RUN rm -rf /usr/local/lib/node_modules/npm +RUN rm -rf /opt/* + +# Remove Node.js development files +RUN rm -rf /usr/local/include/node + # Create "download" user RUN adduser -h /home/download -s /sbin/nologin --disabled-password download