FROM nvidia/cuda:12.1.0-devel-ubuntu22.04 AS dev

RUN apt-get update -y \
    && apt-get install -y python3-pip git

WORKDIR /workspace

# install build and runtime dependencies
COPY requirements.txt requirements.txt
COPY aiproxy aiproxy

RUN --mount=type=cache,target=/root/.cache/pip \
    pip install -r requirements.txt

# Create a non-root user
RUN useradd -m appuser

# Transfer ownership of the /workspace to the new non-root user
RUN chown -R appuser:appuser /workspace

# Create a cache directory within the appuser's home directory and transfer ownership
RUN mkdir -p /home/appuser/cache && \
    chown -R appuser:appuser /home/appuser/cache

# Switch to the non-root user for subsequent commands and container runtime
USER appuser

CMD ["python3", "-m", \
    "aiproxy", \
    "--host", "0.0.0.0", \
    "--port", "7860"]