# Use the official Python image as the base image FROM python:3.10-slim # Set the working directory in the container WORKDIR /app # Install system dependencies (e.g., for building wheel, working with requests, etc.) RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the application code into the container COPY . /app/ # Expose the port the app will run on EXPOSE 80 # Set the environment variable for Python to run in optimized mode ENV PYTHONUNBUFFERED 1 # Install Uvicorn and Gunicorn for serving the app with FastAPI RUN pip install uvicorn gunicorn # Start the FastAPI app using Gunicorn with the Uvicorn worker class CMD ["gunicorn", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "main:app"]