Optimize frontend Dockerfile: npm cache mount, non-root nginx, healthcheck

This commit is contained in:
Viktor Barzin 2026-02-21 19:49:06 +00:00
parent 795e1f7b57
commit c762d5a0a6
No known key found for this signature in database
GPG key ID: 0EB088298288D958

View file

@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
FROM node:24-alpine AS deps
@ -9,7 +11,8 @@ ENV NODE_OPTIONS="--max-old-space-size=1024"
# Copy package files first for better layer caching
COPY package.json package-lock.json* ./
RUN npm ci
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Stage 2: Run tests (fails the build if tests fail)
FROM deps AS test
@ -37,5 +40,13 @@ WORKDIR /app
COPY --from=builder /app/dist /usr/share/nginx/html
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
RUN chown -R nginx:nginx /usr/share/nginx/html
USER nginx
EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
CMD ["nginx", "-g", "daemon off;"]