# Use the official Python 3.10.9 image FROM python:3.10.9 # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Install wkhtmltopdf and its dependencies as root USER root RUN apt-get update && apt-get install -y --no-install-recommends \ wkhtmltopdf \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR $HOME/code # Expose the port FastAPI will run on EXPOSE 7860 # Set environment variables for FastAPI and OpenAI API keys ARG FASTAPI_KEY ARG OPENAI_API_KEY ARG OPENAI_GENERAL_ASSISTANT ARG SENTRY_DSN ENV FASTAPI_KEY=$FASTAPI_KEY ENV OPENAI_API_KEY=$OPENAI_API_KEY ENV OPENAI_GENERAL_ASSISTANT=$OPENAI_GENERAL_ASSISTANT ENV PYTHONUNBUFFERED=1 ENV SENTRY_DSN=$SENTRY_DSN # Set the working directory # WORKDIR /code # Copy requirements and install dependencies COPY ./app/requirements.txt $HOME/code/requirements.txt RUN pip install --no-cache-dir --upgrade -r $HOME/code/requirements.txt # Copy the app directory COPY ./app $HOME/code/app # Start the FastAPI app on port 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "900"]