skip import when persisted data exists

When running in a kubernetes cluster, the import step should usually only happen once.
For example, this could be done using an init container.
Doing so and changing the deployment in a way that triggers a re-deploy currently fails
because the database has already been initialized and persisted.

To avoid this, write an empty file to the postgresql directory and check whether it exists
on the next successful run to avoid running the setup again.
This commit is contained in:
curtisy1 2023-01-23 12:47:50 +01:00
parent 10571b77b7
commit 9c18f030ca

4
run.sh
View File

@ -40,7 +40,7 @@ if [ ! -f /data/style/mapnik.xml ]; then
carto ${NAME_MML:-project.mml} > mapnik.xml carto ${NAME_MML:-project.mml} > mapnik.xml
fi fi
if [ "$1" == "import" ]; then if [ "$1" == "import" ] && [ ! -f /var/lib/postgresql/14/main/.databaseImported ]; then
# Ensure that database directory is in right state # Ensure that database directory is in right state
mkdir -p /data/database/postgres/ mkdir -p /data/database/postgres/
chown renderer: /data/database/ chown renderer: /data/database/
@ -126,6 +126,8 @@ if [ "$1" == "import" ]; then
service postgresql stop service postgresql stop
touch /var/lib/postgresql/14/main/.databaseImported
exit 0 exit 0
fi fi