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
|
2020-10-29 00:46:57 +01:00
|
|
|
|
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 -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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialize() {
|
2020-10-29 00:46:57 +01:00
|
|
|
map_uidgid
|
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
|
|
|
|
2020-10-29 14:30:15 +01:00
|
|
|
for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do
|
|
|
|
|
if [[ ! -d "../$dir" ]]
|
2020-10-29 00:46:57 +01:00
|
|
|
then
|
2020-10-29 14:30:15 +01:00
|
|
|
echo "creating directory ../$dir"
|
|
|
|
|
mkdir ../$dir
|
2020-10-29 00:46:57 +01:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
2021-01-21 01:02:41 +01:00
|
|
|
echo "creating directory /tmp/paperless"
|
|
|
|
|
mkdir -p /tmp/paperless
|
|
|
|
|
|
2021-04-08 00:03:55 +01:00
|
|
|
set +e
|
2020-10-29 00:46:57 +01:00
|
|
|
chown -R paperless:paperless ../
|
2021-01-21 01:02:41 +01:00
|
|
|
chown -R paperless:paperless /tmp/paperless
|
2021-04-08 00:03:55 +01:00
|
|
|
set -e
|
2020-10-29 00:46:57 +01:00
|
|
|
|
2021-04-26 19:06:30 -05:00
|
|
|
gosu paperless /sbin/docker-prepare.sh
|
2020-10-29 00:46:57 +01:00
|
|
|
}
|
2017-12-20 16:17:58 +02:00
|
|
|
|
2020-10-29 00:46:57 +01:00
|
|
|
install_languages() {
|
2021-01-13 19:58:09 +01:00
|
|
|
echo "Installing languages..."
|
|
|
|
|
|
2020-10-29 00:46:57 +01:00
|
|
|
local langs="$1"
|
|
|
|
|
read -ra langs <<<"$langs"
|
|
|
|
|
|
|
|
|
|
# Check that it is not empty
|
|
|
|
|
if [ ${#langs[@]} -eq 0 ]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
apt-get update
|
|
|
|
|
|
|
|
|
|
for lang in "${langs[@]}"; do
|
|
|
|
|
pkg="tesseract-ocr-$lang"
|
2017-12-20 16:17:58 +02:00
|
|
|
# English is installed by default
|
2020-10-29 00:46:57 +01:00
|
|
|
#if [[ "$lang" == "eng" ]]; then
|
|
|
|
|
# continue
|
|
|
|
|
#fi
|
2018-02-24 11:20:00 +01:00
|
|
|
|
2020-10-29 00:46:57 +01:00
|
|
|
if dpkg -s $pkg &> /dev/null; then
|
|
|
|
|
echo "package $pkg already installed!"
|
|
|
|
|
continue
|
2017-12-20 16:17:58 +02:00
|
|
|
fi
|
2020-10-29 00:46:57 +01:00
|
|
|
|
|
|
|
|
if ! apt-cache show $pkg &> /dev/null; then
|
|
|
|
|
echo "package $pkg not found! :("
|
|
|
|
|
continue
|
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
|
|
|
|
|
|
2020-10-29 00:46:57 +01:00
|
|
|
echo "Installing package $pkg..."
|
|
|
|
|
if ! apt-get -y install "$pkg" &> /dev/null; then
|
|
|
|
|
echo "Could not install $pkg"
|
|
|
|
|
exit 1
|
|
|
|
|
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
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 19:58:09 +01:00
|
|
|
echo "Paperless-ng docker container starting..."
|
|
|
|
|
|
2020-11-01 23:01:36 +01:00
|
|
|
# Install additional languages if specified
|
|
|
|
|
if [[ ! -z "$PAPERLESS_OCR_LANGUAGES" ]]; then
|
|
|
|
|
install_languages "$PAPERLESS_OCR_LANGUAGES"
|
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
|
|
|
|
|
|
2020-12-09 23:45:53 +01:00
|
|
|
initialize
|
|
|
|
|
|
2020-11-13 18:42:32 +01:00
|
|
|
if [[ "$1" != "/"* ]]; then
|
2021-01-13 19:58:09 +01:00
|
|
|
echo Executing management command "$@"
|
2021-04-26 19:06:30 -05:00
|
|
|
exec gosu paperless python3 manage.py "$@"
|
2020-11-13 18:42:32 +01:00
|
|
|
else
|
2021-01-13 19:58:09 +01:00
|
|
|
echo Executing "$@"
|
2020-11-13 18:42:32 +01:00
|
|
|
exec "$@"
|
|
|
|
|
fi
|