Dockerfile: improve caching by installing devDependencies before copying the code

This should help avoid having to run the npm install for devDependencies (which are actually most of the modules)
every time there's a change in the code.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-12-11 12:44:08 -08:00
parent b000c0c9ee
commit 12ab5c16ea

View File

@ -142,16 +142,17 @@ RUN mkdir -p rootfs-overlay && \
COPY package.json /usr/src/app/
# Install only the production modules that have C extensions
# Save the modules and then install devDependencies for build
RUN JOBS=MAX npm install --production --no-optional --unsafe-perm \
&& npm dedupe
&& npm dedupe \
&& cp -R node_modules node_modules_prod \
&& npm install --no-optional --unsafe-perm
COPY webpack.config.js fix-jsonstream.js /usr/src/app/
COPY src /usr/src/app/src
# Install devDependencies, build the coffeescript and then prune the deps
RUN cp -R node_modules node_modules_prod \
&& npm install --no-optional --unsafe-perm \
&& npm run lint \
# Build the coffeescript and then restore the production modules
RUN npm run lint \
&& npm run build \
&& rm -rf node_modules \
&& mv node_modules_prod node_modules