Skip to content

Commit

Permalink
container/build: change NODE_ENV handling
Browse files Browse the repository at this point in the history
This alters the Containerfile's setting of NODE_ENV so it's less susceptible to
future line-order changes having unintended side effects.
  • Loading branch information
jpluscplusm committed Jan 10, 2025
1 parent 3ed6f1c commit 79dfd40
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions container/build/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@ RUN date \
######################
## Node dependencies #
######################
ARG NODE_ENV=production
ENV NODE_ENV=$NODE_ENV
# Copy node dependency manifests into the container image.
COPY package.json package-lock.json $APP_CODE/
# "setting NODE_ENV to anything but production is considered an antipattern."
# (https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production)
# However, the version of npm we currently use doesn't appear to offer any way
# to make "npm ci" install the devDependencies (which include the "gulp"
# command that's required later in this build) when NODE_ENV="production".
# Therefore we delay setting NODE_ENV until after "npm ci" has run.
# arg NODE_ENV=production
# env NODE_ENV=$NODE_ENV
# Install dependencies.
# The version of npm we currently use doesn't appear to offer any way to make
# "npm ci" install the devDependencies (which include the "gulp" command that's
# required later in this build) when NODE_ENV="production". We fix this by
# overriding NODE_ENV for these npm commands. Whilst "npm cache clean" might
# not require the same value, we keep it aligned in case it has some effect
# (e.g. maybe the cache location is env-specific, etc).
RUN date \
&& export NODE_ENV=development \
&& cd $APP_CODE/ \
&& npm ci \
&& npm cache clean --force \
&& date
ARG NODE_ENV=production
ENV NODE_ENV=$NODE_ENV

########################
## Python dependencies #
Expand Down

0 comments on commit 79dfd40

Please sign in to comment.