openmaptiles / openmaptiles-tools

Tools to turn the schema into other formats
MIT License
397 stars 136 forks source link

Make `$PGPORT` work in `docker/postgis` image #403

Closed zstadler closed 2 years ago

zstadler commented 2 years ago

Related to https://github.com/openmaptiles/openmaptiles/issues/1354

PostGIS initialization could not be completed if $PGPORT was not the default 5432.

For example, when using PGPORT=54321, the initialization is incomplete:

postgres_1                      | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
postgres_1                      | CREATE DATABASE
postgres_1                      | Loading PostGIS extensions into template_postgis
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | Loading PostGIS extensions into openmaptiles
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      |
postgres_1                      | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/20_omt_postgis.sh
postgres_1                      | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
postgres_1                      |   Loading OMT postgis extensions
postgres_1                      | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
postgres_1                      | Loading extensions into template_postgis
postgres_1                      | psql: connection to server at "postgres" (172.28.0.2), port 54321 failed: Connection refused
postgres_1                      |       Is the server running on that host and accepting TCP/IP connections?

where 20_omt_postgis.sh is a copy of docker/postgis/initdb-postgis.sh

To make 20_omt_postgis.sh work like 10_postgis.sh does:

  1. The execute bits were removed and the script is now sourced by the parent script /usr/local/bin/docker-entrypoint.sh.
  2. "${psql[@]}" is used rather than psql.

The result is a complete initialization:

postgres_1                      | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
postgres_1                      | CREATE DATABASE
postgres_1                      | Loading PostGIS extensions into template_postgis
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | Loading PostGIS extensions into openmaptiles
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      |
postgres_1                      | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/20_omt_postgis.sh
postgres_1                      | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
postgres_1                      |   Loading OMT postgis extensions
postgres_1                      | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
postgres_1                      | Loading extensions into template_postgis
postgres_1                      | DROP EXTENSION
postgres_1                      | DROP EXTENSION
postgres_1                      | NOTICE:  extension "postgis" already exists, skipping
postgres_1                      | CREATE EXTENSION
postgres_1                      | NOTICE:  extension "fuzzystrmatch" already exists, skipping
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | Loading extensions into openmaptiles
postgres_1                      | DROP EXTENSION
postgres_1                      | DROP EXTENSION
postgres_1                      | NOTICE:  extension "postgis" already exists, skipping
postgres_1                      | CREATE EXTENSION
postgres_1                      | NOTICE:  extension "fuzzystrmatch" already exists, skipping
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
postgres_1                      | CREATE EXTENSION
TomPohys commented 2 years ago

Thanks a lot. I assumed that for OMT there will be PR for adding something like command: -p ${PGPORT:-5432} in docker-compose.yml in postgres target?

zstadler commented 2 years ago

I think so too. Something like

services:
  postgres:
    ports:
      - "${PGPORT:-5432}:${PGPORT:-5432}"