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/ COPY package.json /usr/src/app/
# Install only the production modules that have C extensions # 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 \ 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 webpack.config.js fix-jsonstream.js /usr/src/app/
COPY src /usr/src/app/src COPY src /usr/src/app/src
# Install devDependencies, build the coffeescript and then prune the deps # Build the coffeescript and then restore the production modules
RUN cp -R node_modules node_modules_prod \ RUN npm run lint \
&& npm install --no-optional --unsafe-perm \
&& npm run lint \
&& npm run build \ && npm run build \
&& rm -rf node_modules \ && rm -rf node_modules \
&& mv node_modules_prod node_modules && mv node_modules_prod node_modules