wrongmove/frontend/Dockerfile

59 lines
1.5 KiB
Text
Raw Normal View History

# syntax=docker/dockerfile:1
# Stage 1: Install dependencies (cached if package-lock.json unchanged)
FROM node:24-alpine AS deps
2025-06-16 22:43:46 +00:00
WORKDIR /app
# Limit Node.js heap to avoid OOM in constrained CI environments
ENV NODE_OPTIONS="--max-old-space-size=1024"
# Copy package files first for better layer caching
2025-06-16 22:43:46 +00:00
COPY package.json package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm \
npm ci
2025-06-16 22:43:46 +00:00
# Stage 2: Run tests (fails the build if tests fail)
FROM deps AS test
COPY . .
RUN npx vitest run
# Stage 3: Build production bundle
FROM deps AS builder
2025-06-16 22:43:46 +00:00
COPY . .
# Skip tsc type-checking (vitest already validated); Vite transpiles via SWC
RUN npx vite build
2025-06-16 22:43:46 +00:00
# Stage 4: Serve with nginx
2025-06-16 22:43:46 +00:00
FROM nginx:alpine
# Remove default nginx static files
RUN rm -rf /usr/share/nginx/html/*
WORKDIR /app
COPY --from=builder /app/dist /usr/share/nginx/html
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
2025-06-16 22:43:46 +00:00
2026-02-21 19:51:17 +00:00
# Configure nginx to run as non-root
RUN chown -R nginx:nginx /usr/share/nginx/html && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
touch /run/nginx.pid && chown nginx:nginx /run/nginx.pid && \
sed -i 's/listen 80;/listen 8080;/' /etc/nginx/conf.d/default.conf && \
sed -i 's/^user /#user /' /etc/nginx/nginx.conf
USER nginx
2026-02-21 19:51:17 +00:00
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
2026-02-21 19:51:17 +00:00
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
2025-06-16 22:43:46 +00:00
CMD ["nginx", "-g", "daemon off;"]