seekr / Dockerfile
Hemang Thakur
Deploy project on Hugging Face Spaces
4279593
raw
history blame
2.08 kB
# ----------------------------
# Stage 1: Build the React Frontend
# ----------------------------
FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy the 'frontend' folder from the project root into the container
COPY frontend ./frontend
# Switch to the frontend directory
WORKDIR /app/frontend
# Install dependencies (using yarn, npm, or pnpm)
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "No lockfile found. Exiting." && exit 1; \
fi
# Build the React app (produces a production-ready build in the "build" folder)
RUN npm run build
# ----------------------------
# Stage 2: Set Up the FastAPI Backend and Serve the React App
# ----------------------------
FROM python:3.12-slim AS backend
WORKDIR /app
# Install OS-level dependencies
RUN apt-get update --fix-missing && \
apt-get install --no-install-recommends -y git curl && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Node.js (if needed for any backend tasks)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get update --fix-missing && \
apt-get install --no-install-recommends -y nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy requirements.txt and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install additional dependencies for torch and spaCy
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
RUN python -m spacy download en_core_web_sm
# Copy the rest of your backend code and resources
COPY . .
# Copy the built React app from the builder stage into a folder named "static"
COPY --from=builder /app/frontend/build ./static
# Expose the port
EXPOSE ${PORT:-7860}
# Start the FastAPI backend using Uvicorn, reading the PORT env variable
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]