From 54872c129859b31cb3f22da6c6366b852e9724f3 Mon Sep 17 00:00:00 2001 From: Guy Addadi Date: Sat, 9 Dec 2017 23:08:56 +0200 Subject: [PATCH 1/8] adapted Dockerfile for alpine image --- Dockerfile | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index f661012b5..20206a5ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,17 @@ -FROM python:3.5 -MAINTAINER Pit Kleyersburg +FROM alpine:latest # Install dependencies -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - sudo \ - tesseract-ocr tesseract-ocr-eng imagemagick ghostscript unpaper \ - && rm -rf /var/lib/apt/lists/* +RUN apk --no-cache --update add \ + python3 python3-dev gcc musl-dev gnupg zlib-dev jpeg-dev libmagic \ + sudo tesseract-ocr imagemagick ghostscript unpaper -# Install python dependencies -RUN mkdir -p /usr/src/paperless +## Install python dependencies +RUN python3 -m ensurepip && \ + rm -r /usr/lib/python*/ensurepip && \ + mkdir -p /usr/src/paperless WORKDIR /usr/src/paperless COPY requirements.txt /usr/src/paperless/ -RUN pip install --no-cache-dir -r requirements.txt +RUN pip3 install --no-cache-dir -r requirements.txt # Copy application RUN mkdir -p /usr/src/paperless/src @@ -31,8 +30,8 @@ WORKDIR /usr/src/paperless/src RUN ./manage.py migrate # Create user -RUN groupadd -g 1000 paperless \ - && useradd -u 1000 -g 1000 -d /usr/src/paperless paperless \ +RUN addgroup -g 1000 paperless \ + && adduser -D -u 1000 -G paperless -h /usr/src/paperless paperless \ && chown -Rh paperless:paperless /usr/src/paperless # Set export directory From c40b6fbd4e7f4516d65b2661ed0f5819a3d45e14 Mon Sep 17 00:00:00 2001 From: Guy Addadi Date: Mon, 11 Dec 2017 00:41:36 +0200 Subject: [PATCH 2/8] added bash and moved all dev packages to be with virtual alpine env that is removed after python libraries installation --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20206a5ba..7b0464a21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,10 @@ FROM alpine:latest # Install dependencies RUN apk --no-cache --update add \ - python3 python3-dev gcc musl-dev gnupg zlib-dev jpeg-dev libmagic \ - sudo tesseract-ocr imagemagick ghostscript unpaper + python3 gnupg libmagic bash \ + sudo tesseract-ocr imagemagick ghostscript unpaper && \ + apk --no-cache add --virtual .build-dependencies \ + python3-dev gcc musl-dev zlib-dev jpeg-dev ## Install python dependencies RUN python3 -m ensurepip && \ @@ -46,4 +48,7 @@ RUN chmod 755 /sbin/docker-entrypoint.sh VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/consume", "/export"] ENTRYPOINT ["/sbin/docker-entrypoint.sh"] + +# Remove build dependencies +RUN apk del .build-dependencies CMD ["--help"] From a825c546342de47def61943edc76e1fd64c97725 Mon Sep 17 00:00:00 2001 From: Guy Addadi Date: Mon, 11 Dec 2017 22:03:51 +0200 Subject: [PATCH 3/8] moved to alpine:3.7 removed RUN layers to save image space, removed redundant mkdir commands --- Dockerfile | 67 ++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b0464a21..befa90c26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,54 +1,41 @@ -FROM alpine:latest - +FROM alpine:3.7 +WORKDIR /usr/src/paperless +COPY requirements.txt /usr/src/paperless/ +# Copy application +COPY src/ /usr/src/paperless/src/ +COPY data/ /usr/src/paperless/data/ +COPY media/ /usr/src/paperless/media/ +# Set export directory +ENV PAPERLESS_EXPORT_DIR /export +# Set consumption directory +ENV PAPERLESS_CONSUMPTION_DIR /consume +COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh # Install dependencies RUN apk --no-cache --update add \ python3 gnupg libmagic bash \ sudo tesseract-ocr imagemagick ghostscript unpaper && \ apk --no-cache add --virtual .build-dependencies \ - python3-dev gcc musl-dev zlib-dev jpeg-dev - + python3-dev gcc musl-dev zlib-dev jpeg-dev && \ ## Install python dependencies -RUN python3 -m ensurepip && \ + python3 -m ensurepip && \ rm -r /usr/lib/python*/ensurepip && \ - mkdir -p /usr/src/paperless -WORKDIR /usr/src/paperless -COPY requirements.txt /usr/src/paperless/ -RUN pip3 install --no-cache-dir -r requirements.txt - -# Copy application -RUN mkdir -p /usr/src/paperless/src -RUN mkdir -p /usr/src/paperless/data -RUN mkdir -p /usr/src/paperless/media -COPY src/ /usr/src/paperless/src/ -COPY data/ /usr/src/paperless/data/ -COPY media/ /usr/src/paperless/media/ - -# Set consumption directory -ENV PAPERLESS_CONSUMPTION_DIR /consume -RUN mkdir -p $PAPERLESS_CONSUMPTION_DIR - + mkdir -p /usr/src/paperless && \ + pip3 install --no-cache-dir -r requirements.txt && \ +# Remove build dependencies + apk del .build-dependencies && \ +# Create the consumption directory + mkdir -p $PAPERLESS_CONSUMPTION_DIR && \ # Migrate database -WORKDIR /usr/src/paperless/src -RUN ./manage.py migrate - + ./src/manage.py migrate && \ # Create user -RUN addgroup -g 1000 paperless \ - && adduser -D -u 1000 -G paperless -h /usr/src/paperless paperless \ - && chown -Rh paperless:paperless /usr/src/paperless - -# Set export directory -ENV PAPERLESS_EXPORT_DIR /export -RUN mkdir -p $PAPERLESS_EXPORT_DIR - + addgroup -g 1000 paperless && \ + adduser -D -u 1000 -G paperless -h /usr/src/paperless paperless && \ + chown -Rh paperless:paperless /usr/src/paperless && \ + mkdir -p $PAPERLESS_EXPORT_DIR && \ # Setup entrypoint -COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh -RUN chmod 755 /sbin/docker-entrypoint.sh - + chmod 755 /sbin/docker-entrypoint.sh +WORKDIR /usr/src/paperless/src # Mount volumes VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/consume", "/export"] - ENTRYPOINT ["/sbin/docker-entrypoint.sh"] - -# Remove build dependencies -RUN apk del .build-dependencies CMD ["--help"] From 98d4e102bf4b5e5402eaa750724ea047af243a38 Mon Sep 17 00:00:00 2001 From: Guy Addadi Date: Tue, 12 Dec 2017 23:12:34 +0200 Subject: [PATCH 4/8] removed ENV WORKDIR layers, reorg the commands in groups with comments and black lines when possible. Removed redundant mkdir command --- Dockerfile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index befa90c26..d2144d8c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,26 @@ FROM alpine:3.7 -WORKDIR /usr/src/paperless -COPY requirements.txt /usr/src/paperless/ + # Copy application +COPY requirements.txt /usr/src/paperless/ COPY src/ /usr/src/paperless/src/ COPY data/ /usr/src/paperless/data/ COPY media/ /usr/src/paperless/media/ -# Set export directory -ENV PAPERLESS_EXPORT_DIR /export -# Set consumption directory -ENV PAPERLESS_CONSUMPTION_DIR /consume COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh + +# Set export and consumption directories +ENV PAPERLESS_EXPORT_DIR=/export \ + PAPERLESS_CONSUMPTION_DIR=/consume + # Install dependencies RUN apk --no-cache --update add \ python3 gnupg libmagic bash \ sudo tesseract-ocr imagemagick ghostscript unpaper && \ apk --no-cache add --virtual .build-dependencies \ python3-dev gcc musl-dev zlib-dev jpeg-dev && \ -## Install python dependencies +# Install python dependencies python3 -m ensurepip && \ rm -r /usr/lib/python*/ensurepip && \ - mkdir -p /usr/src/paperless && \ + cd /usr/src/paperless && \ pip3 install --no-cache-dir -r requirements.txt && \ # Remove build dependencies apk del .build-dependencies && \ @@ -34,8 +35,9 @@ RUN apk --no-cache --update add \ mkdir -p $PAPERLESS_EXPORT_DIR && \ # Setup entrypoint chmod 755 /sbin/docker-entrypoint.sh + WORKDIR /usr/src/paperless/src -# Mount volumes +# Mount volumes and set Entrypoint VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/consume", "/export"] ENTRYPOINT ["/sbin/docker-entrypoint.sh"] CMD ["--help"] From 01bb91297243bffeddc54732da5faaf2c69afe55 Mon Sep 17 00:00:00 2001 From: Guy Date: Tue, 19 Dec 2017 22:34:22 +0200 Subject: [PATCH 5/8] changed docker-comppse.yml example to build the docker image instead of pull the previously used debian based image from docker hub --- docker-compose.yml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 2b7ee8b36..6920836ba 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -2,7 +2,7 @@ version: '2' services: webserver: - image: pitkley/paperless + build: ./ ports: # You can adapt the port you want Paperless to listen on by # modifying the part before the `:`. @@ -20,7 +20,7 @@ services: command: ["runserver", "--insecure", "0.0.0.0:8000"] consumer: - image: pitkley/paperless + build: ./ volumes: - data:/usr/src/paperless/data - media:/usr/src/paperless/media From febf6799ef57274ee0f4c1a18de65ac6fdf1fbeb Mon Sep 17 00:00:00 2001 From: Guy Date: Wed, 20 Dec 2017 16:17:58 +0200 Subject: [PATCH 6/8] adapted docker-entrypoint script for alpine docker image (mainly how to install additional OCR languages) --- scripts/docker-entrypoint.sh | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 38b8ac1da..f9fde70c8 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -9,7 +9,7 @@ map_uidgid() { USERMAP_UID=${USERMAP_UID:-$USERMAP_ORIG_UID} if [[ ${USERMAP_UID} != "${USERMAP_ORIG_UID}" || ${USERMAP_GID} != "${USERMAP_ORIG_GID}" ]]; then echo "Mapping UID and GID for paperless:paperless to $USERMAP_UID:$USERMAP_GID" - groupmod -g "${USERMAP_GID}" paperless + addgroup -g "${USERMAP_GID}" paperless sed -i -e "s|:${USERMAP_ORIG_UID}:${USERMAP_GID}:|:${USERMAP_UID}:${USERMAP_GID}:|" /etc/passwd fi } @@ -56,25 +56,24 @@ install_languages() { return fi - # Update apt-lists - apt-get update - # Loop over languages to be installed for lang in "${langs[@]}"; do - pkg="tesseract-ocr-$lang" - if dpkg -s "$pkg" > /dev/null 2>&1; then + pkg="tesseract-ocr-data-$lang" + + # English is installed by default + if [ "$lang" == "eng" ]; then + continue + fi + + if apk info -e "$pkg" > /dev/null 2>&1; then + continue + fi + if ! apk info "$pkg" > /dev/null 2>&1; then continue fi - if ! apt-cache show "$pkg" > /dev/null 2>&1; then - continue - fi - - apt-get install "$pkg" + apk --no-cache --update add "$pkg" done - - # Remove apt lists - rm -rf /var/lib/apt/lists/* } From 76d8d9806b7da34457ead134c108c33a73816ecd Mon Sep 17 00:00:00 2001 From: Guy Date: Mon, 29 Jan 2018 23:19:06 +0200 Subject: [PATCH 7/8] Updated Dockerfile with maintainer and contributors Updated setup.rst with information on upgrade path if coming from an earlier version of docker-compose images --- Dockerfile | 4 ++++ docs/setup.rst | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2144d8c9..11a83e2b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ FROM alpine:3.7 +LABEL maintainer="The Paperless Project https://github.com/danielquinn/paperless" \ + contributors="Guy Addadi , Pit Kleyersburg , \ + Sven Fischer " + # Copy application COPY requirements.txt /usr/src/paperless/ COPY src/ /usr/src/paperless/src/ diff --git a/docs/setup.rst b/docs/setup.rst index 6c0522b8e..a2f2564be 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -175,7 +175,7 @@ Docker Method modified versions of the configuration files. 4. Modify ``docker-compose.yml`` to your preferences, following the instructions in comments in the file. The only change that is a hard - requirement is to specify where the consumption directory should mount. + requirement is to specify where the consumption directory should mount. [#docker-compose]_ 5. Modify ``docker-compose.env`` and adapt the following environment variables: ``PAPERLESS_PASSPHRASE`` @@ -192,7 +192,7 @@ Docker Method default English, set this parameter to a space separated list of three-letter language-codes after `ISO 639-2/T`_. For a list of available languages -- including their three letter codes -- see the - `Debian packagelist`_. + `Alpine packagelist`_. ``USERMAP_UID`` and ``USERMAP_GID`` If you want to mount the consumption volume (directory ``/consume`` within @@ -282,12 +282,16 @@ Docker Method .. _Docker: https://www.docker.com/ .. _docker-compose: https://docs.docker.com/compose/install/ .. _ISO 639-2/T: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes -.. _Debian packagelist: https://packages.debian.org/search?suite=jessie&searchon=names&keywords=tesseract-ocr- +.. _Alpine packagelist: https://pkgs.alpinelinux.org/packages?name=tesseract-ocr-data*&arch=x86_64 .. [#compose] You of course don't have to use docker-compose, but it simplifies deployment immensely. If you know your way around Docker, feel free to tinker around without using compose! +.. [#docker-compose] If you're upgrading your docker-compse images from version + 1.1.0 or earlier, you might need to change in the ``docker-compose.yml` + file the ``image: pitkley/paperless`` in both the ``webserver`` and ``consumer`` + sections to ``build: ./`` as per the newer ``docker-compose.yml.example`` file .. _setup-permanent: From 902b66bd823746ff777c908a6735e1d61e4bd03a Mon Sep 17 00:00:00 2001 From: Guy Date: Mon, 29 Jan 2018 23:41:52 +0200 Subject: [PATCH 8/8] fixing typos and rst syntax --- docs/setup.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/setup.rst b/docs/setup.rst index a2f2564be..7fad393ba 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -175,7 +175,7 @@ Docker Method modified versions of the configuration files. 4. Modify ``docker-compose.yml`` to your preferences, following the instructions in comments in the file. The only change that is a hard - requirement is to specify where the consumption directory should mount. [#docker-compose]_ + requirement is to specify where the consumption directory should mount. _. [#docker-compose.yml]_ 5. Modify ``docker-compose.env`` and adapt the following environment variables: ``PAPERLESS_PASSPHRASE`` @@ -288,9 +288,9 @@ Docker Method simplifies deployment immensely. If you know your way around Docker, feel free to tinker around without using compose! -.. [#docker-compose] If you're upgrading your docker-compse images from version - 1.1.0 or earlier, you might need to change in the ``docker-compose.yml` - file the ``image: pitkley/paperless`` in both the ``webserver`` and ``consumer`` +.. [#docker-compose.yml] If you're upgrading your docker-compse images from version + 1.1.0 or earlier, you might need to change in the ``docker-compose.yml`` + file the ``image: pitkley/paperless`` directive in both the ``webserver`` and ``consumer`` sections to ``build: ./`` as per the newer ``docker-compose.yml.example`` file .. _setup-permanent: