1- # ===============================================
2- FROM registry.access.redhat.com/ubi9/nodejs-22 AS appbase
3- # ===============================================
4-
5- # install yarn
6- USER root
7- RUN curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
8- RUN yum -y install yarn
9-
1+ # ============================================================
2+ # STAGE 1: Build the Static Assets
3+ # ============================================================
4+ FROM helsinki.azurecr.io/ubi9/nodejs-24-pnpm-builder-base AS appbase
105WORKDIR /app
116
12- # Offical image has npm log verbosity as info. More info - https://github.com/nodejs/docker-node#verbosity
13- ENV NPM_CONFIG_LOGLEVEL warn
14-
15- # set our node environment, either development or production
16- # defaults to production, compose overrides this to development on build and run
17- ARG NODE_ENV=${NODE_ENV:-"production" }
18- ENV NODE_ENV $NODE_ENV
7+ # 1. Copy needed files for build
8+ COPY --chown=default:root package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json tsconfig.node.json ./
9+ COPY --chown=default:root ./public ./public
10+ COPY --chown=default:root ./scripts ./scripts
1911
20- # Global npm deps in a non-root user directory
21- ENV NPM_CONFIG_PREFIX=/app/.npm-global
22- ENV PATH=$PATH:/app/.npm-global/bin
12+ # 2. Run the install
13+ # corepack in the base image will automatically use the version of pnpm
14+ # defined in your package.json 'packageManager' field if present.
15+ RUN pnpm install --frozen-lockfile --ignore-scripts && pnpm store prune
16+ RUN pnpm update-runtime-env
2317
24- # Yarn
25- ENV YARN_VERSION 1.22.22
26- RUN yarn policies set-version ${YARN_VERSION}
18+ # 3. Copy remaining source files
19+ COPY --chown=default:root index.html vite.config.ts eslint.config.mjs .prettierrc.json .env* ./
20+ COPY --chown=default:root ./src ./src
2721
28- # Copy package.json and package-lock.json/yarn.lock files
29- COPY --chown=default:root package*.json *yarn* ./
3022
31- # Install npm dependencies
32- ENV PATH /app/node_modules/.bin:$PATH
33-
34- RUN yarn install --frozen-lockfile --ignore-scripts && yarn cache clean --force
35-
36- # =============================
23+ # ============================================================
24+ # STAGE 2: Development
25+ # ============================================================
3726FROM appbase AS development
38- # =============================
27+ WORKDIR /app
3928
4029# Set NODE_ENV to development in the development container
4130ARG NODE_ENV=development
@@ -48,99 +37,40 @@ ENV NODE_ENV $NODE_ENV
4837ARG CHOKIDAR_USEPOLLING=true
4938ENV CHOKIDAR_USEPOLLING=${CHOKIDAR_USEPOLLING}
5039
51- # copy in our source code last, as it changes the most
52- COPY --chown=default:root . .
40+ # Expose port and start development server
41+ EXPOSE 8080
42+ CMD pnpm exec vite --port 8080 --no-open --host
5343
54- # Bake package.json start command into the image
55- CMD ["yarn" , "dev" , "--no-open" , "--host" ]
5644
57- # ===================================
45+ # ============================================================
46+ # STAGE 3: Static builder for production
47+ # ============================================================
5848FROM appbase AS staticbuilder
59- # ===================================
60-
61- # Oidc authority
62- ARG VITE_APP_OIDC_AUDIENCES
63- ARG VITE_APP_OIDC_RETURN_TYPE
64- ARG VITE_APP_OIDC_SERVER_TYPE
65- ARG VITE_APP_OIDC_API_CLIENT_ID
66- ARG VITE_APP_OIDC_AUTHORITY
67- ARG VITE_APP_OIDC_CLIENT_ID
68- ARG VITE_APP_OIDC_SCOPE
69- ARG VITE_APP_OIDC_AUTOMATIC_SILENT_RENEW_ENABLED
70-
71- # Sentry variables
72- ARG VITE_APP_SENTRY_ENVIRONMENT
73- ARG VITE_APP_SENTRY_DSN
74- ARG VITE_APP_SENTRY_TRACES_SAMPLE_RATE
75- ARG VITE_APP_SENTRY_TRACE_PROPAGATION_TARGETS
76- ARG VITE_APP_SENTRY_REPLAYS_SESSION_SAMPLE_RATE
77- ARG VITE_APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE
78- ARG VITE_APP_CSP_REPORT_URI
79-
80- # Api url
81- ARG VITE_APP_API_URI
82- ARG VITE_APP_CMS_URI
83- ARG VITE_APP_API_REPORT_URI
84-
85- # Linkedevents api url
86- ARG VITE_APP_LINKEDEVENTS_API_URI
87-
88- # Application's origin (i.e. where this application is hosted)
89- ARG VITE_APP_ORIGIN
9049
91- # Helsinki profile URL
92- ARG VITE_APP_HELSINKI_PROFILE_URL
93-
94- # Time before user logout if idle
95- ARG VITE_APP_IDLE_TIMEOUT_IN_MS
50+ # Perform the build
51+ ARG VITE_APP_SENTRY_RELEASE
52+ ARG VITE_APP_CSP_REPORT_URI
53+ ENV VITE_APP_CSP_REPORT_URI=${VITE_APP_CSP_REPORT_URI:- "" }
54+ RUN pnpm build
9655
97- ARG NODE_OPTIONS
9856
99- # Fix FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed -
100- # JavaScript heap out of memory: https://github.com/vitejs/vite/issues/2433.
101- ENV NODE_OPTIONS=${NODE_OPTIONS}
57+ # ============================================================
58+ # STAGE 4: Production Runtime
59+ # ============================================================
60+ FROM helsinki.azurecr.io/ubi10/nginx-126-spa-standard AS production
10261
103- # Release information
10462ARG VITE_APP_SENTRY_RELEASE
105- ARG VITE_APP_COMMITHASH
106- ARG VITE_APP_BUILDTIME
107-
108- # Use template and inject the environment variables into .prod/nginx.conf
109- ENV VITE_APP_BUILDTIME=${VITE_APP_BUILDTIME:-"" }
110- ENV VITE_APP_RELEASE=${VITE_APP_SENTRY_RELEASE:-"" }
111- ENV VITE_APP_COMMITHASH=${VITE_APP_COMMITHASH:-"" }
112- COPY .prod/nginx.conf.template /tmp/.prod/nginx.conf.template
113- RUN export APP_VERSION=$(yarn --silent app:version) && \
114- envsubst '${APP_VERSION},${VITE_APP_BUILDTIME},${VITE_APP_RELEASE},${VITE_APP_COMMITHASH}' < \
115- "/tmp/.prod/nginx.conf.template" > \
116- "/tmp/.prod/nginx.conf"
117-
118- # Copy all files
119- COPY . /app
120-
121- # Build
122- RUN yarn build
123-
124- # =============================
125- FROM registry.access.redhat.com/ubi9/nginx-122 AS production
126- # =============================
127- # Add application sources to a directory that the assemble script expects them
128- # and set permissions so that the container runs without root access
129- ARG PORT
130-
131- USER root
132-
133- RUN chgrp -R 0 /usr/share/nginx/html && \
134- chmod -R g=u /usr/share/nginx/html
135-
136- # Copy static build
63+ ENV APP_RELEASE=${VITE_APP_SENTRY_RELEASE:-"" }
64+ # 1. Copy the compiled assetsE_APP
13765COPY --from=staticbuilder /app/build /usr/share/nginx/html
138- # Copy nginx config
139- COPY --from=staticbuilder /tmp/.prod/nginx.conf /etc/nginx/nginx.conf
14066
141- USER 1001
67+ # 2. Runtime env is pre-generated during build as env-config.js
68+ WORKDIR /usr/share/nginx/html
14269
143- # Run script uses standard ways to run the application
144- CMD [ "/bin/bash" , "-c" , "nginx -g \" daemon off; \" " ]
70+ # 3. Inject Versioning for the /readiness endpoint from package.json using base image
71+ COPY package.json .
14572
146- EXPOSE ${PORT:-8080}
73+ # - env.sh (Inherited from base image at /usr/share/nginx/html/env.sh)
74+ # - USER 1001 (Inherited from base image)
75+ # - EXPOSE 8080 (Inherited from base image)
76+ # - ENTRYPOINT/CMD (Inherited from base image)
0 commit comments