Skip to content

Commit ea9478c

Browse files
committed
Only run npm install /app when starting non-production apps
The npm install functionality ran on each launch. The installed packages are already fetched during the build phase, hence there should be no reason to fetch the npm packages again unless we are running in development mode. The earlier implementations also did an npm install of the image's packages. These should be bundled with the image and should not be updated accidentally. Hence we choose to only run the npm install on build of the template image, not on the build of the docker image which uses this template.
1 parent 2a87466 commit ea9478c

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ ONBUILD RUN if [ -f /app/on-build.sh ]; \
2323
&& chmod +x /app/on-build.sh \
2424
&& /bin/bash /app/on-build.sh ;\
2525
fi
26-
ONBUILD RUN cd /usr/src/app && npm install && if [ -f "/app/package.json" ]; then npm install /app; fi
26+
ONBUILD RUN if [ -f "/app/package.json" ]; then npm install /app; fi

boot.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#! /bin/sh
2-
## Install new dependencies
3-
if [ -f "/app/package.json" ];
4-
then
5-
npm install /app
6-
fi
7-
npm install
8-
92
if [ "$NODE_ENV" == "production" ];
103
then
114
./node_modules/supervisor/lib/cli-wrapper.js \
125
-i . \
136
-k --ignore-symlinks \
147
-x sh start.sh
158
else
9+
## Install new dependencies
10+
if [ -f "/app/package.json" ]; then npm install /app; fi
11+
## Boot the app in development mode
1612
./node_modules/supervisor/lib/cli-wrapper.js \
1713
-w /usr/src/app,/app \
1814
-i /usr/src/app/node_modules,/usr/src/app/helpers,/app/node_modules \

0 commit comments

Comments
 (0)