-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (52 loc) · 2.43 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (52 loc) · 2.43 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
# Use the official Node.js runtime as the base image
# SC-MOD-008 (internal security audit): standardized on node:22-alpine
# to match Dockerfile.coordinator + Dockerfile.gateway.
#
# SC-MOD-005 (internal security audit, B-step): the previous single-
# stage build installed ALL dependencies (including devDeps like eslint,
# jest, c8, nodemon) and shipped them in the production image, inflating
# the attack surface and trivy findings. The new multi-stage build uses
# a `build` stage to compile (needs devDeps for the UI build + tests),
# then a slim `runtime` stage that re-installs ONLY production dependencies.
FROM node:22-alpine AS build
# Set the working directory in the container
WORKDIR /app
# Create non-root user. Same pattern as Dockerfile.coordinator and
# Dockerfile.gateway — runs the node process as 'aware' (UID 10001).
RUN addgroup -S aware && adduser -S aware -G aware
# Copy package manifests first to leverage Docker layer caching.
COPY package*.json ./
# Build stage: install ALL deps (including devDeps needed for the
# UI build + any pre-compilation tooling).
RUN npm install
# Copy the rest of the application code to the working directory
COPY . .
# Ensure scripts directory exists (some hosts .dockerignore it).
RUN mkdir -p scripts
# Build the UI for production (uses react-scripts which is a devDep).
WORKDIR /app/src/ui
RUN npm install && npm run build
WORKDIR /app
# ---------- runtime stage (no devDeps) ------------------------------
FROM node:22-alpine AS runtime
# Re-create the non-root user in the runtime image (multi-stage build
# copies nothing from `build` except the explicit COPY below).
RUN addgroup -S aware && adduser -S aware -G aware
WORKDIR /app
# Copy only the package manifests + the compiled artifacts from build.
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/package-lock.json ./package-lock.json
COPY --from=build /app/src ./src
COPY --from=build /app/scripts ./scripts
# SC-MOD-005: install ONLY production dependencies — drops devDeps
# (eslint, jest, c8, nodemon, react-scripts, etc.) from the runtime image.
ENV NODE_ENV=production
RUN npm install --omit=dev --no-audit --no-fund && npm cache clean --force
# Set ownership of the app directory to the non-root user.
RUN chown -R aware:aware /app
# Switch to non-root user for runtime (fixes trivy DS-0002).
USER aware
# Expose the port the app runs on
EXPOSE 3000
# Define the command to run the application
CMD ["npm", "start"]