FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu20.04 COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ ENV DEBIAN_FRONTEND=noninteractive \ TZ=Europe/Paris # Remove any third-party apt sources to avoid issues with expiring keys. # Install some basic utilities RUN rm -f /etc/apt/sources.list.d/*.list && \ apt-get update && apt-get install -y --no-install-recommends \ curl \ ca-certificates \ sudo \ git \ wget \ procps \ git-lfs \ zip \ unzip \ htop \ vim \ nano \ bzip2 \ libx11-6 \ build-essential \ libsndfile-dev \ software-properties-common \ python3-distutils \ && rm -rf /var/lib/apt/lists/* RUN add-apt-repository ppa:flexiondotorg/nvtop && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends nvtop # Create a working directory WORKDIR /app # Create a non-root user and switch to it RUN adduser --disabled-password --gecos '' --shell /bin/bash user \ && chown -R user:user /app RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user USER user # All users can use /home/user as their home directory ENV HOME=/home/user RUN mkdir $HOME/.cache $HOME/.config \ && chmod -R 777 $HOME WORKDIR $HOME/app ####################################### # Start root user section ####################################### USER root # User Debian packages ## Security warning : Potential user code executed as root (build time) RUN --mount=target=/root/packages.txt,source=packages.txt \ apt-get update && \ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* RUN curl -fsSL https://ollama.com/install.sh | sh RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \ bash /root/on_startup.sh RUN mkdir /data && chown user:user /data ####################################### # End root user section ####################################### USER user RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --locked --no-install-project RUN uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=uv_project # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/app RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --locked ENV PYTHONUNBUFFERED=1 \ SYSTEM=spaces \ SHELL=/bin/bash RUN chmod +x start_server.sh EXPOSE 7860 CMD ["./start_server.sh"]