FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04 ARG TIMEZONE=America/Vancouver # Set environment variables ENV DEBIAN_FRONTEND=noninteractive \ TZ=${TIMEZONE} \ CONDA_AUTO_UPDATE_CONDA=false \ PYTHONUNBUFFERED=1 \ GRADIO_ALLOW_FLAGGING=never \ GRADIO_NUM_PORTS=1 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_THEME=huggingface \ SYSTEM=spaces \ SHELL=/bin/bash # Remove any third-party apt sources to avoid issues with expiring keys. # Install apt-packages RUN rm -f /etc/apt/sources.list.d/*.list && \ apt-get update && apt-get install -y --no-install-recommends \ tzdata \ curl \ ca-certificates \ sudo \ git \ wget \ procps \ git-lfs \ zip \ unzip \ htop \ vim \ nano \ bzip2 \ libx11-6 \ build-essential \ libsndfile-dev \ software-properties-common \ jq \ tree \ libjpeg-turbo8-dev \ zlib1g-dev \ libtiff5-dev \ liblcms2-dev \ libfreetype6-dev \ libwebp-dev \ libharfbuzz-dev \ libfribidi-dev \ libopenjp2-7-dev \ libraqm0 \ && rm -rf /var/lib/apt/lists/* # Add sources & install nvtop & node RUN add-apt-repository ppa:flexiondotorg/nvtop && \ curl -sL https://deb.nodesource.com/setup_21.x | bash - && \ apt-get update && apt-get install -y --no-install-recommends \ nvtop \ nodejs \ && npm install -g configurable-http-proxy \ && rm -rf /var/lib/apt/lists/* # Create a non-root user and switch to it RUN adduser --disabled-password --gecos '' --shell /bin/bash user 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 $HOME/app $HOME/bin \ && chmod -R 775 $HOME ENV PATH=$HOME/bin:$PATH # Switch to user for conda installation USER user WORKDIR $HOME # Install Miniconda ARG CONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py312_24.11.1-0-Linux-x86_64.sh ENV PATH=$HOME/miniconda/bin:$PATH RUN curl -sLo ~/miniconda.sh ${CONDA_URL} && \ chmod +x ~/miniconda.sh && \ ~/miniconda.sh -b -p ~/miniconda && \ rm ~/miniconda.sh && \ conda clean -ya # base python packages RUN pip install --no-cache-dir --upgrade \ jupyterlab==4.3.4 \ tornado==6.4.2 \ ipywidgets # Copy some context we need now / later into app folder COPY 'packages.txt' 'requirements.txt' 'login.html' '_welcome.ipynb' \ 'on_build.sh' 'on_startup.sh' 'start_server.sh' $HOME/app/ COPY 'setup_timm_dev' 'setup_timm_scripts' $HOME/bin/ ####################################### # Start root user section ####################################### USER root # User Debian packages ## Security warning : Potential user code executed as root (build time) RUN apt-get update && \ xargs -r -a $HOME/app/packages.txt apt-get install -y --no-install-recommends && \ rm -rf /var/lib/apt/lists/* # Instead of using $HOME/app as our default, let's have files relative to our workspace in /data # This way it will be persisent if a persistent drive is mapped to /data WORKDIR /data RUN mkdir /data/.cache RUN chown -R user:user /data RUN chmod +x $HOME/app/start_server.sh RUN chmod +x $HOME/app/on_startup.sh RUN chmod 755 $HOME/bin/* ####################################### # End root user section ####################################### USER user ENV HF_HOME=/data/.cache/huggingface # Python packages in packages.txt RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt # Run extra steps to build environment via on_build.sh script RUN bash $HOME/app/on_build.sh # Apply overrides to Juptyer default settings RUN mkdir -p $HOME/miniconda/share/jupyter/lab/settings/ COPY overrides.json $HOME/miniconda/share/jupyter/lab/settings/ # Update login page template RUN SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])") \ && mv $HOME/app/login.html "$SITE_PACKAGES/jupyter_server/templates/login.html" # Remove Pillow and install faster Pillow-SIMD (big impact for limited CPU) RUN pip uninstall -y pillow && \ CC="cc -mavx2" pip install -U --force-reinstall --no-cache-dir pillow-simd CMD ["/home/user/app/start_server.sh"]