Skip to content

Commit 4065f06

Browse files
committed
Minor cleanup to production Dockerfile. Update to Node v22. Add inline comments. Use Dockerfile best practices for ENTRYPOINT vs CMD. Switch to "npm ci" which is recommended for Docker environments.
1 parent 2432925 commit 4065f06

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

Dockerfile.dist

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,46 @@
44
# Test build:
55
# docker build -f Dockerfile.dist -t dspace/dspace-angular:latest-dist .
66

7-
FROM docker.io/node:20-alpine AS build
7+
# Step 1 - Build code for production
8+
FROM docker.io/node:22-alpine AS build
89

910
# Ensure Python and other build tools are available
1011
# These are needed to install some node modules, especially on linux/arm64
1112
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
1213

1314
WORKDIR /app
15+
# Copy over package files first, so this layer will only be rebuilt if those files change.
1416
COPY package.json package-lock.json ./
15-
RUN npm install
17+
# NOTE: "ci" = clean install from package files
18+
RUN npm ci
1619

17-
ADD . /app/
20+
# Around 4GB of memory is required to build the app for production.
21+
# This default setting can be overridden as needed in your shell, via an env file or in docker-compose.
22+
# See Docker environment var precedence: https://docs.docker.com/compose/environment-variables/envvars-precedence/
23+
ENV NODE_OPTIONS="--max_old_space_size=4096"
24+
25+
COPY . /app/
1826
RUN npm run build:prod
1927

20-
FROM node:20-alpine
28+
# Step 2 - Start up UI via PM2
29+
FROM docker.io/node:22-alpine
30+
31+
# Install PM2
2132
RUN npm install --global pm2
2233

34+
# Copy pre-built code from build image
2335
COPY --chown=node:node --from=build /app/dist /app/dist
36+
# Copy configs and PM2 startup script from local machine
2437
COPY --chown=node:node config /app/config
2538
COPY --chown=node:node docker/dspace-ui.json /app/dspace-ui.json
2639

40+
# Start up UI in PM2 in production mode
2741
WORKDIR /app
2842
USER node
2943
ENV NODE_ENV=production
3044
EXPOSE 4000
31-
CMD pm2-runtime start dspace-ui.json --json
45+
46+
# On startup, run start the DSpace UI in PM2
47+
ENTRYPOINT [ "pm2-runtime", "start", "dspace-ui.json" ]
48+
# By default, pass param that specifies to use JSON format logs.
49+
CMD ["--json"]

0 commit comments

Comments
 (0)