Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Default login is `wallabag:wallabag`.
- `-e MYSQL_ROOT_PASSWORD=...` (needed for the mariadb container to initialise and for the entrypoint in the wallabag container to create a database and user if its not there)
- `-e POSTGRES_PASSWORD=...` (needed for the postgres container to initialise and for the entrypoint in the wallabag container to create a database and user if not there)
- `-e POSTGRES_USER=...` (needed for the posgres container to initialise and for the entrypoint in the wallabag container to create a database and user if not there)
- `-e POSTGRES_DATABASE_NAME=...` (optional: psql always connects to the database that matches the user name. this allows using a different name from user)
- `-e SYMFONY__ENV__DATABASE_DRIVER=...` (defaults to "pdo_sqlite", this sets the database driver to use)
- `-e SYMFONY__ENV__DATABASE_HOST=...` (defaults to "127.0.0.1", if use mysql this should be the name of the mariadb container)
- `-e SYMFONY__ENV__DATABASE_PORT=...` (port of the database host)
Expand Down
10 changes: 10 additions & 0 deletions root/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ provisioner() {

# Configure Postgres database
if [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_pgsql" ] && [ "$POPULATE_DATABASE" = "True" ] && [ "$POSTGRES_PASSWORD" != "" ] ; then
if [ -z "$POSTGRES_DATABASE_NAME" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already rely on POSTGRES_USER and POSTGRES_PASSWORD that are provided by the postgresql docker image. I think we can also rely on POSTGRES_DB to avoid creating a new variable

echo "WARN: POSTGRES_DATABASE_NAME is not set. POSTGRES_USER will be used as database name"
else
export PGDATABASE="${POSTGRES_DATABASE_NAME}"
fi
export PGPASSWORD="${POSTGRES_PASSWORD}"
DATABASE_EXISTS="$(psql -qAt -h "${SYMFONY__ENV__DATABASE_HOST}" -p "${SYMFONY__ENV__DATABASE_PORT}" -U "${POSTGRES_USER}" \
-c "SELECT 1 FROM pg_catalog.pg_database WHERE datname = '${SYMFONY__ENV__DATABASE_NAME}';")"
TABLE_EXISTS="$(psql -qAt -h "${SYMFONY__ENV__DATABASE_HOST}" -p "${SYMFONY__ENV__DATABASE_PORT}" -U "${POSTGRES_USER}" \
-c "SELECT 1 FROM information_schema.tables WHERE table_name = 'wallabag_user';")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table wallabag_user may have a different name on some installations as a prefix can be set using $SYMFONY__ENV__DATABASE_TABLE_PREFIX

if [ "$DATABASE_EXISTS" != "1" ]; then
echo "Configuring the Postgres database ..."
psql -q -h "${SYMFONY__ENV__DATABASE_HOST}" -p "${SYMFONY__ENV__DATABASE_PORT}" -U "${POSTGRES_USER}" \
Expand All @@ -87,6 +94,9 @@ provisioner() {
-c "CREATE ROLE ${SYMFONY__ENV__DATABASE_USER} with PASSWORD '${SYMFONY__ENV__DATABASE_PASSWORD}' LOGIN;"
fi
install_wallabag
elif [ "$TABLE_EXISTS" != "1" ]; then
echo "Wallabag user and database is set already but tables not initialized, running install_wallabag ..."
install_wallabag
else
echo "WARN: Postgres database is already configured. Remove the environment variable with root password."
fi
Expand Down