mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

Building mapnik+node-mapnik with postgis SSL support #110

Closed tomalrussell closed 6 years ago

tomalrussell commented 6 years ago

When trying to connect to Postgres with sslmode=require, I get:

Error: Postgis Plugin: sslmode value "require" invalid when SSL support is not compiled in

Related to https://github.com/mapnik/node-mapnik/issues/755 and https://github.com/mapnik/mapnik/issues/2550, but I'm not on Heroku (so the pgbouncer fix doesn't seem to be relevant), and I'm working with Ubuntu 18.04 (so the mapnik nightly builds don't seem to be available).

My steps so far:

Is there anything obvious I'm missing, or more information that I can provide?

talaj commented 6 years ago

The error message comes from https://github.com/postgres/postgres/blob/e3f99e03e2ec65e7ddb1f3056b545f2afa57b2d0/src/interfaces/libpq/fe-connect.c#L1161

It's a block within #ifndef USE_SSL, which means your libpq was compiled without USE_SSL.

lightmare commented 6 years ago

It's not "your libpq" that's the culprit, it's libpq from mason installed by ./bootstrap.sh.

You should be able to compile mapnik with just system packages, I'd start with

# add-apt-repository ppa:ubuntugis/ppa
# apt-get update
apt-get -s build-dep mapnik

to see what's missing, some may be optional. rm mapnik-settings.env config.py #, to clear stuff from bootstrap;

./configure #, install what's missing, repeat until satisfied

tomalrussell commented 6 years ago

Thanks for the quick responses - I'll have a go at installing with system packages and update with a :+1: or more questions.

tomalrussell commented 6 years ago

Okay, compiling with system packages seems to work.

Here are my steps (script in details below):

  1. install dependences (see https://github.com/mapnik/mapnik/blob/master/INSTALL.md)
  2. build node with shared openssl option (node v8.11.3 would bundle openssl 1.0, whereas Ubuntu 18.04 libpq-dev links against openssl 1.1)
  3. build mapnik
  4. build node-mapnik straight into a project with npm install --build-from-source=mapnik
  5. test creating a postgis Datasource with PGSSLMODE=require environment variable set

I learnt that node bundles openssl, and compiling node with ./configure --shared-openssl fixed a segmentation fault that was being thrown (when running my test script with node index.js) when I had just installed the linux binaries.

Note that this was for Ubuntu 18.04. Almost the same steps worked on Ubuntu 16.04, though the default boost libraries are only recent enough for mapnik v3.0.x, and libpq was happy with the version of openssl packaged in the node binaries (so compiling node wasn't necessary).

Script ```bash # Set up build environment sudo add-apt-repository universe # provides libboost-regex-dev, libboost-python-dev, libgdal-dev, postgis sudo apt update sudo apt upgrade sudo apt install --no-install-recommends \ build-essential clang python python-dev \ libicu-dev \ zlib1g-dev \ libharfbuzz-dev \ libfreetype6 libfreetype6-dev \ libxml2 libxml2-dev \ libpng-dev libjpeg-dev \ postgresql libpq-dev \ postgresql-10-postgis-2.4 postgresql-10-postgis-2.4-scripts # or postgresql-9.5-postgis-2.2 (on Ubuntu 16.04) \ libgdal-dev libproj-dev \ libboost-filesystem-dev \ libboost-system-dev \ libboost-regex-dev \ libboost-program-options-dev \ libboost-python-dev \ libboost-thread-dev \ libssl-dev # for node to compile against # Node with shared openssl (would bundle 1.0, system libpq links against 1.1) NODE_VERSION=v8.11.3 wget https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION.tar.gz tar xf node-$NODE_VERSION.tar.gz cd node-$NODE_VERSION ./configure --shared-openssl make -j4 cat >> ~/.profile <mapnik_version # git checkout v3.0.x # would work with node-mapnik 3.7.2 git submodule update --init rm config.py ./configure JOBS=4 make sudo make install # Check mapnik-config -v # Test cd ~ mkdir test-project cd test-project sudo -S -u postgres psql -c 'create role tom with superuser login;' createdb test psql -c "create user test with login password 'test';" -d test psql -c 'grant all on database test to test;' -d test psql -c 'create extension postgis;' -d test psql -c 'create table test( geom geometry(geometry, 3857) );' -d test -U test cat > package.json < index.js <