Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from pitkley/feature/dockerfile
Browse files Browse the repository at this point in the history
Add Dockerfile for application and documentation
  • Loading branch information
danielquinn committed Feb 18, 2016
2 parents 57bcb88 + 724afa5 commit 99be40a
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ db.sqlite3
# Other stuff that doesn't belong
virtualenv
.vagrant
docker-compose.yml

# Used for development
scripts/import-for-development
Expand Down
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM python:3.5.1
MAINTAINER Pit Kleyersburg <[email protected]>

# Install dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
sudo \
tesseract-ocr tesseract-ocr-eng imagemagick ghostscript \
&& 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

# Copy application
RUN mkdir -p /usr/src/paperless/src
COPY src/ /usr/src/paperless/src/

# Set consumption directory
ENV PAPERLESS_CONSUME /consume
RUN mkdir -p $PAPERLESS_CONSUME

# Migrate database
WORKDIR /usr/src/paperless/src
RUN mkdir /usr/src/paperless/data
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

# Setup entrypoint
COPY scripts/docker-entrypoint.sh /sbin/docker-entrypoint.sh
RUN chmod 755 /sbin/docker-entrypoint.sh

# Mount volumes
VOLUME ["/usr/src/paperless/data", "/usr/src/paperless/media", "/consume"]

ENTRYPOINT ["/sbin/docker-entrypoint.sh"]
CMD ["--help"]
15 changes: 15 additions & 0 deletions docker-compose.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Environment variables to set for Paperless
# Commented out variables will be replaced by a default within Paperless.

# Passphrase Paperless uses to encrypt and decrypt your documents
PAPERLESS_PASSPHRASE=CHANGE_ME

# The amount of threads to use for text recognition
# PAPERLESS_OCR_THREADS=4

# Additional languages to install for text recognition
# PAPERLESS_OCR_LANGUAGES=deu ita

# You can change the default user and group id to a custom one
# USERMAP_UID=1000
# USERMAP_GID=1000
31 changes: 31 additions & 0 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '2'

services:
webserver:
image: paperless
ports:
# You can adapt the port you want Paperless to listen on by
# modifying the part before the `:`.
- "8000:8000"
volumes:
- paperless-data:/usr/src/paperless/data
- paperless-media:/usr/src/paperless/media
env_file: docker-compose.env
environment:
- PAPERLESS_OCR_LANGUAGES=
command: ["runserver", "0.0.0.0:8000"]

consumer:
image: paperless
volumes:
- paperless-data:/usr/src/paperless/data
- paperless-media:/usr/src/paperless/media
# You have to adapt the local path you want the consumption
# directory to mount to by modifying the part before the ':'.
- /path/to/arbitrary/place:/consume
env_file: docker-compose.env
command: ["document_consumer"]

volumes:
paperless-data:
paperless-media:
18 changes: 18 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.5.1
MAINTAINER Pit Kleyersburg <[email protected]>

# Install Sphinx and Pygments
RUN pip install Sphinx Pygments

# Setup directories, copy data
RUN mkdir /build
COPY . /build
WORKDIR /build/docs

# Build documentation
RUN make html

# Start webserver
WORKDIR /build/docs/_build/html
EXPOSE 8000/tcp
CMD ["python3", "-m", "http.server"]
95 changes: 95 additions & 0 deletions docs/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ as part of the update:
Note that it's possible (even likely) that while ``git pull`` may update some
files, the ``migrate`` step may not update anything. This is totally normal.

If you are :ref:`using Docker <setup-installation-docker>` the update process
requires only one additional step:

.. code-block:: shell-session
$ cd /path/to/project
$ git pull
$ docker build -t paperless .
$ docker-compose up -d
$ docker-compose run --rm webserver migrate
If ``git pull`` doesn't report any changes, there is no need to continue with
the remaining steps.


.. _migrating-backup:

Expand All @@ -53,6 +67,65 @@ with Django's ``dumpdata`` command, which produces JSON output.
$ ./manage.py document_export /path/to/arbitrary/place/
$ ./manage.py dumpdata documents.Tag > /path/to/arbitrary/place/tags.json
If you are :ref:`using Docker <setup-installation-docker>`, exporting your tags
as JSON is almost as easy:

.. code-block:: shell-session
$ docker-compose run --rm webserver dumpdata documents.Tag > /path/to/arbitrary/place/tags.json
Exporting the documents though is a little more involved, since docker-compose
doesn't support mounting additional volumes with the ``run`` command. You have
three general options:

1. Use the consumption directory if you happen to already have it mounted to a
host directory.

.. code-block:: console
$ # Stop the consumer so that it doesn't consume the exported documents
$ docker-compose stop consumer
$ # Export into the consumption directory
$ docker-compose run --rm consumer document_exporter /consume
2. Add another volume to ``docker-compose.yml`` for exports and use
``docker-compose run``:

.. code-block:: diff
diff --git a/docker-compose.yml b/docker-compose.yml
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -17,9 +18,8 @@ services:
volumes:
- paperless-data:/usr/src/paperless/data
- paperless-media:/usr/src/paperless/media
- /consume
+ - /path/to/arbitrary/place:/export
.. code-block:: shell-session
$ docker-compose run --rm consumer document_exporter /export
3. Use ``docker run`` directly, supplying the necessary commandline options:

.. code-block:: shell-session
$ # Identify your containers
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------
paperless_consumer_1 /sbin/docker-entrypoint.sh ... Exit 0
paperless_webserver_1 /sbin/docker-entrypoint.sh ... Exit 0
$ # Make sure to replace your passphrase and remove or adapt the id mapping
$ docker run --rm \
--volumes-from paperless_data_1 \
--volume /path/to/arbitrary/place:/export \
-e PAPERLESS_PASSPHRASE=YOUR_PASSPHRASE \
-e USERMAP_UID=1000 -e USERMAP_GID=1000 \
paperless document_exporter /export
.. _migrating-restoring:

Expand All @@ -77,3 +150,25 @@ exported documents into the consumption directory and start up the consumer.
$ cp /path/to/exported/docs/* /path/to/consumption/dir/
$ ./manage.py document_consumer
Importing your data if you are :ref:`using Docker <setup-installation-docker>`
is almost as simple:

.. code-block:: shell-session
$ # Stop and remove your current containers
$ docker-compose stop
$ docker-compose rm -f
$ # Recreate them, add the superuser
$ docker-compose up -d
$ docker-compose run --rm webserver createsuperuser
$ # Load the tags
$ cat /path/to/arbitrary/place/tags.json | docker-compose run --rm webserver loaddata_stdin -
$ # Load your exported documents into the consumption directory
$ # (How you do this highly depends on how you have set this up)
$ cp /path/to/exported/docs/* /path/to/mounted/consumption/dir/
After loading the documents into the consumption directory the consumer will
immediately start consuming the documents.
13 changes: 13 additions & 0 deletions docs/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,16 @@ you'd like to generate your own docs locally, you'll need to:
$ pip install sphinx
and then cd into the ``docs`` directory and type ``make html``.

If you are using Docker, you can use the following commands to build the
documentation and run a webserver serving it on `port 8001`_:

.. code:: bash
$ pwd
/path/to/paperless
$ docker build -t paperless:docs -f docs/Dockerfile .
$ docker run --rm -it -p "8001:8000" paperless:docs
.. _port 8001: http://127.0.0.1:8001
Loading

0 comments on commit 99be40a

Please sign in to comment.