semgrep HIGH: no USER directive before ENTRYPOINT (container ran as root). Runtime dirs, conf.d and html dir chowned to nginx so the entrypoint (env.js write + PORT envsubst) and nginx master both run as uid 101. Verified: docker build + run, HTTP 200, SPA fallback, env override OK, ps shows master+workers as nginx. CONSTRAINT: PORT env var must now be >=1024 (default 8080 unaffected).
41 lines
1.1 KiB
Docker
41 lines
1.1 KiB
Docker
# ---- stage 1: builder -----------------------------------------------
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install pnpm via corepack
|
|
RUN corepack enable && corepack prepare pnpm@10.13.1 --activate
|
|
|
|
# Copy manifests first for layer caching
|
|
COPY package.json pnpm-lock.yaml* ./
|
|
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# Copy source and build
|
|
COPY . .
|
|
RUN pnpm build
|
|
|
|
# ---- stage 2: runner ------------------------------------------------
|
|
FROM nginx:alpine AS runner
|
|
|
|
# Copy built static assets
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
|
|
# Copy custom nginx config and entrypoint
|
|
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
|
|
COPY docker/entrypoint.sh /entrypoint.sh
|
|
|
|
# Run fully as non-root (port 8080 is unprivileged). nginx needs to own:
|
|
# its runtime dirs, the config it rewrites at startup (PORT envsubst),
|
|
# and the html dir (entrypoint writes env.js there).
|
|
RUN chmod +x /entrypoint.sh \
|
|
&& touch /var/run/nginx.pid \
|
|
&& chown -R nginx:nginx /var/cache/nginx /var/run/nginx.pid \
|
|
/etc/nginx/conf.d /usr/share/nginx/html
|
|
|
|
USER nginx
|
|
|
|
EXPOSE 8080
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|