2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-22 10:08:55 +00:00

Docker: slim down image size, by removing temp/cache files (PR #1128)

Per the [note](https://github.com/nativefier/nativefier/pull/1122#discussion_r588922780) by @SuperSandro2000 in #1122 Docker will still cache files in intermediate layers if you delete them, so they'll still be part of the image.

Only solution seems to be to delete them as you create them so they don't cache:
Per https://stackoverflow.com/questions/53998310/docker-remove-file-from-intermediate-layer

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This commit is contained in:
Adam Weeden 2021-03-10 18:54:33 -05:00 committed by GitHub
parent 9b455670c4
commit e9ccb35825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 23 deletions

View File

@ -1,3 +1,6 @@
# git
.git*
# OSX # OSX
.DS_Store .DS_Store
@ -7,11 +10,12 @@
lib/* lib/*
app/lib/* app/lib/*
built-tests built-tests
# commit a placeholder to keep the app/lib directory
!app/lib/.placeholder
dist dist
app/dist
# Docs
docs
*.md
# Logs # Logs
logs logs

View File

@ -2,44 +2,52 @@ FROM node:12-alpine
LABEL description="Alpine image to build Nativefier apps" LABEL description="Alpine image to build Nativefier apps"
# Install dependencies # Install dependencies and cleanup extraneous files
RUN apk update \ RUN apk update \
&& apk add bash wine imagemagick dos2unix \ && apk add bash wine imagemagick dos2unix \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*
# Use node (1000) as default user not root
USER node
ENV NPM_PACKAGES="/home/node/npm-packages"
ENV PATH="$PATH:$NPM_PACKAGES/bin"
ENV MANPATH="$MANPATH:$NPM_PACKAGES/share/man"
# Setup a global packages location for "node" user so we can npm link
RUN mkdir $NPM_PACKAGES \
&& npm config set prefix $NPM_PACKAGES
WORKDIR /nativefier WORKDIR /nativefier
# Add sources # Add sources with node as the owner so that it has the power it needs to build in /nativefier
COPY . . COPY --chown=node:node . .
# Fix line endings that may have gotten mangled in Windows # Fix line endings that may have gotten mangled in Windows
RUN find ./icon-scripts ./src ./app -type f -print0 | xargs -0 dos2unix RUN find ./icon-scripts ./src ./app -type f -print0 | xargs -0 dos2unix
# Build nativefier and link globally # Link (which will install and build)
WORKDIR /nativefier/app # Run tests (to ensure we don't Docker build & publish broken stuff)
RUN npm install # Cleanup leftover files in this step to not waste Docker layer space
WORKDIR /nativefier # Make sure nativefier is executable
RUN npm link \
# Install (note that we had to manually install in `app` before, as `prepare` won't run as root) && npm test \
# Also, running tests, to ensure we don't Docker build & publish broken stuff && rm -rf /tmp/nativefier* ~/.npm/_cacache ~/.cache/electron \
RUN npm install && npm run build && npm test && npm link && chmod +x $NPM_PACKAGES/bin/nativefier
# Cleanup test artifacts
RUN rm -rf /tmp/nativefier*
# Use 1000 as default user not root
USER 1000
# Run a {lin,mac,win} build # Run a {lin,mac,win} build
# 1. to check installation was sucessful # 1. to check installation was sucessful
# 2. to cache electron distributables and avoid downloads at runtime # 2. to cache electron distributables and avoid downloads at runtime
# Also delete generated apps so they don't get added to the Docker layer
# !Important! The `rm -rf` command must be in the same `RUN` command (using an `&&`), to not waste Docker layer space
RUN nativefier https://github.com/nativefier/nativefier /tmp/nativefier \ RUN nativefier https://github.com/nativefier/nativefier /tmp/nativefier \
&& nativefier -p osx https://github.com/nativefier/nativefier /tmp/nativefier \ && nativefier -p osx https://github.com/nativefier/nativefier /tmp/nativefier \
&& nativefier -p windows https://github.com/nativefier/nativefier /tmp/nativefier && nativefier -p windows https://github.com/nativefier/nativefier /tmp/nativefier \
&& rm -rf /tmp/nativefier
RUN echo Generated Electron cache size: $(du -sh ~/.cache/electron) \ RUN echo Generated Electron cache size: $(du -sh ~/.cache/electron) \
&& rm -rf /tmp/nativefier \
&& echo Final image size: $(du -sh / 2>/dev/null) && echo Final image size: $(du -sh / 2>/dev/null)
ENTRYPOINT ["nativefier"] ENTRYPOINT ["nativefier"]