File size: 1,156 Bytes
c2efbe6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # Multi-stage Dockerfile for MKCart Fullstack App
# Optimized for Hugging Face Spaces
# Stage 1: Build Frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy package files first for better caching
COPY frontend/package*.json ./
RUN npm install
# Copy source and build
COPY frontend/ ./
# Set REACT_APP_API_URL to empty to use relative paths (serving from same origin)
ENV REACT_APP_API_URL=""
RUN npm run build
# Stage 2: Final Runner
FROM node:20-alpine
WORKDIR /app
# Install backend dependencies
COPY backend/package*.json ./backend/
WORKDIR /app/backend
RUN npm install --production
# Copy backend source
COPY backend/ ./
# Copy built frontend from Stage 1
# Backend expects it at ../frontend/build
COPY --from=frontend-builder /app/frontend/build /app/frontend/build
# Environment configuration
ENV NODE_ENV=production
ENV PORT=7860
# HF Spaces expects the app to be reachable on port 7860
EXPOSE 7860
# Health check (optional but good for HF)
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --quiet --tries=1 --spider http://localhost:7860/api/products || exit 1
# Start the application
CMD ["node", "app.js"]
|