From d6c34719091351e0606acd34fd9524bce52346be Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Fri, 12 Feb 2021 16:53:51 +0100 Subject: [PATCH] reprganized docker file, less layers, new shortcuts for management commands --- Dockerfile | 59 +++++++++++++-------------- docker/install_management_commands.sh | 6 +++ docker/management_script.sh | 15 +++++++ 3 files changed, 50 insertions(+), 30 deletions(-) create mode 100755 docker/install_management_commands.sh create mode 100644 docker/management_script.sh diff --git a/Dockerfile b/Dockerfile index 6247ef009..57f96c39f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,6 @@ RUN ./configure && make FROM python:3.7-slim -WORKDIR /usr/src/paperless/ - -COPY requirements.txt ./ - # Binary dependencies RUN apt-get update \ && apt-get -y --no-install-recommends install \ @@ -49,16 +45,24 @@ RUN apt-get update \ tesseract-ocr-spa \ unpaper \ zlib1g \ - && rm -rf /var/lib/apt/lists/* # This pulls in updated dependencies from bullseye to fix some issues with file type detection. # TODO: Remove this once bullseye releases. -RUN echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list.d/bullseye.list \ + && echo "deb http://deb.debian.org/debian bullseye main" > /etc/apt/sources.list.d/bullseye.list \ && apt-get update \ && apt-get install --no-install-recommends -y file libmagic-dev \ && rm -rf /var/lib/apt/lists/* \ && rm /etc/apt/sources.list.d/bullseye.list +# copy jbig2enc +COPY --from=jbig2enc /usr/src/jbig2enc/src/.libs/libjbig2enc* /usr/local/lib/ +COPY --from=jbig2enc /usr/src/jbig2enc/src/jbig2 /usr/local/bin/ +COPY --from=jbig2enc /usr/src/jbig2enc/src/*.h /usr/local/include/ + +WORKDIR /usr/src/paperless/src/ + +COPY requirements.txt ../ + # Python dependencies RUN apt-get update \ && apt-get -y --no-install-recommends install \ @@ -67,41 +71,36 @@ RUN apt-get update \ libpq-dev \ libqpdf-dev \ && python3 -m pip install --upgrade --no-cache-dir supervisor \ - && python3 -m pip install --no-cache-dir -r requirements.txt \ + && python3 -m pip install --no-cache-dir -r ../requirements.txt \ && apt-get -y purge build-essential libqpdf-dev \ && apt-get -y autoremove --purge \ - && rm -rf /var/lib/apt/lists/* \ - && mkdir /var/log/supervisord /var/run/supervisord + && rm -rf /var/lib/apt/lists/* +# setup docker-specific things +COPY docker/ ./docker/ -# copy scripts -# this fixes issues with imagemagick and PDF -COPY docker/imagemagick-policy.xml /etc/ImageMagick-6/policy.xml - -COPY gunicorn.conf.py ./ -COPY docker/supervisord.conf /etc/supervisord.conf -COPY docker/docker-entrypoint.sh /sbin/docker-entrypoint.sh - -# copy jbig2enc -COPY --from=jbig2enc /usr/src/jbig2enc/src/.libs/libjbig2enc* /usr/local/lib/ -COPY --from=jbig2enc /usr/src/jbig2enc/src/jbig2 /usr/local/bin/ -COPY --from=jbig2enc /usr/src/jbig2enc/src/*.h /usr/local/include/ +RUN cd docker \ + && cp imagemagick-policy.xml /etc/ImageMagick-6/policy.xml \ + && mkdir /var/log/supervisord /var/run/supervisord \ + && cp supervisord.conf /etc/supervisord.conf \ + && cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \ + && chmod 755 /sbin/docker-entrypoint.sh \ + && chmod +x install_management_commands.sh \ + && ./install_management_commands.sh \ + && cd .. \ + && rm docker -rf +COPY gunicorn.conf.py ../ # copy app -COPY src/ ./src/ +COPY src/ ./ # add users, setup scripts RUN addgroup --gid 1000 paperless \ && useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \ - && chown -R paperless:paperless . \ - && chmod 755 /sbin/docker-entrypoint.sh - -WORKDIR /usr/src/paperless/src/ - -RUN sudo -HEu paperless python3 manage.py collectstatic --clear --no-input - -RUN sudo -HEu paperless python3 manage.py compilemessages + && chown -R paperless:paperless ../ \ + && sudo -HEu paperless python3 manage.py collectstatic --clear --no-input \ + && sudo -HEu paperless python3 manage.py compilemessages VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/usr/src/paperless/consume", "/usr/src/paperless/export"] ENTRYPOINT ["/sbin/docker-entrypoint.sh"] diff --git a/docker/install_management_commands.sh b/docker/install_management_commands.sh new file mode 100755 index 000000000..6aeca635d --- /dev/null +++ b/docker/install_management_commands.sh @@ -0,0 +1,6 @@ +for command in document_archiver document_exporter document_importer mail_fetcher document_create_classifier document_index document_renamer document_retagger document_thumbnails; +do + echo "installing $command..." + sed "s/management_command/$command/g" management_script.sh > /usr/local/bin/$command + chmod +x /usr/local/bin/$command +done diff --git a/docker/management_script.sh b/docker/management_script.sh new file mode 100644 index 000000000..bffa26e98 --- /dev/null +++ b/docker/management_script.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +cd /usr/src/paperless/src/ + +if [[ $(id -u) == 0 ]] ; +then + sudo -HEu paperless python3 manage.py management_command "$@" +elif [[ $(id -un) == "paperless" ]] ; +then + python3 manage.py management_command "$@" +else + echo "Unknown user." +fi