From dd7c5da256594a22534611df1b7042f1ec2b916f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 8 Apr 2021 00:03:55 +0100 Subject: [PATCH] docker-entrypoint.sh: split non-root tasks into docker-prepare.sh --- Dockerfile | 1 + docker/docker-entrypoint.sh | 75 +++---------------------------------- docker/docker-prepare.sh | 68 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 70 deletions(-) create mode 100755 docker/docker-prepare.sh diff --git a/Dockerfile b/Dockerfile index e41aeb7ac..332a56aba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,6 +78,7 @@ RUN cd docker \ && mkdir /var/log/supervisord /var/run/supervisord \ && cp supervisord.conf /etc/supervisord.conf \ && cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \ + && cp docker-prepare.sh /sbin/docker-prepare.sh \ && chmod 755 /sbin/docker-entrypoint.sh \ && chmod +x install_management_commands.sh \ && ./install_management_commands.sh \ diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index cf6129438..5b0389b96 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -15,70 +15,6 @@ map_uidgid() { fi } - -wait_for_postgres() { - attempt_num=1 - max_attempts=5 - - echo "Waiting for PostgreSQL to start..." - - host="${PAPERLESS_DBHOST}" - port="${PAPERLESS_DBPORT}" - - if [[ -z $port ]] ; - then - port="5432" - fi - - while !/usr/src/paperless/data/migration_lock - -} - -search_index() { - index_version=1 - index_version_file=/usr/src/paperless/data/.index_version - - if [[ (! -f "$index_version_file") || $(< $index_version_file) != "$index_version" ]]; then - echo "Search index out of date. Updating..." - sudo -HEu paperless python3 manage.py document_index reindex - echo $index_version | sudo -HEu paperless tee $index_version_file >/dev/null - fi -} - initialize() { map_uidgid @@ -92,13 +28,13 @@ initialize() { echo "creating directory /tmp/paperless" mkdir -p /tmp/paperless - + + set +e chown -R paperless:paperless ../ chown -R paperless:paperless /tmp/paperless - - migrations - - search_index + set -e + + sudo -HEu paperless /sbin/docker-prepare.sh } install_languages() { @@ -154,4 +90,3 @@ else echo Executing "$@" exec "$@" fi - diff --git a/docker/docker-prepare.sh b/docker/docker-prepare.sh new file mode 100755 index 000000000..fd32d0a7e --- /dev/null +++ b/docker/docker-prepare.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +wait_for_postgres() { + attempt_num=1 + max_attempts=5 + + echo "Waiting for PostgreSQL to start..." + + host="${PAPERLESS_DBHOST}" + port="${PAPERLESS_DBPORT}" + + if [[ -z $port ]] ; + then + port="5432" + fi + + while !/usr/src/paperless/data/migration_lock +} + +search_index() { + index_version=1 + index_version_file=/usr/src/paperless/data/.index_version + + if [[ (! -f "$index_version_file") || $(< $index_version_file) != "$index_version" ]]; then + echo "Search index out of date. Updating..." + python3 manage.py document_index reindex + echo $index_version | sudo -HEu paperless tee $index_version_file >/dev/null + fi +} + +do_work() { + migrations; + + search_index; +} + +do_work;