Skip to content

Commit aee895a

Browse files
authored
refactor(api): replace RedHat UBI with Debian-Slim (#946) (#1063)
1 parent e54576f commit aee895a

1 file changed

Lines changed: 23 additions & 33 deletions

File tree

api/Dockerfile

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,53 @@
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
33

4-
# Install packages, build and keep only prod packages
4+
# Install dependencies and build API
55
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
96

107
# Root lockfile + only the manifests this image builds (api + libs). `npm ci`
118
# 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.
1410
COPY package.json package-lock.json ./
1511
COPY libs/package.json ./libs/
1612
COPY api/package.json ./api/
13+
1714
# Hoisted install incl. devDeps (@nestjs/cli + typescript) needed to build.
1815
RUN npm ci --ignore-scripts
1916

2017
# Source for the shared lib and the api
2118
COPY libs ./libs
2219
COPY api ./api
23-
WORKDIR /app/api
2420
RUN npm run build:api
2521

2622
# Reinstall prod-only, api-scoped deps so the runtime node_modules (hoisted to
2723
# /app/node_modules) is lean and matches the pre-workspace api-only footprint.
28-
WORKDIR /app
2924
RUN npm ci --ignore-scripts --workspace=api --omit=dev
3025

3126

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
4729

4830
# Copy over app (node_modules is hoisted to the workspace root under npm workspaces)
4931
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/*
5440

55-
# Expose port - mostly a convention, for readability
41+
# Expose port and configure health check
5642
ARG port=3333
57-
EXPOSE ${port}
43+
ENV APP_PORT=${port}
44+
EXPOSE ${APP_PORT}
5845

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
6047

61-
# Start up command
48+
# Non-root secure execution
6249
USER 1001
50+
6351
ENTRYPOINT ["node", "--max-old-space-size=2048", "./dist/api/src/main.js"]
52+
53+

0 commit comments

Comments
 (0)