From c762d5a0a6ae0f708017bde6f76e7c8016d147a7 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sat, 21 Feb 2026 19:49:06 +0000 Subject: [PATCH] Optimize frontend Dockerfile: npm cache mount, non-root nginx, healthcheck --- frontend/Dockerfile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 74fddc8..d3f1179 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -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;"]