# syntax=docker/dockerfile:1.7 ARG NODE_VERSION=20.15.0 FROM node:${NODE_VERSION}-alpine AS build WORKDIR /app # Install all deps for build COPY package*.json ./ RUN npm install && npm cache clean --force # Build frontend COPY . . ENV NODE_ENV=production ENV NODE_OPTIONS=--max-old-space-size=512 RUN npm run build # ---- Runtime (Node.js server with static files) ---- FROM node:${NODE_VERSION}-alpine AS runtime WORKDIR /app # Install curl for healthcheck RUN apk add --no-cache curl # Copy package.json and production dependencies COPY package*.json ./ RUN npm install --omit=dev && npm cache clean --force # Copy server files and built frontend COPY server ./server COPY --from=build /app/dist ./dist # Create data directory for volume mount RUN mkdir -p /app/data && chown -R node:node /app/data # Set data directory environment variable ENV DATA_DIR=/app/data ENV NODE_ENV=production ENV PORT=80 # Switch to non-root user USER node EXPOSE 80 HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ CMD curl -fsS http://localhost/api/health >/dev/null || exit 1 CMD ["npm", "start"]