From 9c18f030ca743e77cce0205bf5f49a77e8bf33bd Mon Sep 17 00:00:00 2001 From: curtisy1 Date: Mon, 23 Jan 2023 12:47:50 +0100 Subject: [PATCH] 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. --- run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 69d54a1..0b2abe6 100755 --- a/run.sh +++ b/run.sh @@ -40,7 +40,7 @@ if [ ! -f /data/style/mapnik.xml ]; then carto ${NAME_MML:-project.mml} > mapnik.xml fi -if [ "$1" == "import" ]; then +if [ "$1" == "import" ] && [ ! -f /var/lib/postgresql/14/main/.databaseImported ]; then # Ensure that database directory is in right state mkdir -p /data/database/postgres/ chown renderer: /data/database/ @@ -126,6 +126,8 @@ if [ "$1" == "import" ]; then service postgresql stop + touch /var/lib/postgresql/14/main/.databaseImported + exit 0 fi