File size: 2,717 Bytes
aa1a2e9 722189e 9757169 f578c56 d9c9597 f578c56 9757169 c93b918 d9c9597 c93b918 d9c9597 9757169 d9c9597 f578c56 d9c9597 b7659bd d9c9597 b7659bd 9757169 d9c9597 aa1a2e9 d9c9597 aa1a2e9 d9c9597 aa1a2e9 ec78e7f bf5d9ea d7d6b2f aed86da 038ec37 bf5d9ea f92ad8c bf5d9ea 43ccb64 71aca09 43ccb64 a2dbf08 d9c9597 265f723 43ccb64 | 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 | # syntax=docker/dockerfile:1
FROM python:3.10.12
ARG APP_HOME=/home/user
ARG APP_CODE=/opt/code
ARG APP_DATA=/data/app
ARG HF_HOME=/data/huggingface
ENV APP_CODE=$APP_CODE \
APP_DATA=$APP_DATA \
HF_HOME=$HF_HOME
ENV PYTHONUNBUFFERED=1 \
SYSTEM=spaces \
SHELL=/bin/bash
# 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 \
git-lfs \
zip \
unzip \
htop \
bzip2 \
libx11-6 \
build-essential \
libsndfile-dev \
software-properties-common \
nodejs \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt
# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' --shell /bin/bash -u 1000 user \
&& chown -R user:user /opt
RUN echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER user
# All users can use /home/user as their home directory
ENV HOME=$APP_HOME
ENV PATH=$HOME/.local/bin:$PATH
RUN mkdir -p $HOME/.cache $HOME/.config \
&& chmod -R 777 $HOME
#######################################
# 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 --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
bash /root/on_startup.sh
#######################################
# End root user section
#######################################
USER user
WORKDIR $APP_HOME
RUN --mount=target=$APP_CODE/requirements.txt,source=requirements.txt \
pip3 install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir --upgrade -r $APP_CODE/requirements.txt
# Copy our code to $APP_CODE and config
COPY --chown=user:user --chmod=u=rX src/ $APP_CODE/
COPY --chown=user ./start_*.sh $APP_HOME
RUN chmod +x $APP_HOME/start_*.sh
COPY --chown=user:user --chmod=u=rX .streamlit/ $APP_HOME/.streamlit/
# Persistent disk space
# Assumes a mount is passed to the docker command, like:
# $ docker ... --mount type=volume,src=ai-playground-vol,dst=/data ...
# see https://huggingface.co/docs/hub/spaces-storage
VOLUME /data
ENV PYTHONPATH=$APP_CODE:$PYTHONPATH
RUN ln -s $APP_DATA/ data
RUN ln -s $APP_CODE/ code
ADD jupyter/notebooks notebooks
# Expose streamlit application
EXPOSE 8501
EXPOSE 7860
ENTRYPOINT [ "bash", "-o", "allexport" ]
CMD [ "-f", "./start_server.sh" ]
|