From 3f9ea7b97164770bb7db3e844db4f77800e02e3b Mon Sep 17 00:00:00 2001 From: Georgi Todorov Date: Mon, 5 Feb 2018 18:23:35 -0500 Subject: [PATCH] Add a dependency link between two containers and change the way Django migrations are done. Provide example for auto-starting the containers --- Dockerfile | 2 -- docker-compose.yml.example | 14 +++++++++++++- docs/migrating.rst | 3 +-- scripts/docker-entrypoint.sh | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f60ccd073..a7e1c43cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,8 +30,6 @@ RUN apk --no-cache --update add \ 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 && \ diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 6920836ba..245ed83c4 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -1,12 +1,19 @@ -version: '2' +version: '2.1' services: webserver: build: ./ + # uncomment the following line to start automatically on system boot + # restart: always ports: # You can adapt the port you want Paperless to listen on by # modifying the part before the `:`. - "8000:8000" + healthcheck: + test: ["CMD", "curl" , "-f", "http://localhost:8000"] + interval: 30s + timeout: 10s + retries: 5 volumes: - data:/usr/src/paperless/data - media:/usr/src/paperless/media @@ -21,6 +28,11 @@ services: consumer: build: ./ + # uncomment the following line to start automatically on system boot + # restart: always + depends_on: + webserver: + condition: service_healthy volumes: - data:/usr/src/paperless/data - media:/usr/src/paperless/media diff --git a/docs/migrating.rst b/docs/migrating.rst index 55ed9ce8a..4d20f4714 100644 --- a/docs/migrating.rst +++ b/docs/migrating.rst @@ -94,7 +94,7 @@ You may want to take a look at the ``paperless.conf.example`` file to see if there's anything new in there compared to what you've got int ``/etc``. If you are :ref:`using Docker ` the update process -requires only one additional step: +is similar: .. code-block:: shell-session @@ -102,7 +102,6 @@ requires only one additional step: $ 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. diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index f9fde70c8..f7be92fa9 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -42,9 +42,24 @@ set_permissions() { chown -Rh paperless:paperless /usr/src/paperless } +migrations() { + # A simple lock file in case other containers use this startup + LOCKFILE="/usr/src/paperless/data/db.sqlite3.migration" + + set -o noclobber + # check for and create lock file in one command + (> ${LOCKFILE}) &> /dev/null + if [ $? -eq 0 ] + then + sudo -HEu paperless "/usr/src/paperless/src/manage.py" "migrate" + rm ${LOCKFILE} + fi +} + initialize() { map_uidgid set_permissions + migrations } install_languages() {