davanstrien HF staff commited on
Commit
b42b3f3
1 Parent(s): 5732dad

chore: Add Dockerfile for containerization

Browse files
Files changed (1) hide show
  1. Dockerfile +100 -0
Dockerfile ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.3.1-base-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Europe/Paris
5
+
6
+ # Remove any third-party apt sources to avoid issues with expiring keys.
7
+ # Install some basic utilities
8
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
9
+ apt-get update && apt-get install -y --no-install-recommends \
10
+ curl \
11
+ ca-certificates \
12
+ sudo \
13
+ git \
14
+ git-lfs \
15
+ zip \
16
+ unzip \
17
+ htop \
18
+ bzip2 \
19
+ libx11-6 \
20
+ build-essential \
21
+ libsndfile-dev \
22
+ software-properties-common \
23
+ && rm -rf /var/lib/apt/lists/*
24
+
25
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
26
+ apt-get upgrade -y && \
27
+ apt-get install -y --no-install-recommends nvtop
28
+
29
+ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
30
+ apt-get install -y nodejs && \
31
+ npm install -g configurable-http-proxy
32
+
33
+ # Create a working directory
34
+ WORKDIR /app
35
+
36
+ # Create a non-root user and switch to it
37
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
38
+ && chown -R user:user /app
39
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
40
+ USER user
41
+
42
+ # All users can use /home/user as their home directory
43
+ ENV HOME=/home/user
44
+ RUN mkdir $HOME/.cache $HOME/.config \
45
+ && chmod -R 777 $HOME
46
+
47
+ # Set up the Conda environment
48
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
49
+ PATH=$HOME/miniconda/bin:$PATH
50
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
51
+ && chmod +x ~/miniconda.sh \
52
+ && ~/miniconda.sh -b -p ~/miniconda \
53
+ && rm ~/miniconda.sh \
54
+ && conda clean -ya
55
+
56
+ WORKDIR $HOME/app
57
+
58
+ #######################################
59
+ # Start root user section
60
+ #######################################
61
+
62
+ USER root
63
+
64
+ # User Debian packages
65
+ ## Security warning : Potential user code executed as root (build time)
66
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
67
+ apt-get update && \
68
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
69
+ && rm -rf /var/lib/apt/lists/*
70
+
71
+ # Copy notebooks directory to a temporary location
72
+ COPY --chown=user notebooks /home/user/notebooks
73
+
74
+ #######################################
75
+ # End root user section
76
+ #######################################
77
+
78
+ USER user
79
+
80
+ # Python packages
81
+ RUN --mount=target=base_requirements.txt,source=base_requirements.txt \
82
+ --mount=target=notebooks/requirements.txt,source=notebooks/requirements.txt \
83
+ pip install --no-cache-dir --upgrade -r base_requirements.txt -r notebooks/requirements.txt
84
+
85
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
86
+ COPY --chown=user . $HOME/app
87
+
88
+ RUN chmod +x start_server.sh
89
+
90
+ COPY --chown=user login.html /home/user/miniconda/lib/python3.9/site-packages/jupyter_server/templates/login.html
91
+
92
+ ENV PYTHONUNBUFFERED=1 \
93
+ GRADIO_ALLOW_FLAGGING=never \
94
+ GRADIO_NUM_PORTS=1 \
95
+ GRADIO_SERVER_NAME=0.0.0.0 \
96
+ GRADIO_THEME=huggingface \
97
+ SYSTEM=spaces \
98
+ SHELL=/bin/bash
99
+
100
+ CMD ["./start_server.sh"]