Skip to content

Commit 59c3ac4

Browse files
committed
Update examples to reflect new Docker guidance
1 parent 9920d21 commit 59c3ac4

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

examples/Dockerfile.service

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This assumes that the parent image has been built locally using production and development build configuration as defra-node
22
# and defra-node-development tagged with a version.
33

4-
ARG BASE_VERSION=2.7.0-node22.14.0
4+
ARG BASE_VERSION=2.10.3-node24.12.0
55
FROM defra-node:$BASE_VERSION AS base
66

77
# Copy our package files so that our package install will do a clean install. This installs the exact versions of the packages
@@ -39,7 +39,14 @@ CMD [ "npm", "run", "test" ]
3939
# Production stage exposes service port, copies in built app code and declares the Node app as the default command
4040
FROM base AS production
4141

42+
# Copy application artifacts and assign root ownership to prevent modification by other users.
43+
COPY --from=development --chown=root:root /home/node/package*.json ./
44+
COPY --from=development --chown=root:root /home/node/app/ ./app/
45+
46+
# Install node modules and remove write permissions.
47+
RUN npm ci --ignore-scripts --omit=dev && chmod -R a-w /home/node
48+
4249
# This is the command that is run for the production service. The parent image has an ENTRYPOINT that uses a lightweight
43-
# init program "tini" that handles signals. As long as we don't override the ENTRYPOINT the "tini" routine will handle signals and
44-
# orphaned processes
50+
# init program "tini" that handles signals. As long as we don't override the ENTRYPOINT the "tini" routine will handle signals and
51+
# orphaned processes
4552
CMD [ "node", "app/index" ]

examples/Dockerfile.web

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This assumes that the parent image has been built locally using production and development build configuration as defra-node
22
# and defra-node-development tagged with a version.
33

4-
ARG BASE_VERSION=2.5.2-node22.14.0
4+
ARG BASE_VERSION=2.10.3-node24.12.0
55
FROM defra-node:$BASE_VERSION AS base
66

77
# Set the port that is going to be exposed later on in the Dockerfile as well.
@@ -53,10 +53,14 @@ WORKDIR /home/node
5353
EXPOSE ${PORT}
5454

5555
# Copy in the files that we built using the tools in the development stage. The final production stage will have the built files,
56-
# but none of the tools required to build those files. This reduces the attack surface, and also the size of the final production image
57-
COPY --from=development /home/node/app/ ./app/
56+
# but none of the tools required to build those files. This reduces the attack surface, and also the size of the final production image
57+
COPY --from=development --chown=root:root /home/node/package*.json ./
58+
COPY --from=development --chown=root:root /home/node/app/ ./app/
59+
60+
# Install node modules and remove write permissions.
61+
RUN npm ci --ignore-scripts --omit=dev && chmod -R a-w /home/node
5862

5963
# This is the command that is run for the production service. The parent image has an ENTRYPOINT that uses a lightweight
60-
# init program "tini" that handles signals. As long as we don't override the ENTRYPOINT the "tini" routine will handle signals and
61-
# orphaned processes
64+
# init program "tini" that handles signals. As long as we don't override the ENTRYPOINT the "tini" routine will handle signals and
65+
# orphaned processes
6266
CMD [ "node", "app/index" ]

0 commit comments

Comments
 (0)