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

Make $PGPORT work in docker/postgis image #403

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

zstadler
Copy link
Contributor

Related to openmaptiles/openmaptiles#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

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 proper 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
Copy link
Member

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
Copy link
Contributor Author

I think so too. Something like

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

@TomPohys TomPohys merged commit 0225201 into openmaptiles:master Feb 22, 2022
@zstadler zstadler deleted the fix-pgport branch February 22, 2022 12:03
zstadler added a commit to zstadler/openmaptiles that referenced this pull request Feb 24, 2022
- Allow use of environment variables in addition to .env
- Remove .env-postgres and the need to synchronize it with .env

Resolves openmaptiles#1354
Related to openmaptiles/openmaptiles-tools#403
TomPohys pushed a commit to openmaptiles/openmaptiles that referenced this pull request Apr 19, 2022
- Allow use of environment variables in addition to .env
- Remove .env-postgres and the need to synchronize it with .env

Resolves #1354
Related to openmaptiles/openmaptiles-tools#403
francois2metz pushed a commit to indoorequal/openmaptiles-tools that referenced this pull request Mar 17, 2023
Related to openmaptiles/openmaptiles#1354

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

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`.
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 this pull request may close these issues.

None yet

2 participants