improved docker startup time

This commit is contained in:
jonaswinkler 2021-05-19 22:26:51 +02:00
parent c72791bd21
commit 3b912a0de1

View File

@ -4,37 +4,41 @@ set -e
# Source: https://github.com/sameersbn/docker-gitlab/ # Source: https://github.com/sameersbn/docker-gitlab/
map_uidgid() { map_uidgid() {
USERMAP_ORIG_UID=$(id -u paperless) USERMAP_ORIG_UID=$(id -u paperless)
USERMAP_ORIG_GID=$(id -g paperless) USERMAP_ORIG_GID=$(id -g paperless)
USERMAP_NEW_UID=${USERMAP_UID:-$USERMAP_ORIG_UID} USERMAP_NEW_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
USERMAP_NEW_GID=${USERMAP_GID:-${USERMAP_ORIG_GID:-$USERMAP_NEW_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 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" echo "Mapping UID and GID for paperless:paperless to $USERMAP_NEW_UID:$USERMAP_NEW_GID"
usermod -u "${USERMAP_NEW_UID}" paperless usermod -u "${USERMAP_NEW_UID}" paperless
groupmod -o -g "${USERMAP_NEW_GID}" paperless groupmod -o -g "${USERMAP_NEW_GID}" paperless
fi fi
} }
initialize() { initialize() {
map_uidgid map_uidgid
for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do for dir in export data data/index media media/documents media/documents/originals media/documents/thumbnails; do
if [[ ! -d "../$dir" ]] if [[ ! -d "../$dir" ]]; then
then echo "Creating directory ../$dir"
echo "creating directory ../$dir"
mkdir ../$dir mkdir ../$dir
fi fi
done done
echo "creating directory /tmp/paperless" echo "Creating directory /tmp/paperless"
mkdir -p /tmp/paperless mkdir -p /tmp/paperless
set +e set +e
chown -R paperless:paperless ../ CURRENT_USER=$(stat -c '%U' ../)
CURRENT_GROUP=$(stat -c '%G' ../)
if [[ ${CURRENT_USER} != "paperless" || ${CURRENT_GROUP} != "paperless" ]] ; then
echo "Adjusting permissions of paperless files. This may take a while."
chown -R paperless:paperless ../
fi
chown -R paperless:paperless /tmp/paperless chown -R paperless:paperless /tmp/paperless
set -e set -e
gosu paperless /sbin/docker-prepare.sh gosu paperless /sbin/docker-prepare.sh
} }
install_languages() { install_languages() {
@ -50,35 +54,35 @@ install_languages() {
apt-get update apt-get update
for lang in "${langs[@]}"; do for lang in "${langs[@]}"; do
pkg="tesseract-ocr-$lang" pkg="tesseract-ocr-$lang"
# English is installed by default # English is installed by default
#if [[ "$lang" == "eng" ]]; then #if [[ "$lang" == "eng" ]]; then
# continue # continue
#fi #fi
if dpkg -s $pkg &> /dev/null; then if dpkg -s $pkg &>/dev/null; then
echo "package $pkg already installed!" echo "Package $pkg already installed!"
continue continue
fi fi
if ! apt-cache show $pkg &> /dev/null; then if ! apt-cache show $pkg &>/dev/null; then
echo "package $pkg not found! :(" echo "Package $pkg not found! :("
continue continue
fi fi
echo "Installing package $pkg..." echo "Installing package $pkg..."
if ! apt-get -y install "$pkg" &> /dev/null; then if ! apt-get -y install "$pkg" &>/dev/null; then
echo "Could not install $pkg" echo "Could not install $pkg"
exit 1 exit 1
fi fi
done done
} }
echo "Paperless-ng docker container starting..." echo "Paperless-ng docker container starting..."
# Install additional languages if specified # Install additional languages if specified
if [[ ! -z "$PAPERLESS_OCR_LANGUAGES" ]]; then if [[ ! -z "$PAPERLESS_OCR_LANGUAGES" ]]; then
install_languages "$PAPERLESS_OCR_LANGUAGES" install_languages "$PAPERLESS_OCR_LANGUAGES"
fi fi
initialize initialize