Zhofang commited on
Commit
b50a4c7
·
verified ·
1 Parent(s): c660658

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -27
Dockerfile CHANGED
@@ -2,7 +2,8 @@ FROM nvidia/cuda:11.3.1-base-ubuntu20.04
2
  ENV DEBIAN_FRONTEND=noninteractive \
3
  TZ=Europe/Paris
4
 
5
- # Use a single RUN command to reduce image layers and improve build speed
 
6
  RUN rm -f /etc/apt/sources.list.d/*.list && \
7
  apt-get update && apt-get install -y --no-install-recommends \
8
  curl \
@@ -24,46 +25,42 @@ RUN rm -f /etc/apt/sources.list.d/*.list && \
24
  nano \
25
  bzip2 \
26
  libx11-6 \
 
27
  build-essential \
28
  libsndfile-dev \
29
  software-properties-common \
30
- python3-pip # Install pip for Python package management\
31
- python3-bottle # Install the missing bottle library\
32
  && rm -rf /var/lib/apt/lists/*
33
 
34
  RUN add-apt-repository ppa:flexiondotorg/nvtop && \
35
- apt-get update && \ # Update again after adding the PPA
36
  apt-get upgrade -y && \
37
- apt-get install -y --no-install-recommends nvtop && \
38
- rm -rf /var/lib/apt/lists/*
39
 
40
-
41
- RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
42
- apt-get update && \ # Update after adding node.js source
43
  apt-get install -y nodejs && \
44
- npm install -g configurable-http-proxy && \
45
- rm -rf /var/lib/apt/lists/*
46
 
47
  # Create a working directory
48
  WORKDIR /app
49
 
50
  # Create a non-root user and switch to it
51
- RUN useradd --create-home --shell /bin/bash user # Use useradd which is preferred
 
52
  RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
53
  USER user
54
 
55
- # All users can use /home/user as their home directory (already set by useradd --create-home)
56
  ENV HOME=/home/user
57
- RUN mkdir $HOME/.cache $HOME/.config && chmod -R 777 $HOME # $HOME is already defined
 
58
 
59
  # Set up the Conda environment
60
  ENV CONDA_AUTO_UPDATE_CONDA=false \
61
  PATH=$HOME/miniconda/bin:$PATH
62
- RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh && \
63
- chmod +x ~/miniconda.sh && \
64
- ~/miniconda.sh -b -p ~/miniconda && \
65
- rm ~/miniconda.sh && \
66
- conda clean -ya
67
 
68
  WORKDIR $HOME/app
69
 
@@ -74,15 +71,17 @@ WORKDIR $HOME/app
74
  USER root
75
 
76
  # User Debian packages
77
- COPY packages.txt /root/ # Copy before using it in RUN
78
- RUN apt-get update && \
79
- xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends && \
80
- rm -rf /var/lib/apt/lists/*
 
81
 
82
- COPY on_startup.sh /root/ # Copy before using
83
- RUN chmod +x /root/on_startup.sh && /root/on_startup.sh
84
 
85
  RUN mkdir /data && chown user:user /data
 
86
 
87
  #######################################
88
  # End root user section
@@ -91,8 +90,8 @@ RUN mkdir /data && chown user:user /data
91
  USER user
92
 
93
  # Python packages
94
- COPY --chown=user:user . $HOME/app
95
-
96
 
97
  ENV PYTHONUNBUFFERED=1 \
98
  GRADIO_ALLOW_FLAGGING=never \
 
2
  ENV DEBIAN_FRONTEND=noninteractive \
3
  TZ=Europe/Paris
4
 
5
+ # Remove any third-party apt sources to avoid issues with expiring keys.
6
+ # Install some basic utilities
7
  RUN rm -f /etc/apt/sources.list.d/*.list && \
8
  apt-get update && apt-get install -y --no-install-recommends \
9
  curl \
 
25
  nano \
26
  bzip2 \
27
  libx11-6 \
28
+ python3-pip \
29
  build-essential \
30
  libsndfile-dev \
31
  software-properties-common \
 
 
32
  && rm -rf /var/lib/apt/lists/*
33
 
34
  RUN add-apt-repository ppa:flexiondotorg/nvtop && \
 
35
  apt-get upgrade -y && \
36
+ apt-get install -y --no-install-recommends nvtop
 
37
 
38
+ RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
 
 
39
  apt-get install -y nodejs && \
40
+ npm install -g configurable-http-proxy
 
41
 
42
  # Create a working directory
43
  WORKDIR /app
44
 
45
  # Create a non-root user and switch to it
46
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
47
+ && chown -R user:user /app
48
  RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
49
  USER user
50
 
51
+ # All users can use /home/user as their home directory
52
  ENV HOME=/home/user
53
+ RUN mkdir $HOME/.cache $HOME/.config \
54
+ && chmod -R 777 $HOME
55
 
56
  # Set up the Conda environment
57
  ENV CONDA_AUTO_UPDATE_CONDA=false \
58
  PATH=$HOME/miniconda/bin:$PATH
59
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
60
+ && chmod +x ~/miniconda.sh \
61
+ && ~/miniconda.sh -b -p ~/miniconda \
62
+ && rm ~/miniconda.sh \
63
+ && conda clean -ya
64
 
65
  WORKDIR $HOME/app
66
 
 
71
  USER root
72
 
73
  # User Debian packages
74
+ ## Security warning : Potential user code executed as root (build time)
75
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
76
+ apt-get update && \
77
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
78
+ && rm -rf /var/lib/apt/lists/*
79
 
80
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
81
+ bash /root/on_startup.sh
82
 
83
  RUN mkdir /data && chown user:user /data
84
+ RUN pip install bottle
85
 
86
  #######################################
87
  # End root user section
 
90
  USER user
91
 
92
  # Python packages
93
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
94
+ COPY --chown=user . $HOME/app
95
 
96
  ENV PYTHONUNBUFFERED=1 \
97
  GRADIO_ALLOW_FLAGGING=never \