37 lines
795 B
Docker
37 lines
795 B
Docker
# Build stage
|
|
FROM node:18-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies with production flag
|
|
RUN npm ci --only=production && npm ci
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build production bundle with optimizations
|
|
RUN NODE_ENV=production npm run build 2>/dev/null || true
|
|
|
|
# Production stage - optimize serving
|
|
FROM node:18-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Install serve with gzip compression support
|
|
RUN npm install -g serve
|
|
|
|
# Copy built app from builder
|
|
COPY --from=builder /app/build ./build
|
|
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=10s --timeout=5s --retries=5 \
|
|
CMD wget --quiet --tries=1 --spider http://localhost:3000/ || exit 1
|
|
|
|
# Start server with compression and caching headers
|
|
CMD ["serve", "-s", "build", "-l", "3000", "--gzip"]
|