reprganized docker file, less layers, new shortcuts for management commands

This commit is contained in:
jonaswinkler 2021-02-12 16:53:51 +01:00
parent 5b56fad9c7
commit d6c3471909
3 changed files with 50 additions and 30 deletions

View File

@ -10,10 +10,6 @@ RUN ./configure && make
FROM python:3.7-slim FROM python:3.7-slim
WORKDIR /usr/src/paperless/
COPY requirements.txt ./
# Binary dependencies # Binary dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get -y --no-install-recommends install \ && apt-get -y --no-install-recommends install \
@ -49,16 +45,24 @@ RUN apt-get update \
tesseract-ocr-spa \ tesseract-ocr-spa \
unpaper \ unpaper \
zlib1g \ zlib1g \
&& rm -rf /var/lib/apt/lists/*
# This pulls in updated dependencies from bullseye to fix some issues with file type detection. # This pulls in updated dependencies from bullseye to fix some issues with file type detection.
# TODO: Remove this once bullseye releases. # 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 update \
&& apt-get install --no-install-recommends -y file libmagic-dev \ && apt-get install --no-install-recommends -y file libmagic-dev \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& rm /etc/apt/sources.list.d/bullseye.list && 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 # Python dependencies
RUN apt-get update \ RUN apt-get update \
&& apt-get -y --no-install-recommends install \ && apt-get -y --no-install-recommends install \
@ -67,41 +71,36 @@ RUN apt-get update \
libpq-dev \ libpq-dev \
libqpdf-dev \ libqpdf-dev \
&& python3 -m pip install --upgrade --no-cache-dir supervisor \ && 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 purge build-essential libqpdf-dev \
&& apt-get -y autoremove --purge \ && apt-get -y autoremove --purge \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/*
&& mkdir /var/log/supervisord /var/run/supervisord
# setup docker-specific things
COPY docker/ ./docker/
# copy scripts RUN cd docker \
# this fixes issues with imagemagick and PDF && cp imagemagick-policy.xml /etc/ImageMagick-6/policy.xml \
COPY docker/imagemagick-policy.xml /etc/ImageMagick-6/policy.xml && mkdir /var/log/supervisord /var/run/supervisord \
&& cp supervisord.conf /etc/supervisord.conf \
COPY gunicorn.conf.py ./ && cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \
COPY docker/supervisord.conf /etc/supervisord.conf && chmod 755 /sbin/docker-entrypoint.sh \
COPY docker/docker-entrypoint.sh /sbin/docker-entrypoint.sh && chmod +x install_management_commands.sh \
&& ./install_management_commands.sh \
# copy jbig2enc && cd .. \
COPY --from=jbig2enc /usr/src/jbig2enc/src/.libs/libjbig2enc* /usr/local/lib/ && rm docker -rf
COPY --from=jbig2enc /usr/src/jbig2enc/src/jbig2 /usr/local/bin/
COPY --from=jbig2enc /usr/src/jbig2enc/src/*.h /usr/local/include/
COPY gunicorn.conf.py ../
# copy app # copy app
COPY src/ ./src/ COPY src/ ./
# add users, setup scripts # add users, setup scripts
RUN addgroup --gid 1000 paperless \ RUN addgroup --gid 1000 paperless \
&& useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \ && useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \
&& chown -R paperless:paperless . \ && chown -R paperless:paperless ../ \
&& chmod 755 /sbin/docker-entrypoint.sh && sudo -HEu paperless python3 manage.py collectstatic --clear --no-input \
&& sudo -HEu paperless python3 manage.py compilemessages
WORKDIR /usr/src/paperless/src/
RUN sudo -HEu paperless python3 manage.py collectstatic --clear --no-input
RUN sudo -HEu paperless python3 manage.py compilemessages
VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/usr/src/paperless/consume", "/usr/src/paperless/export"] VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/usr/src/paperless/consume", "/usr/src/paperless/export"]
ENTRYPOINT ["/sbin/docker-entrypoint.sh"] ENTRYPOINT ["/sbin/docker-entrypoint.sh"]

View File

@ -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

View File

@ -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