Optimize frontend Dockerfile: npm cache mount, non-root nginx, healthcheck
This commit is contained in:
parent
795e1f7b57
commit
c762d5a0a6
1 changed files with 12 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
|
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
|
||||||
FROM node:24-alpine AS deps
|
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 files first for better layer caching
|
||||||
COPY package.json package-lock.json* ./
|
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)
|
# Stage 2: Run tests (fails the build if tests fail)
|
||||||
FROM deps AS test
|
FROM deps AS test
|
||||||
|
|
@ -37,5 +40,13 @@ WORKDIR /app
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
|
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
|
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;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue