How can I enable postgis on a Kubernetes executor under gitlab-runner?

10/8/2019

I'm trying to set up a CI flow for a Django application which relies on postgis with a Kubernetes executor under the runner. In trying to do so, I've hit several kinds of problem:

  • Trying to use postgres as a service obviously isn't sufficient, but it fails sanely, reporting that /usr/share/postgresql/9.6/extensions/postgis.control can't be found. At this point, that's expected -- but I'm including it here because it serves as proof that the Django/PostgreSQL connection works fine, since the failure occurs when trying to CREATE EXTENSION 'postgis' from a database bootstrap script.

  • Adding a before_script step to apt install -y postgis* postgresql-9.6-postgis-scripts as recommended by an older answer on SO also fails in the same way. Because this is a k8s executor, I'm suspecting that this doesn't install postgis on the actual postgres host, resulting in the error. Adding a find /usr postgis.control step confirms that the file exists on the test runner container.

  • I've also tried using the mdillon/postgis container often referenced as a solution to this, but no dice there: using localhost as the database host in the Django app (which both works for plain postgres as well as being recommended by the docs for the k8s executor type) results in errors about postgres not being reachable at localhost:5432. Updating the hostname to mdillon__postgis likewise fails (but this is predictable since that DNS name format is only supposed to work on Docker executors).

  • At this point, I've also tried creating a bespoke Dockerfile, but what I have mimics mdillon/postgis's Dockerfile very closely (there are only so many ways to install postgis and copy the initdb script), and fails in the same way.

Is there any documented, or at least, working, way to get Postgres with postgis working under a k8s gitlab-runner executor?

-- verandaguy
django
gitlab-ci
kubernetes
postgis
postgresql

0 Answers