Spaces:
Runtime error
Runtime error
File size: 1,457 Bytes
456b2dd | 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 | # Stage 1: Build stage - Install dependencies
# Using a specific version is good practice for reproducibility.
FROM python:3.11-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory
WORKDIR /app
# Install poetry for dependency management (a robust alternative to pip)
# If you stick with requirements.txt, you can replace this with pip install.
COPY requirements.txt .
# Install dependencies without caching to keep the layer small
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Stage 2: Final stage - Create the production image
FROM python:3.11-slim
# Set the working directory
WORKDIR /app
# Copy the installed dependencies from the builder stage
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 the application source code
COPY . .
# Expose the port that the application will run on
# As per your README, the FastAPI app runs on port 8000.
EXPOSE 8000
# Command to run the application
# We use Gunicorn as a process manager and Uvicorn for the ASGI server,
# which is the recommended setup for running FastAPI in production.
# The number of workers (-w) can be adjusted based on your server's CPU cores.
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-w", "4", "--bind", "0.0.0.0:8000", "app:app"] |