#Deploying my backend for a geospatial project with Django (GeoDjango) online

17 messages · Page 1 of 1 (latest)

livid elbow
#

1-Installation of Python:

-I installed Python 3.12.7 (avoiding version 3.13.0 as psycopg2 is not yet compatible).
-Configured in VSCode with the necessary extensions.

2-Database transfer:

-I exported my spatial database arrdelbeecarte from PostgreSQL 15 to another system using PostgreSQL 16 through the Backup/Restore function in PGAdmin.
-I had to activate PostGIS with the command CREATE EXTENSION postgis; after creating the database.

3-GDAL installation via OSGeo4W:

-Since GDAL can no longer be installed directly via pip, I used OSGeo4W to install GDAL, PROJ, and GEOS.
-I added the necessary environment variables as recommended in the GeoDjango documentation.

#

4-Virtual environment and dependencies:

I recreated my virtual environment with venv and installed all the dependencies via my requirements.txt file.

Important note: I’m explaining this because the goal was to install my project on a new machine designed exclusively for programming, while my other computer is for gaming. So, the key step to remember is the third one, where Django recommends installing GDAL via OSGeo4W (https://docs.djangoproject.com/en/5.0/ref/contrib/gis/install/#windows).

Current issue: Deployment

I tried deploying my project on AWS using Docker, but I’m facing issues with installing GDAL in the Docker image.
I’m considering deploying my backend on Heroku, but I would like to get the community's advice on the best approach to host a project that uses GDAL and PostGIS, especially with this constraint of having to install GDAL via OSGeo4W.

My questions:

Which platform would you recommend for deploying a Django backend with GDAL and PostGIS (AWS, Heroku, others)?
Are there specific solutions to handle GDAL installation in Docker during deployment?
How have you managed similar situations in your projects?
Note: The constraint relates to GDAL installation via OSGeo4W.

Please tag me when you respond, as it will be easier for me to find the message even if you reply after a couple of days, given that Discord will notify me of your response to my query.

Thank you very much for your help!

hazy tendon
#

not sure about OSGeo4W part, I set it up without ever touching it but i guess it depends on which docker base you are using

#

I'm using python:3.13.0-slim-bookworm and just adding gdal-bin package was enough for OS level dependencies

livid elbow
# hazy tendon not sure about OSGeo4W part, I set it up without ever touching it but i guess it...
  1. psycopg2 compatibility:

    • "I avoided using Python 3.13.0 due to compatibility issues with psycopg2. Have you encountered similar issues using Python 3.13.0 in your project?"
  2. Docker base image used:

    • "You mentioned using python:3.13.0-slim-bookworm in your Docker setup. Could you share the full configuration of your Dockerfile to see how you handle the installation of dependencies like gdal-bin?"
  3. Installing GDAL in Docker:

    • "Did you encounter any compatibility issues or specific errors using gdal-bin in Docker? Was this sufficient to meet all the GDAL requirements for your geospatial project?"
  4. Comparison with OSGeo4W:

    • "Since I installed GDAL through OSGeo4W, do you think there’s an advantage to simplifying things by directly adding gdal-bin to the Docker image? Could this cause compatibility issues with certain systems?"
  5. System dependencies in Docker:

    • "Are you using any other system dependencies for PostGIS or other geospatial libraries besides gdal-bin in your Docker environment?"
  6. Docker base image choice:

    • "Why did you choose python:3.13.0-slim-bookworm for your Docker image? Is this image lighter and more performant for projects involving GDAL and PostGIS compared to other Python images?"
#

and Which platform would you recommend for deploying a Django backend with GDAL and PostGIS (AWS, Heroku, others)?

hazy tendon
#
  1. you don't need psycopg2, not sure why you choose that. Check the django docs for a small warning about it.
  2. "apt install gdal-bin"
  3. No, yes
  4. Not sure what type of compatability issues you expect. An example would be nice.
  5. No
  6. That's the smallest base debian image for Python, people prefer it as a sane default
livid elbow
# hazy tendon 1. you don't need psycopg2, not sure why you choose that. Check the django docs ...

Response:

Thank you so much for your answers, they’re really helpful! You’ve really simplified the process for installing gdal-bin via apt.

I have a few more questions to clarify things:

  1. You mentioned I don't need psycopg2, but I’m using PostgreSQL with PostGIS for my geospatial project. Could you explain why you recommend not using psycopg2? Is there an alternative suggested in the Django documentation?

  2. For installing gdal-bin via apt, did you install it directly in your Dockerfile or did you install it via the Docker Desktop shell? I was trying to install it with a Dockerfile, but I encountered issues. Which method would you recommend?

  3. Would it be possible to share an example of your Dockerfile? It would help me see how you configure the image and install the dependencies.

  4. Regarding compatibility issues, I was concerned that installing gdal via OSGeo4W on my machine might cause conflicts when deploying on Docker. But if you’re simply using gdal-bin in your image, do you think this could cause compatibility issues with certain machines or platforms?

  5. Did you install Docker locally on your system, or are you using a different setup? I’m using Docker Desktop and would like to know if you had to configure anything specific to work with geospatial libraries.

Thanks again for your help, and I look forward to your insights on these questions!

hazy tendon
#
  1. I shared the link to the doc, please check it
  2. Dockerfile. I was talking about an isolated - automated docker build.
  3. I don't configure a thing about GDAL, it's literally just "apt install".
  4. Why would something on your machine might cause conflict with something in Docker? I feel like there is a confusion about the isolation happening with Docker. Again, I'm missing why a package inside a docker container would create any issues with the host.
  5. How you install docker has nothing with what dependencies you use in a container
livid elbow
# hazy tendon 1. I shared the link to the doc, please check it 2. Dockerfile. I was talking ab...

Topic: Hosting Postgres/PostGIS and Deploying GeoDjango Backend with Docker and Heroku

Hi everyone! 👋

I’m working on a Django project with GeoDjango to manage spatial data, and I have a few questions about database hosting and deploying my backend. Thanks in advance for your help!

1. Hosting the Postgres/PostGIS Database

I’d like to host my Postgres/PostGIS database online. Here are the options I’m considering:

  • Render: Unfortunately, it doesn’t support PostGIS.
  • Heroku: This is my preferred platform since it's widely used in the Python community.
  • Supabase: It supports Postgres/PostGIS, but I’m less familiar with this platform.

My goal is to deploy my Postgres/PostGIS database both on Docker Desktop (for local use) and Heroku (for the cloud). Is it possible to set up this configuration in parallel? Are there any specific challenges with integrating PostGIS on Heroku that I should be aware of?

2. Dockerfile for the GeoDjango Backend

Here is my Dockerfile for the Django backend with GeoDjango. I’d love your feedback to make sure the setup is correct, especially for using GDAL (essential for GeoDjango):

#
# Using a base image with Python 3.10
FROM python:3.10-slim

# Installing GDAL and dependencies
RUN apt-get update && \
    apt-get install -y gdal-bin libgdal-dev && \
    apt-get clean

# Setting up the working directory
WORKDIR /app

# Copying the project files
COPY . /app

# Installing Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Adding an environment variable for Django
ENV DJANGO_SETTINGS_MODULE=backend.settings

# Running command to collect static files
RUN python manage.py collectstatic --noinput

# Exposing port 8000
EXPOSE 8000

# Default command to run the server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Do you have any suggestions to improve this Dockerfile? Are there any other configurations you’d recommend for GeoDjango and PostGIS?

3. Deployment on Heroku

Finally, I’m considering hosting both my backend and database on Heroku. I’m aware that Heroku doesn’t have native support for Docker Desktop and that deploying Docker containers may require additional steps. If anyone has experience deploying GeoDjango on Heroku, I’d love to hear your advice and recommendations!

Thanks for your help! 😊

hazy tendon
#

This is getting a bit out of the scope of "help" imo, you are asking for a review of a feature implementation rather than some particular problem

#

Do you have a specific problem/question?

livid elbow
south pecan
#

facing same "problems".
developing on windows, and pushing to Hetzner (Linux). It gets complicated. Trying to install a simple SpatialLite DB so i can push to solid architecture (postgres with postgis activated on docker)

btw, stop using chat GPT for your communication ...

livid elbow