diff --git a/Dockerfile b/Dockerfile index f661012b5..11a83e2b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,47 @@ -FROM python:3.5 -MAINTAINER Pit Kleyersburg +FROM alpine:3.7 -# 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/* - -# Install python dependencies -RUN mkdir -p /usr/src/paperless -WORKDIR /usr/src/paperless -COPY requirements.txt /usr/src/paperless/ -RUN pip install --no-cache-dir -r requirements.txt +LABEL maintainer="The Paperless Project https://github.com/danielquinn/paperless" \ + contributors="Guy Addadi , Pit Kleyersburg , \ + Sven Fischer " # Copy application -RUN mkdir -p /usr/src/paperless/src -RUN mkdir -p /usr/src/paperless/data -RUN mkdir -p /usr/src/paperless/media +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 consumption directory -ENV PAPERLESS_CONSUMPTION_DIR /consume -RUN mkdir -p $PAPERLESS_CONSUMPTION_DIR - -# Migrate database -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 \ - && chown -Rh paperless:paperless /usr/src/paperless - -# Set export directory -ENV PAPERLESS_EXPORT_DIR /export -RUN mkdir -p $PAPERLESS_EXPORT_DIR - -# Setup entrypoint COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh -RUN chmod 755 /sbin/docker-entrypoint.sh -# Mount volumes +# 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 + python3 -m ensurepip && \ + rm -r /usr/lib/python*/ensurepip && \ + cd /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 + ./src/manage.py migrate && \ +# Create user + 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 + chmod 755 /sbin/docker-entrypoint.sh + +WORKDIR /usr/src/paperless/src +# Mount volumes and set Entrypoint VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/consume", "/export"] - ENTRYPOINT ["/sbin/docker-entrypoint.sh"] CMD ["--help"] 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 diff --git a/docs/setup.rst b/docs/setup.rst index 6c0522b8e..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. + 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`` @@ -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.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: 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/* }