From 9694f8d7ee3e242d1c71d68cbeed735c17e477e3 Mon Sep 17 00:00:00 2001 From: Sush Shringarputale Date: Sun, 20 Jun 2021 11:09:22 -0700 Subject: [PATCH] Add docker multi stage build --- backend/Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index c82b821..4b7670b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,9 +1,10 @@ -FROM python:3.8-slim-buster +FROM python:3.8-slim-buster as base # system packages installation RUN apt update && apt install -y ffmpeg libimage-exiftool-perl curl nfs-common cifs-utils libopenblas-dev libmagickwand-dev libheif-dev libmagic1 ufraw-batch libboost-all-dev libxrender-dev liblapack-dev git bzip2 cmake build-essential libsm6 libglib2.0-0 libgl1-mesa-glx libpq-dev --no-install-recommends +FROM base as model # pre trained models download WORKDIR /data_models RUN mkdir -p /root/.cache/torch/hub/checkpoints/ @@ -12,6 +13,7 @@ RUN curl -SL https://github.com/LibrePhotos/librephotos-docker/releases/download RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth RUN pip install torch==1.8.0+cpu torchvision==0.9.0+cpu -f https://download.pytorch.org/whl/torch_stable.html +FROM base as dlib # Build and install dlib WORKDIR / RUN git clone https://github.com/davisking/dlib.git && \ @@ -23,6 +25,7 @@ RUN git clone https://github.com/davisking/dlib.git && \ python setup.py install --no USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA --no USE_SSE4_INSTRUCTIONS # actual project +FROM base ARG DEBUG WORKDIR /code RUN git clone https://github.com/LibrePhotos/librephotos . @@ -31,5 +34,8 @@ RUN if [ "$DEBUG" = 1 ] ; then pip install -r requirements.dev.txt ; fi RUN python -m spacy download en_core_web_sm EXPOSE 8001 +COPY --from=model /data_models /data-models +COPY --from=dlib /dlib/build /dlib/build COPY entrypoint.sh /entrypoint.sh CMD ["/entrypoint.sh"] +