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
1112RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
1213
1314WORKDIR /app
15+ # Copy over package files first, so this layer will only be rebuilt if those files change.
1416COPY 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/
1826RUN 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
2132RUN npm install --global pm2
2233
34+ # Copy pre-built code from build image
2335COPY --chown=node:node --from=build /app/dist /app/dist
36+ # Copy configs and PM2 startup script from local machine
2437COPY --chown=node:node config /app/config
2538COPY --chown=node:node docker/dspace-ui.json /app/dspace-ui.json
2639
40+ # Start up UI in PM2 in production mode
2741WORKDIR /app
2842USER node
2943ENV NODE_ENV=production
3044EXPOSE 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