Anthony Truchet commited on
Commit ·
b7659bd
1
Parent(s): 038ec37
refacor: clean up the Dockerfile
Browse files- Dockerfile +13 -14
- scripts/build-run-local-docker.sh +1 -1
Dockerfile
CHANGED
|
@@ -5,45 +5,44 @@ ARG APP_HOME=/home/user
|
|
| 5 |
ARG APP_CODE=/app
|
| 6 |
ARG APP_DATA=/data/app
|
| 7 |
ARG HF_HOME=/data/huggingface
|
| 8 |
-
ARG HOST_STATIC_FILES=static
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
COPY ./requirements.txt $APP_CODE/requirements.txt
|
| 13 |
COPY ./packages.txt $APP_CODE/packages.txt
|
| 14 |
|
| 15 |
-
|
| 16 |
-
RUN
|
|
|
|
|
|
|
| 17 |
RUN pip3 install --no-cache-dir --upgrade pip
|
| 18 |
RUN pip3 install --no-cache-dir -r $APP_CODE/requirements.txt
|
| 19 |
|
| 20 |
-
# Creates an
|
| 21 |
RUN useradd -m -u 1000 user
|
| 22 |
|
| 23 |
-
# Copy our code to $APP_CODE
|
| 24 |
-
|
| 25 |
COPY --chown=user:user --chmod=u=rX src/ $APP_CODE/
|
| 26 |
COPY --chown=user:user --chmod=u=rX .streamlit/ $APP_HOME/.streamlit/
|
| 27 |
|
| 28 |
# Persistent disk space
|
| 29 |
# Assumes a mount is passed to the docker command, like:
|
| 30 |
# $ docker ... --mount type=volume,src=ai-playground-vol,dst=/data ...
|
| 31 |
-
#
|
| 32 |
# see https://huggingface.co/docs/hub/spaces-storage
|
| 33 |
VOLUME /data
|
| 34 |
-
RUN mkdir -p /data
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# User
|
| 37 |
USER user
|
| 38 |
-
ENV APP_DATA $APP_DATA
|
| 39 |
-
RUN mkdir -p $APP_DATA
|
| 40 |
ENV HOME $APP_HOME
|
| 41 |
ENV PATH $HOME/.local/bin:$PATH
|
| 42 |
-
|
| 43 |
-
RUN mkdir -p $HF_HOME
|
| 44 |
|
| 45 |
# Expose streamlit application
|
| 46 |
-
WORKDIR $APP_HOME
|
| 47 |
EXPOSE 8501
|
| 48 |
CMD streamlit run $APP_CODE/app.py \
|
| 49 |
--logger.level=info \
|
|
|
|
| 5 |
ARG APP_CODE=/app
|
| 6 |
ARG APP_DATA=/data/app
|
| 7 |
ARG HF_HOME=/data/huggingface
|
|
|
|
| 8 |
|
| 9 |
+
ENV APP_CODE $APP_CODE
|
| 10 |
+
ENV APP_DATA $APP_DATA
|
| 11 |
+
ENV HF_HOME $HF_HOME
|
| 12 |
|
| 13 |
COPY ./requirements.txt $APP_CODE/requirements.txt
|
| 14 |
COPY ./packages.txt $APP_CODE/packages.txt
|
| 15 |
|
| 16 |
+
|
| 17 |
+
RUN apt-get update \
|
| 18 |
+
&& xargs -r -a $APP_CODE/packages.txt apt-get install -y \
|
| 19 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
RUN pip3 install --no-cache-dir --upgrade pip
|
| 21 |
RUN pip3 install --no-cache-dir -r $APP_CODE/requirements.txt
|
| 22 |
|
| 23 |
+
# Creates an unpriviledged user
|
| 24 |
RUN useradd -m -u 1000 user
|
| 25 |
|
| 26 |
+
# Copy our code to $APP_CODE and config to the working directory
|
|
|
|
| 27 |
COPY --chown=user:user --chmod=u=rX src/ $APP_CODE/
|
| 28 |
COPY --chown=user:user --chmod=u=rX .streamlit/ $APP_HOME/.streamlit/
|
| 29 |
|
| 30 |
# Persistent disk space
|
| 31 |
# Assumes a mount is passed to the docker command, like:
|
| 32 |
# $ docker ... --mount type=volume,src=ai-playground-vol,dst=/data ...
|
|
|
|
| 33 |
# see https://huggingface.co/docs/hub/spaces-storage
|
| 34 |
VOLUME /data
|
| 35 |
+
RUN mkdir -p /data && chown user:user /data
|
| 36 |
+
RUN mkdir -p $APP_DATA && chown user:user $APP_DATA
|
| 37 |
+
RUN mkdir -p $HF_HOME && chown user:user $HF_HOME
|
| 38 |
|
| 39 |
# User
|
| 40 |
USER user
|
|
|
|
|
|
|
| 41 |
ENV HOME $APP_HOME
|
| 42 |
ENV PATH $HOME/.local/bin:$PATH
|
| 43 |
+
WORKDIR $APP_HOME
|
|
|
|
| 44 |
|
| 45 |
# Expose streamlit application
|
|
|
|
| 46 |
EXPOSE 8501
|
| 47 |
CMD streamlit run $APP_CODE/app.py \
|
| 48 |
--logger.level=info \
|
scripts/build-run-local-docker.sh
CHANGED
|
@@ -17,7 +17,7 @@ docker build --label tests -t $CONTAINER_NAME .
|
|
| 17 |
|
| 18 |
# During development ONLY use a `bind mount` to enable
|
| 19 |
# editing the code without having to rebuild the container.
|
| 20 |
-
docker run -it \
|
| 21 |
-p 8501:8501 \
|
| 22 |
--mount type=volume,src=$VOLUME_NAME,dst=/data \
|
| 23 |
--mount type=bind,source=${ROOT_DIRECTORY}/src/,target=/app/,readonly \
|
|
|
|
| 17 |
|
| 18 |
# During development ONLY use a `bind mount` to enable
|
| 19 |
# editing the code without having to rebuild the container.
|
| 20 |
+
docker run --rm -it \
|
| 21 |
-p 8501:8501 \
|
| 22 |
--mount type=volume,src=$VOLUME_NAME,dst=/data \
|
| 23 |
--mount type=bind,source=${ROOT_DIRECTORY}/src/,target=/app/,readonly \
|