FROM python:3.12-slim # Set up a new user with user ID 1000 RUN useradd -m -u 1000 user # Switch to root user temporarily for installing system dependencies USER root # Set environment variables for the user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR /home/user/app # Upgrade pip RUN pip install --no-cache-dir --upgrade pip==23.3.1 # Install necessary build tools (if required for your dependencies) RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential && \ rm -rf /var/lib/apt/lists/* # Switch back to the "user" user USER user # Copy the application code into the container at $HOME/app and set the ownership to the "user" COPY --chown=user product_return_prediction $HOME/app/product_return_prediction COPY --chown=user README.md $HOME/app/ COPY --chown=user requirements.txt $HOME/app/ COPY --chown=user pyproject.toml $HOME/app/ # Copy the external data and models, ensuring proper permissions COPY --chown=user models/scaler.pkl $HOME/app/models/ COPY --chown=user models/svm.pkl $HOME/app/models/ # Install Python dependencies RUN pip install --no-cache-dir -r $HOME/app/requirements.txt # Expose port 7860 for the app EXPOSE 7860 # Set the command to run the FastAPI app with Uvicorn CMD ["uvicorn", "product_return_prediction.api:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]