Spaces:
Running
Running
File size: 1,405 Bytes
b89a86e 7d90f1f b89a86e 83a7ffb b89a86e |
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 49 50 51 52 53 54 55 56 |
# 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"]
|