Spaces:
Sleeping
Sleeping
File size: 1,204 Bytes
2a8faae 138f333 2a8faae 138f333 2a8faae 138f333 2a8faae a79df1f 2a8faae 240e5e9 |
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 |
# ========================
# Stage 1 - Builder
# ========================
FROM python:3.11-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy only requirements first (better caching)
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# ========================
# Stage 2 - Final Runtime Image
# ========================
FROM python:3.11-slim
# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN useradd --create-home --shell /bin/bash appuser
WORKDIR /app
# Copy installed packages and application code
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY . /app
# Set permissions
RUN chown -R appuser:appuser /app
USER appuser
# Expose port
EXPOSE 7860
# Set the working directory to the backend folder
WORKDIR /app
# Command to run the FastAPI app
CMD ["sh", "-c", "uvicorn api.app:app --host 0.0.0.0 --port 7860"] |