Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnecting database during init process makes a dependency service management harder in "docker-compose.yml" #296

Closed
sanak opened this issue May 31, 2022 · 1 comment

Comments

@sanak
Copy link

sanak commented May 31, 2022

From #290 and #292, reconnecting database during init process was introduced, but this makes a dependency service management harder in docker-compose.yml like the following redmine usecase, because redmine database migration process starts before reconnecting database and failed.
https://github.com/gtt-project/docker-gtt/blob/feature/simplify-docker-settings/docker-compose.yml

services:
  postgis:
    image: postgis/postgis:14-3.2
    volumes:
      - postgis:/var/lib/postgresql/data

  redmine:
    :
    depends_on:
      - postgis

docker-compose.yml side workaround is possible by waiting for last postgis_tiger_geocoder extension like as follows, but this is not handy.

     volumes:
       - postgis:/var/lib/postgresql/data
+    healthcheck:
+      test: "pg_isready && psql -c \"\\dx\" | grep postgis_tiger_geocoder"
+      interval: 10s
+      timeout: 2s
+      retries: 5
+      start_period: 10s
 
   redmine:
     :
     depends_on:
-      - postgis
+      postgis:
+        condition: service_healthy

So, if possible, without reconnecting database during init process is preferable.

The following diff is my suggestion, but I am not sure whether the sessions are separated and original #290 issue will be solved by this.

--- a/initdb-postgis.sh
+++ b/initdb-postgis.sh
        "${psql[@]}" --dbname="$DB" <<-'EOSQL'
                CREATE EXTENSION IF NOT EXISTS postgis;
                CREATE EXTENSION IF NOT EXISTS postgis_topology;
-               -- Reconnect to update pg_setting.resetval
-               -- See https://github.com/postgis/docker-postgis/issues/288
-               \c
+EOSQL
+
+       "${psql[@]}" --dbname="$DB" <<-'EOSQL'
                CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
                CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
 EOSQL
@sanak
Copy link
Author

sanak commented Jun 7, 2022

Using external IP (address) in docker-compose.yml healthcheck (from #297 (comment)) is enough handy, so I close this issue.

--- a/docker-compose.yml
+++ b/docker-compose.yml
     volumes:
       - postgis:/var/lib/postgresql/data
+    healthcheck:
+      test: "pg_isready -h postgis -U ${DB_USER} -d ${DB_NAME}"
+      interval: 10s
+      timeout: 2s
+      retries: 5
+      start_period: 10s
 
   redmine:
    :
     depends_on:
-      - postgis
+      postgis:
+        condition: service_healthy

@sanak sanak closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant