Running a Postgres DB in an Alpine Linux image to run Mapnik Tests
Intro
In order to run Mapnik's tests, it requires a local Postgres db with Postgis installed. When I built it from source and ran the tests I had 138 errors. I was receiving log output indicating that there were errors from connecting to the PostgresDB.
root@container$ make test
...
psql (PostgreSQL) 15.1
-------------------------------------------------------------------------------
postgis
Ping Postmaster (check if server is runnging and accessible
-------------------------------------------------------------------------------
test/unit/datasource/postgis.cpp:83
...............................................................................
test/unit/datasource/postgis.cpp:87: warning:
Can't run postgis.input tests - check postmaster is running and accessible
...
ERROR (Postgis Plugin: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Connection string: 'dbname=template_postgis connect_timeout=4 fallback_application_name=mapnik'
...
View failure report at "/tmp/mapnik-visual-images/visual-test-results/index.html"
make: *** [Makefile:83: test] Error 158
So I decided to start one up in the container and then run the tests. The error indicates that it is trying to communicate with postgres locally and not on a defined server. So I can manually do this test just to see if it reduces the error count.
Steps
root@container$ apk add postgresql postgis
root@container$ mkdir /run/postgresql
root@container$ chown postgres:postgres /run/postgresql
root@container$ mkdir /var/lib/postgresql/data
root@container$ chmod 0700 /var/lib/postgresql/data
root@container$ chown postgres:postgres /var/lib/postgresql/data
root@container$ su postgres
postgres@container$ initdb -D /var/lib/postgresql/data
postgres@container$ echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf
postgres@container$ echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf
postgres@container$ pg_ctl start -D /var/lib/postgresql/data/
postgres@container$ pg_lsclusters
postgres@container$ createdb template_postgis
postgres@container$ psql -d template_postgis -f /usr/share/postgresql15/contrib/postgis-3.3/postgis.sql
postgres@container$ psql -d template_postgis -f /usr/share/postgresql15/contrib/postgis-3.3/spatial_ref_sys.sql
postgres@container$ psql
postgres=# CREATE ROLE root with LOGIN SUPERUSER password '';
postgres=# \du
postgres=# SELECT * from pg_available_extensions
postgres=# CREATE EXTENSION postgis;
postgres=# SELECT * from pg_extension;
postgres=# select postgis_version();
postgres=# \q
postgres@container$ whoami
postgres
postgres@container$ exit
root@container$ make
root@container$ make test
Conclusion
root@container$ make test
output:
...
psql (PostgreSQL) 15.1
2023-01-18 17:21:43.066 UTC [6012] ERROR: relation "does_not_exist" does not exist at character 15
2023-01-18 17:21:43.066 UTC [6012] STATEMENT: SELECT * FROM does_not_exist LIMIT 0
2023-01-18 17:21:43.122 UTC [6014] FATAL: role "not_a_valid_user" does not exist
...
View failure report at "/tmp/mapnik-visual-images/visual-test-results/index.html"
make: *** [Makefile:83: test] Error 164
Now there are six more errors... :roll_eyes: