Dockerfile: cleanup unused files after installation

This commit is contained in:
Jesse Chan
2020-12-11 12:54:40 +08:00
parent b4c7dc020c
commit 5caeeaeb12
+18 -7
View File
@@ -18,28 +18,39 @@ RUN apk --no-cache add \
python build-base python build-base
# Fetch dependencies from npm # Fetch dependencies from npm
RUN npm set unsafe-perm true RUN npm ci --no-optional
RUN npm install
# Build package # Build package
RUN cp config.cli.js config.js RUN cp config.cli.js config.js
RUN npm run build RUN npm pack
RUN npm pack --ignore-scripts
# Now get the clean image # Now get the clean image
FROM ${NODE_IMAGE} as flood FROM ${NODE_IMAGE} as flood
# Copy package built # Copy package built
COPY --from=nodebuild /usr/src/app/*.tgz /tmp/ COPY --from=nodebuild /usr/src/app/flood-*.tgz /tmp/
# Install package # Install package
RUN npm i -g /tmp/*.tgz --unsafe-perm RUN npm i -g /tmp/flood-*.tgz
RUN rm /tmp/*.tgz
# Install runtime dependencies # Install runtime dependencies
RUN apk --no-cache add \ RUN apk --no-cache add \
mediainfo 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 # Create "download" user
RUN adduser -h /home/download -s /sbin/nologin --disabled-password download RUN adduser -h /home/download -s /sbin/nologin --disabled-password download