Skip to content

Commit

Permalink
Add GIS / GeoDjango support
Browse files Browse the repository at this point in the history
  • Loading branch information
aapris committed Oct 10, 2023
1 parent 8a3affe commit 7c02748
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

FROM python:3.11-alpine

# DOCKER_IMAGE is checked in settings.py to determine which *_LIBRARY_PATHs to use
ENV DOCKER_IMAGE alpine

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Override these in the docker-compose.yml file or elsewhere
ENV DATABASE_NAME=postgres
ENV DATABASE_USER=postgres
ENV DATABASE_PASSWORD=postgres
ENV DATABASE_HOST=db
ENV DATABASE_PORT=5432

ENV MEDIA_HOME=/media
ENV DJANGO_SETTINGS_MODULE=deviceregistry.settings

# Install GeoDjango dependencies
RUN apk add --no-cache \
geos-dev \
proj-dev \
gdal-dev

RUN addgroup -S app && adduser -S app -G app
WORKDIR /home/app

Expand Down
35 changes: 17 additions & 18 deletions deviceregistry/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

import environ
import os
from pathlib import Path

import environ

env = environ.Env(
# set casting, default value
DEBUG=(bool, False)
Expand Down Expand Up @@ -43,6 +45,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.gis",
"rest_framework",
"rest_framework.authtoken",
"auditlog",
Expand Down Expand Up @@ -78,32 +81,19 @@

WSGI_APPLICATION = "deviceregistry.wsgi.application"

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

# Database https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
# "ENGINE": "django.contrib.gis.db.backends.postgis",
# "ENGINE": "django.db.backends.postgresql",
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": env("DATABASE_NAME", default="postgres"),
"USER": env("DATABASE_USER", default="postgres"),
"PASSWORD": env("DATABASE_PASSWORD", default="postgres"),
"HOST": env("DATABASE_HOST", default="db"),
"PORT": env("DATABASE_PORT", default=5432),
}
}
# if env("DATABASE_LOCAL", default=False):
# # Temp database for development
# DATABASES = {
# "default": {
# "ENGINE": "django.contrib.gis.db.backends.postgis",
# "NAME": "deviceregistry",
# # "USER": env("DATABASE_USER", default="postgres"),
# # "PASSWORD": env("DATABASE_PASSWORD", default="postgres"),
# # "HOST": env("DATABASE_HOST", default="db"),
# # "PORT": env("DATABASE_PORT", default=5432),
# }
# }


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -151,3 +141,12 @@
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 50,
}


# Set library paths depending on which environment we are running in
# These are needed for GeoDjango running in Docker python:3.11-alpine
if os.environ.get("DOCKER_IMAGE", "") == "alpine":
GDAL_LIBRARY_PATH = "/usr/lib/libgdal.so"
GEOS_LIBRARY_PATH = "/usr/lib/libgeos_c.so"
else:
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ requires-python = ">=3.10"
dynamic = ["version"]

dependencies = [
"Django >= 4.2.5, < 5.0",
"Django >= 4.2.6, < 5.0",
"django-auditlog",
"django-environ",
"django-rest-framework",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
asgiref==3.7.2
# via django
django==4.2.5
django==4.2.6
# via
# django-auditlog
# djangorestframework
Expand Down

0 comments on commit 7c02748

Please sign in to comment.