https://github.com/wooyek/docker-geodjango
Test environment for GeoDjango projects with PostGIS and SpatiaLite support out of the box.
https://github.com/wooyek/docker-geodjango
bitbucket-pipelines django docker geodjango postgis
Last synced: about 1 month ago
JSON representation
Test environment for GeoDjango projects with PostGIS and SpatiaLite support out of the box.
- Host: GitHub
- URL: https://github.com/wooyek/docker-geodjango
- Owner: wooyek
- License: mit
- Created: 2016-11-07T10:34:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-03-25T19:01:15.000Z (over 6 years ago)
- Last Synced: 2025-04-08T03:13:36.549Z (6 months ago)
- Topics: bitbucket-pipelines, django, docker, geodjango, postgis
- Language: Dockerfile
- Homepage: https://hub.docker.com/r/wooyek/geodjango/
- Size: 76.2 KB
- Stars: 5
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker for GeoDjango with PostGIS and SpatiaLite
Test environment for GeoDjango projects with PostGIS and SpatiaLite support out of the box.
[](https://hub.docker.com/r/wooyek/geodjango/)
[](https://hub.docker.com/r/wooyek/geodjango/)
[](https://hub.docker.com/r/wooyek/geodjango/)
[](https://travis-ci.org/wooyek/docker-geodjango)## BitBucket Pipelines support
You can use this as a test image with BitBucket Pipelines, an example:
```yaml
image: wooyek/geodjangopipelines:
default:
- step:
script:
# Pipelines overrides default docker entry point, we need to run it maually
- docker-entrypoint.sh
- tox
```
## Tox supportTox is is the best way to encapsulate your tests, here's an example:
```ini
[tox]
envlist = py35,py27
skipsdist = True[testenv]
passenv =
DJANGO_SETTINGS_MODULE
DATABASE_PASSWORD
DATABASE_USER
DATABASE_HOST
DATABASE_NAME
DATABASE_TEST_NAME
setenv =
TOX_ENVBINDIR = {envbindir}
LIBRARY_PATH = /usr/local/lib
CPATH=/usr/local/include
PYTHONIOENCODING = utf-8commands =
coverage erase
coverage run setup.py test
coverage report
coverage xmldeps =
-rrequirements.txt
-rrequirements-dev.txt
```# Build docker image
If you don't have [Docker installed](https://docs.docker.com/engine/installation/#supported-platforms),
you can use [Vagrant](https://www.vagrantup.com/downloads.html) development environment:```bash
vagrant up
vagrant ssh
```Replace `wooyek/geodjango` with your own image name, replace `/vagrant/` with a proper path if you don't use Vagrant:
```bash
docker build -t wooyek/geodjango /vagrant/
docker push wooyek/geodjango
```# Run and test
We can always [check docker machine environment variables](https://docs.docker.com/edge/engine/reference/run/#env-environment-variables)
by this command (you should see default values set in [Dockerfile](Dockerfile)):```bash
docker run --rm wooyek/geodjango env
```We can use host environment, but we still need to to pass environment variable names in a command.
I find the cleaniest easiest way is to create a separate file containing all the environment variables.
Let's prepare our environment file with some variable substitution [from a sample file](sample/environment.env).
This is a one time operations.```bash
ENV_FILE=/vagrant/sample/environment.env
source <(sed -E 's/[^#]+/export &/' ${ENV_FILE})
envsubst < ${ENV_FILE} | tee /vagrant/environment.env
```Let's check them out:
```bash
docker run --rm --env-file /vagrant/environment.env wooyek/geodjango env
```Now we can run tests from a sample project. We will map local `vagrant` folder to a docker volume
to make them accessible from inside a running container. We'll also override `DJANGO_SETTINGS_MODULE` to point to all-in-one settings file,
instead of more specialized `website.settings.testing` module used when settings are split info multiple modules:```bash
docker run --rm -it --name qa \
--volume=/vagrant:/vagrant \
--workdir="/vagrant" \
--memory=4g \
--memory-swap=4g \
--entrypoint=/bin/bash \
--env-file /vagrant/environment.env \
--hostname ${HOSTNAME} \
-e DJANGO_SETTINGS_MODULE=website.settings \
wooyek/geodjango \
docker-entrypoint.sh tox -c /vagrant/sample/awesome-project
```There should be a one passed [test filtering on distance](sample/awesome-project/geoapp/tests.py).
## Cleanup
Docker images take some space, if you need to clear that out use one of those prune commands:```bash
docker system prune
docker image prune
docker container prune
```