Skip to content

Commit

Permalink
paperless postgres fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-garavini committed Jan 28, 2025
1 parent 6f9f10b commit 6ecdb88
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 4 additions & 2 deletions paperless/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ENV PAPERLESS_DATA_DIR="/config/paperless" \
PG_MAJOR=16

# Postgres & Redis install
RUN apt-get update; \
RUN mkdir /docker-entrypoint-initdb.d; \
apt-get update; \
apt-get install -y lsb-release; \
install -d /usr/share/postgresql-common/pgdg; \
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc; \
Expand All @@ -34,8 +35,9 @@ RUN apt-get update; \
netcat-traditional \
curl \
gpg \
postgresql-client-common \
postgresql-client-$PG_MAJOR \
postgresql-$PG_MAJOR \
postgresql-common \
redis-server; \
apt-get autoclean -y; \
rm -rf \
Expand Down
2 changes: 1 addition & 1 deletion paperless/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Paperless
version: "2.14.5-v3"
version: "2.14.5-v4"
slug: paperless
codenotary: [email protected]
description: Document management system that transforms your physical documents into a searchable online archive
Expand Down
36 changes: 36 additions & 0 deletions paperless/rootfs/usr/bin/postgres-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,38 @@ docker_verify_minimum_env() {
fi
}

# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
# process initializer files, based on file extensions and permissions
docker_process_init_files() {
# psql here for backwards compatibility "${psql[@]}"
psql=( docker_process_sql )

printf '\n'
local f
for f; do
case "$f" in
*.sh)
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then
printf '%s: running %s\n' "$0" "$f"
"$f"
else
printf '%s: sourcing %s\n' "$0" "$f"
. "$f"
fi
;;
*.sql) printf '%s: running %s\n' "$0" "$f"; docker_process_sql -f "$f"; printf '\n' ;;
*.sql.gz) printf '%s: running %s\n' "$0" "$f"; gunzip -c "$f" | docker_process_sql; printf '\n' ;;
*.sql.xz) printf '%s: running %s\n' "$0" "$f"; xzcat "$f" | docker_process_sql; printf '\n' ;;
*.sql.zst) printf '%s: running %s\n' "$0" "$f"; zstd -dc "$f" | docker_process_sql; printf '\n' ;;
*) printf '%s: ignoring %s\n' "$0" "$f" ;;
esac
printf '\n'
done
}

# Execute sql script, passed via stdin (or -f flag of pqsl)
# usage: docker_process_sql [psql-cli-args]
# ie: docker_process_sql --dbname=mydb <<<'INSERT ...'
Expand Down Expand Up @@ -285,6 +317,9 @@ _main() {
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env

# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

docker_init_database_dir
pg_setup_hba_conf "$@"

Expand All @@ -294,6 +329,7 @@ _main() {
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
Expand Down

0 comments on commit 6ecdb88

Please sign in to comment.