-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (65 loc) · 3.38 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (65 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# ============================================================
# STAGE 1: Install dependencies
# ============================================================
FROM helsinki.azurecr.io/ubi9/nodejs-24-pnpm-builder-base AS appbase
COPY --chown=default:root package.json pnpm-lock.yaml pnpm-workspace.yaml index.html vite.config.js .eslintrc.json .env ./
COPY --chown=default:root ./scripts ./scripts
COPY --chown=default:root ./config ./config
COPY --chown=default:root ./server ./server
COPY --chown=default:root server.mjs ./
COPY --chown=default:root ./public ./public
COPY --chown=default:root ./src ./src
# 2. Run install
# corepack in the base image will automatically use the version of pnpm
# defined in your package.json 'packageManager' field if present.
RUN pnpm install --frozen-lockfile --ignore-scripts && pnpm store prune
COPY --chown=default:root ./.git ./.git
# ============================================================
# STAGE 2: Development
# ============================================================
FROM appbase AS development
# Set NODE_ENV to development in the development container
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV
CMD ["pnpm", "dev"]
# ============================================================
# STAGE 3: Build
# ============================================================
FROM appbase AS staticbuilder
ARG NODE_OPTIONS=--max-old-space-size=4096
ENV NODE_OPTIONS=$NODE_OPTIONS
ENV NODE_ENV=production
RUN pnpm build
# ============================================================
# STAGE 4: Production Runtime
# ============================================================
# This app is SSR (Express + React server-side rendering) — it requires a
# Node runtime, not a static file server like nginx.
FROM registry.access.redhat.com/ubi9/nodejs-24-minimal AS production
WORKDIR /servicemap-ui
# Copy built assets and the unified server entry point
COPY --from=staticbuilder --chown=1001:root /app/dist ./dist
COPY --from=staticbuilder --chown=1001:root /app/server.mjs ./server.mjs
COPY --from=staticbuilder --chown=1001:root /app/server ./server
COPY --from=staticbuilder --chown=1001:root /app/config ./config
COPY --from=staticbuilder --chown=1001:root /app/package.json ./package.json
# Copy .env so update-runtime-env.js can use it as a fallback at container startup
# for any variable not present in the Azure ConfigMap. process.env (ConfigMap) wins.
COPY --from=appbase --chown=1001:root /app/.env ./.env
# Copy scripts needed at container startup (update-runtime-env.js)
COPY --from=appbase --chown=1001:root /app/scripts ./scripts
# Copy node_modules from staticbuilder so the hds-core cookie-consent shim
# (applied during pnpm build via fix-hds-shim) is present at runtime.
COPY --from=staticbuilder --chown=1001:root /app/node_modules ./node_modules
# OpenShift runs containers with a random UID in group 0 (root group).
# Make dist/ group-writable so update-runtime-env.js can overwrite env-config.js
# regardless of the actual runtime UID.
RUN chmod -R g+w /servicemap-ui/dist
ENV NODE_ENV=production
USER 1001
EXPOSE 8080
# Re-run the env script at startup so Azure configmap variables overwrite the
# baked-in build-time defaults in dist/env-config.js before the server starts.
# The existing dist/env-config.js serves as the fallback for any variable that
# is not present in the runtime environment.
CMD ["sh", "-c", "node scripts/update-runtime-env.js && exec node server.mjs"]