# Stage 1: Build Frontend FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm ci COPY frontend/ ./ RUN npm run build # Stage 2: Production Server FROM node:20-alpine WORKDIR /app # Install production dependencies COPY backend/package*.json ./ RUN npm ci --only=production && \ npm cache clean --force # Copy backend source COPY backend/ ./ # Copy built frontend COPY --from=frontend-builder /app/frontend/dist ./public # Create temp upload directory RUN mkdir -p /app/temp && \ chown -R node:node /app # Switch to non-root user USER node # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" # Start server CMD ["node", "src/server.js"]