| FROM python:3.11 | |
| # Install OS-level libraries required by OpenCV (libGL, etc.) | |
| # Do this as root before switching to a non-root user | |
| RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 libsm6 libxext6 && rm -rf /var/lib/apt/lists/* | |
| # Set up a new user named "user" with user ID 1000 | |
| RUN useradd -m -u 1000 user | |
| # 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/app | |
| # Install Python requirements (installed as the non-root user into ~/.local) | |
| RUN pip install --no-cache-dir numpy pandas uvicorn fastapi python-multipart pydantic torch torchvision opencv-python matplotlib | |
| RUN pip install --no-cache-dir pyyaml --no-deps | |
| RUN pip install --no-cache-dir ultralytics | |
| RUN pip install --no-cache-dir DeepForest | |
| # Copy app code | |
| COPY --chown=user . $HOME/app | |
| # Expose port | |
| EXPOSE 8000 | |
| # Start FastAPI with uvicorn | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] |