[Answered ]-How do I use Docker on BitBucket pipelines to test a Django app that needs PostGIS?

1👍

✅

We have recently figured it out, and published our own Docker image with support for Python, Django, Postgres, PotGIS and a few other things.

https://github.com/zostera/docker-django-ci

1👍

I’ve written a detailed post about Building, Testing and Deploying Django App with Bitbucket Pipelines

It can be a good start for extending it with PostGIS and I will point you in the right direction. In addition to the post, we’ve open sourced Dockerfiles which you can extend to support PostGIS.

You’ll need a good tutorial on installing PostGIS, e.g. try this one.

Start with the centos7-postgresql9.4 Dockerfile, and add commands for installing PostGIS, right before VOLUME line:

...

# install PostGIS
RUN yum -y install postgis2_94 postgis2_94-client

VOLUME ["/var/lib/pgsql/9.4"]

Finally, you have to enable extensions in database. Add this code to start_postgres.sh:

if [ -n "${POSTGRESQL_DATABASE}" ]; then
  echo "Creating database \"${POSTGRESQL_DATABASE}\"..."
  sudo -u postgres psql -c "CREATE DATABASE \"${POSTGRESQL_DATABASE}\" OWNER \"${POSTGRESQL_USER}\";"
  # create db gistest, connect to db gistest and create postgis extension
  sudo -u postgres psql -c "CREATE DATABASE gistest;\c gistest;CREATE EXTENSION postgis;"
fi

Leave a comment