HindiBPE / Dockerfile
Vibi007's picture
reduce docker image size
1fad674
# Stage 1: Build React frontend
FROM node:14-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy frontend code and install dependencies
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Stage 2: Build FastAPI backend
FROM python:3.8-alpine AS backend-builder
WORKDIR /app/backend
# Install system dependencies (use lightweight alternatives)
RUN apk update && apk add --no-cache gcc libpq-dev
# Copy backend code and install Python dependencies
COPY backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY backend/ ./
# Stage 3: Final stage
FROM python:3.8-alpine
WORKDIR /app
# Step 1: Install nodejs, npm, and supervisor
RUN apk update
RUN apk add --no-cache nodejs npm supervisor
# Step 2: Install Python dependencies
RUN pip install --no-cache-dir uvicorn fastapi tqdm wikitextparser pydantic requests beautifulsoup4
# Step 3: Install serve globally for serving React app
RUN npm install -g serve
# No need for apk clean, it's not required
# Copy supervisord configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Copy built frontend from the first stage
COPY --from=frontend-builder /app/frontend/build /app/frontend/build
# Copy backend from the second stage
COPY --from=backend-builder /app/backend /app/backend
# Expose ports
EXPOSE 7860
EXPOSE 8000
# Start supervisord to manage both React frontend and FastAPI backend
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]