ecom / Dockerfile
shashwatIDR's picture
Update Dockerfile
83a7ffb verified
# Multi-stage Dockerfile for Hugging Face Spaces
# - Builds the client with Vite
# - Bundles the server with esbuild (via npm run build)
# - Serves on PORT (default 7860) from dist/index.js
############################
# Builder stage
############################
FROM node:20-bookworm-slim AS builder
WORKDIR /app
# Install system deps needed for native builds (e.g., bcrypt)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Copy dependency manifests first for better caching
COPY package.json package-lock.json ./
# Install all deps (including devDeps to build)
RUN npm ci
# Copy the rest of the project
COPY . .
# Build client and server to dist/
RUN npm run build
############################
# Runtime stage
############################
FROM node:20-bookworm-slim AS runner
ENV NODE_ENV=production
ENV PORT=7860
WORKDIR /app
# Copy only the runtime artifacts
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/uploads ./uploads
# Ensure uploads directory exists and is writable
RUN mkdir -p /app/uploads && chmod -R 777 /app/uploads
# Expose the Space port (Hugging Face sets PORT env var)
EXPOSE 7860
# Start the server (listens on 0.0.0.0:${PORT})
CMD ["npm", "run", "start"]