# Start from the TGI base image FROM ghcr.io/huggingface/text-generation-inference:2.0 as base # Install git RUN apt-get update && apt-get install -y git COPY ./requirements.txt /code/requirements.txt RUN pip install -r /code/requirements.txt # Create a non-root user with UID 1000 RUN useradd -m -u 1000 -s /bin/bash user # Create the /data directory and set its ownership RUN mkdir /data && chown user:user /data # Switch to the non-root user USER user # Set working directory WORKDIR /home/user # Add local python bin directory to PATH ENV PATH="/home/user/.local/bin:${PATH}" # Override the ENTRYPOINT ENTRYPOINT [] # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=$HOME/app \ PYTHONUNBUFFERED=1 \ GRADIO_ALLOW_FLAGGING=never \ GRADIO_NUM_PORTS=1 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_THEME=huggingface \ SYSTEM=spaces # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/ # Set the CMD to run your script CMD python /home/user/app.py