|
1 | | -# RedHat UBI 8 with nodejs 24 |
2 | | -FROM registry.access.redhat.com/ubi8/nodejs-24:1-1782882986 AS builder |
| 1 | +# Build container |
| 2 | +FROM node:24.19.0-bookworm-slim AS build |
3 | 3 |
|
4 | | -# Install packages, build and keep only prod packages |
| 4 | +# Install dependencies and build API |
5 | 5 | WORKDIR /app |
6 | | -USER root |
7 | | -RUN dnf install -y ca-certificates && dnf clean all && rm -rf /var/cache/dnf |
8 | | -RUN npm install -g npm@10.9.4 --ignore-scripts |
9 | 6 |
|
10 | 7 | # Root lockfile + only the manifests this image builds (api + libs). `npm ci` |
11 | 8 | # reads the full root lockfile but skips workspaces whose directory is absent, |
12 | | -# so it installs just api's + libs' deps. (npm is pinned to 10.9.4 above, which |
13 | | -# makes this skip-missing-workspaces behaviour deterministic.) |
| 9 | +# so it installs just api's + libs' deps. |
14 | 10 | COPY package.json package-lock.json ./ |
15 | 11 | COPY libs/package.json ./libs/ |
16 | 12 | COPY api/package.json ./api/ |
| 13 | + |
17 | 14 | # Hoisted install incl. devDeps (@nestjs/cli + typescript) needed to build. |
18 | 15 | RUN npm ci --ignore-scripts |
19 | 16 |
|
20 | 17 | # Source for the shared lib and the api |
21 | 18 | COPY libs ./libs |
22 | 19 | COPY api ./api |
23 | | -WORKDIR /app/api |
24 | 20 | RUN npm run build:api |
25 | 21 |
|
26 | 22 | # Reinstall prod-only, api-scoped deps so the runtime node_modules (hoisted to |
27 | 23 | # /app/node_modules) is lean and matches the pre-workspace api-only footprint. |
28 | | -WORKDIR /app |
29 | 24 | RUN npm ci --ignore-scripts --workspace=api --omit=dev |
30 | 25 |
|
31 | 26 |
|
32 | | -# Deployment container |
33 | | -FROM registry.access.redhat.com/ubi8/ubi:8.10-1781720109 |
34 | | - |
35 | | -# Node packages and dependencies |
36 | | -COPY --from=builder /usr/bin/node /usr/bin/ |
37 | | -COPY --from=builder /usr/lib64/libnode.so* /usr/lib64/ |
38 | | -COPY --from=builder /usr/lib64/libz.so.1 /usr/lib64/ |
39 | | -COPY --from=builder /usr/lib64/libbrotlidec.so.1 /usr/lib64/ |
40 | | -COPY --from=builder /usr/lib64/libbrotlienc.so.1 /usr/lib64/ |
41 | | -COPY --from=builder /usr/lib64/libcrypto.so.1.1 /usr/lib64/ |
42 | | -COPY --from=builder /usr/lib64/libssl.so* /usr/lib64/ |
43 | | -COPY --from=builder /usr/lib64/libstdc++.so.6 /usr/lib64/ |
44 | | -COPY --from=builder /usr/lib64/libgcc_s.so.1 /usr/lib64/ |
45 | | -COPY --from=builder /usr/lib64/libbrotlicommon.so.1 /usr/lib64/ |
46 | | -COPY --from=builder /etc/pki /etc/pki |
| 27 | +# Deploy container |
| 28 | +FROM node:24.19.0-bookworm-slim |
47 | 29 |
|
48 | 30 | # Copy over app (node_modules is hoisted to the workspace root under npm workspaces) |
49 | 31 | WORKDIR /app |
50 | | -COPY --from=builder /app/node_modules ./node_modules |
51 | | -COPY --from=builder /app/api/dist ./dist |
52 | | -COPY --from=builder /app/api/src/migrations/main ./dist/api/src/migrations/main |
53 | | -COPY --from=builder /app/api/src/migrations/test ./dist/api/src/migrations/test |
| 32 | +COPY --from=build /app/node_modules ./node_modules |
| 33 | +COPY --from=build /app/api/dist ./dist |
| 34 | +COPY --from=build /app/api/src/migrations/main ./dist/api/src/migrations/main |
| 35 | +COPY --from=build /app/api/src/migrations/test ./dist/api/src/migrations/test |
| 36 | + |
| 37 | +# Add curl to debian-slim for the health check |
| 38 | +RUN apt-get update && apt-get install -y --no-install-recommends curl && \ |
| 39 | + rm -rf /var/lib/apt/lists/* |
54 | 40 |
|
55 | | -# Expose port - mostly a convention, for readability |
| 41 | +# Expose port and configure health check |
56 | 42 | ARG port=3333 |
57 | | -EXPOSE ${port} |
| 43 | +ENV APP_PORT=${port} |
| 44 | +EXPOSE ${APP_PORT} |
58 | 45 |
|
59 | | -HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:${port} || exit 1 |
| 46 | +HEALTHCHECK --interval=30s --timeout=3s CMD curl -f "http://localhost:${APP_PORT}/health-check" || exit 1 |
60 | 47 |
|
61 | | -# Start up command |
| 48 | +# Non-root secure execution |
62 | 49 | USER 1001 |
| 50 | + |
63 | 51 | ENTRYPOINT ["node", "--max-old-space-size=2048", "./dist/api/src/main.js"] |
| 52 | + |
| 53 | + |
0 commit comments