Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Source: https://github.com/sameersbn/docker-gitlab/
|
|
|
|
|
map_uidgid() {
|
|
|
|
|
USERMAP_ORIG_UID=$(id -u paperless)
|
2018-02-24 11:20:00 +01:00
|
|
|
USERMAP_ORIG_GID=$(id -g paperless)
|
|
|
|
|
USERMAP_NEW_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
|
|
|
|
|
USERMAP_NEW_GID=${USERMAP_GID:-${USERMAP_ORIG_GID:-$USERMAP_NEW_UID}}
|
|
|
|
|
if [[ ${USERMAP_NEW_UID} != "${USERMAP_ORIG_UID}" || ${USERMAP_NEW_GID} != "${USERMAP_ORIG_GID}" ]]; then
|
|
|
|
|
echo "Mapping UID and GID for paperless:paperless to $USERMAP_NEW_UID:$USERMAP_NEW_GID"
|
|
|
|
|
usermod -u "${USERMAP_NEW_UID}" paperless
|
2020-01-05 18:20:03 -08:00
|
|
|
groupmod -o -g "${USERMAP_NEW_GID}" paperless
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_permissions() {
|
2017-05-02 19:06:01 +02:00
|
|
|
# Set permissions for consumption and export directory
|
2017-05-02 19:48:28 +02:00
|
|
|
for dir in PAPERLESS_CONSUMPTION_DIR PAPERLESS_EXPORT_DIR; do
|
|
|
|
|
# Extract the name of the current directory from $dir for the error message
|
|
|
|
|
cur_dir_name=$(echo "$dir" | awk -F'_' '{ print tolower($2); }')
|
|
|
|
|
chgrp paperless "${!dir}" || {
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "Changing group of ${cur_dir_name} directory:"
|
2017-05-02 19:48:28 +02:00
|
|
|
echo " ${!dir}"
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "failed."
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Either try to set it on your host-mounted directory"
|
2017-10-31 15:30:33 +01:00
|
|
|
echo "directly, or make sure that the directory has \`g+wx\`"
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "permissions and the files in it at least \`o+r\`."
|
|
|
|
|
} >&2
|
2017-10-31 15:30:33 +01:00
|
|
|
chmod g+wx "${!dir}" || {
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "Changing group permissions of ${cur_dir_name} directory:"
|
2017-05-02 19:48:28 +02:00
|
|
|
echo " ${!dir}"
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "failed."
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Either try to set it on your host-mounted directory"
|
2017-10-31 15:30:33 +01:00
|
|
|
echo "directly, or make sure that the directory has \`g+wx\`"
|
2017-05-02 19:06:01 +02:00
|
|
|
echo "permissions and the files in it at least \`o+r\`."
|
|
|
|
|
} >&2
|
|
|
|
|
done
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
# Set permissions for application directory
|
|
|
|
|
chown -Rh paperless:paperless /usr/src/paperless
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 18:23:35 -05:00
|
|
|
migrations() {
|
|
|
|
|
# A simple lock file in case other containers use this startup
|
|
|
|
|
LOCKFILE="/usr/src/paperless/data/db.sqlite3.migration"
|
|
|
|
|
|
|
|
|
|
# check for and create lock file in one command
|
2018-05-15 19:34:21 +02:00
|
|
|
if (set -o noclobber; echo "$$" > "${LOCKFILE}") 2> /dev/null
|
2018-02-05 18:23:35 -05:00
|
|
|
then
|
2018-05-15 19:34:21 +02:00
|
|
|
trap 'rm -f "${LOCKFILE}"; exit $?' INT TERM EXIT
|
2018-02-05 18:23:35 -05:00
|
|
|
sudo -HEu paperless "/usr/src/paperless/src/manage.py" "migrate"
|
|
|
|
|
rm ${LOCKFILE}
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
initialize() {
|
|
|
|
|
map_uidgid
|
|
|
|
|
set_permissions
|
2018-02-05 18:23:35 -05:00
|
|
|
migrations
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_languages() {
|
|
|
|
|
local langs="$1"
|
|
|
|
|
read -ra langs <<<"$langs"
|
|
|
|
|
|
|
|
|
|
# Check that it is not empty
|
|
|
|
|
if [ ${#langs[@]} -eq 0 ]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Loop over languages to be installed
|
|
|
|
|
for lang in "${langs[@]}"; do
|
2017-12-20 16:17:58 +02:00
|
|
|
pkg="tesseract-ocr-data-$lang"
|
|
|
|
|
|
|
|
|
|
# English is installed by default
|
2018-12-30 17:32:17 +00:00
|
|
|
if [[ "$lang" == "eng" ]]; then
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
continue
|
|
|
|
|
fi
|
2018-02-24 11:20:00 +01:00
|
|
|
|
2017-12-20 16:17:58 +02:00
|
|
|
if apk info -e "$pkg" > /dev/null 2>&1; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
2019-03-27 22:22:20 +01:00
|
|
|
if ! apk --no-cache info "$pkg" > /dev/null 2>&1; then
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
2017-12-20 16:17:58 +02:00
|
|
|
apk --no-cache --update add "$pkg"
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$1" != "/"* ]]; then
|
|
|
|
|
initialize
|
|
|
|
|
|
|
|
|
|
# Install additional languages if specified
|
2018-12-30 17:32:17 +00:00
|
|
|
if [[ ! -z "$PAPERLESS_OCR_LANGUAGES" ]]; then
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
install_languages "$PAPERLESS_OCR_LANGUAGES"
|
|
|
|
|
fi
|
|
|
|
|
|
2019-08-09 00:44:41 +02:00
|
|
|
if [[ "$1" = "gunicorn" ]]; then
|
2019-09-21 15:45:10 +02:00
|
|
|
shift
|
2019-11-03 18:24:03 +01:00
|
|
|
EXTRA_PARAMS=""
|
|
|
|
|
SSL_KEY_PATH="/usr/src/paperless/data/ssl.key"
|
|
|
|
|
SSL_CERT_PATH="/usr/src/paperless/data/ssl.cert"
|
2019-11-03 20:14:17 +01:00
|
|
|
if [ "${PAPERLESS_USE_SSL}" = "true" ]; then
|
|
|
|
|
if [ -f "${SSL_KEY_PATH}" ] && [ -f "${SSL_CERT_PATH}" ]; then
|
|
|
|
|
EXTRA_PARAMS="--certfile=${SSL_CERT_PATH} --keyfile=${SSL_KEY_PATH}"
|
|
|
|
|
else
|
|
|
|
|
echo "Error: Could not find certfile in ${SSL_CERT_PATH} or keyfile in ${SSL_KEY_PATH}, but \$PAPERLESS_USE_SSL is true. Starting without SSL enabled."
|
|
|
|
|
fi
|
2019-11-03 18:24:03 +01:00
|
|
|
fi
|
2019-08-09 00:44:41 +02:00
|
|
|
cd /usr/src/paperless/src/ && \
|
2019-11-03 18:24:03 +01:00
|
|
|
exec sudo -HEu paperless /usr/bin/gunicorn -c /usr/src/paperless/gunicorn.conf ${EXTRA_PARAMS} "$@" paperless.wsgi
|
2019-08-09 00:44:41 +02:00
|
|
|
else
|
|
|
|
|
exec sudo -HEu paperless "/usr/src/paperless/src/manage.py" "$@"
|
|
|
|
|
fi
|
Add Dockerfile for application and documentation
This commit adds a `Dockerfile` to the root of the project, accompanied
by a `docker-compose.yml.example` for simplified deployment. The
`Dockerfile` is agnostic to whether it will be the webserver, the
consumer, or if it is run for a one-off command (i.e. creation of a
superuser, migration of the database, document export, ...).
The containers entrypoint is the `scripts/docker-entrypoint.sh` script.
This script verifies that the required permissions are set, remaps the
default users and/or groups id if required and installs additional
languages if the user wishes to.
After initialization, it analyzes the command the user supplied:
- If the command starts with a slash, it is expected that the user
wants to execute a binary file and the command will be executed
without further intervention. (Using `exec` to effectively replace
the started shell-script and not have any reaping-issues.)
- If the command does not start with a slash, the command will be
passed directly to the `manage.py` script without further
modification. (Again using `exec`.)
The default command is set to `--help`.
If the user wants to execute a command that is not meant for `manage.py`
but doesn't start with a slash, the Docker `--entrypoint` parameter can
be used to circumvent the mechanics of `docker-entrypoint.sh`.
Further information can be found in `docs/setup.rst` and in
`docs/migrating.rst`.
For additional convenience, a `Dockerfile` has been added to the `docs/`
directory which allows for easy building and serving of the
documentation. This is documented in `docs/requirements.rst`.
2016-02-17 18:45:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
exec "$@"
|
|
|
|
|
|