File size: 4,142 Bytes
0da5cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bf5d6e
 
0da5cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf634f8
0da5cb0
2bf5d6e
cf634f8
0da5cb0
 
 
 
 
cf634f8
 
0da5cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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"]