Deploying a development environment

In this section, we will learn how to run GeoNode in development mode. This particular way of running GeoNode will allow us to view and debug any changes to the code at runtime without needing to restart the services.

Note that we will still need the following services to run on the system:

  • PostgreSQL service w/ PostGIS extensions; we will learn how to link Dev GeoNode to an existing database and initialize a new one.

  • Apache Tomcat9 with GeoServer; we will still need a running GeoServer instance to manage the geospatial datasets.

Stop GeoNode Services

You may still have some services running from a previous tutorial, so make sure these services are down.

  • Stop NGINX and UWSGI services

sudo systemctl stop nginx

sudo systemctl stop uwsgi

You may also want to check the status of the services:

sudo systemctl status nginx
   [...long output here...]
   
sudo systemctl status uwsgi
   [...long output here...]

You may also want to check that the service was properly closed

sudo ps aux | grep uwsgi

If you find any uwsgi processes still running, you can kill them right away with:

sudo pkill -9 -f uwsgi

Other services and processes

In order to have a complete GeoNode ecosystem, you need additional services along with the GeoNode-Django process itself.

As documented in a previous training session, you will have to set up at least PostgreSQL and GeoServer. If you didn’t do it before, run

Prepare the GeoNode environment

You may have already had your GeoNode code checked out. Anyway, let’s repeat the steps of the “GeoNode Basic Install” training lesson here.

  • Create the geonode_dev virtualenv (if you don’t already have it):

    mkvirtualenv --python=$(which python3.10) geonode_dev
    
  • Switch to the geonode_dev virtual env

    workon geonode_dev
    
  • Prepare the GeoNode working directory (if you don’t already have it):

    # Let's create the GeoNode core base folder and clone it
    sudo mkdir -p /opt/geonode/; sudo usermod -a -G www-data $USER; sudo chown -Rf $USER:www-data /opt/geonode/; sudo chmod -Rf 775 /opt/geonode/
    
    # Clone the GeoNode source code on /opt/geonode
    cd /opt; git clone https://github.com/GeoNode/geonode.git -b 4.1.x geonode
    
  • Install the Python packages needed by GeoNode:

    cd /opt/geonode
    pip install -r requirements.txt --upgrade --no-cache --no-cache-dir
    pip install -e . --upgrade
    pip install pygdal=="`gdal-config --version`.*"
    

Prepare the .env_dev variables

Adjust the .env_dev file to match our current configuration.

vim .env_dev

Make sure SITEURL, DB connection settings, and GEOSERVER_* URLs and connection parameters are correct.

...
# #################
# backend
# #################
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
GEONODE_DATABASE=geonode
GEONODE_DATABASE_PASSWORD=geonode
GEONODE_GEODATABASE=geonode_data
GEONODE_GEODATABASE_PASSWORD=geonode
GEONODE_DATABASE_SCHEMA=public
GEONODE_GEODATABASE_SCHEMA=public
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_URL=postgis://geonode:geonode@localhost:5432/geonode
GEODATABASE_URL=postgis://geonode:geonode@localhost:5432/geonode_data
GEONODE_DB_CONN_MAX_AGE=0
GEONODE_DB_CONN_TOUT=5
DEFAULT_BACKEND_DATASTORE=datastore
...
SITEURL=http://localhost:8000/
...
# #################
# geoserver
# #################
GEOSERVER_WEB_UI_LOCATION=http://localhost:8080/geoserver/
GEOSERVER_PUBLIC_LOCATION=http://localhost:8080/geoserver/
GEOSERVER_LOCATION=http://localhost:8080/geoserver/
GEOSERVER_ADMIN_USER=admin
GEOSERVER_ADMIN_PASSWORD=geoserver

Aligning the DB

Make sure the DB and GeoNode are aligned.

  • Align the migrations and static/media folders

./paver_dev.sh sync
  • Align the internal URLs and Metadata links

# The order is important! Those are regex expressions and will be executed one after the other...

# Fix GeoServer URLs first
./manage_dev.sh migrate_baseurl --source-address=http://localhost/geoserver --target-address=http://localhost:8080/geoserver

# Fix GeoNode URLs
./manage_dev.sh migrate_baseurl --source-address=http://localhost/ --target-address=http://localhost:8000/

# Align the Metadata links
./manage_dev.sh set_all_datasets_metadata -d
./paver_dev.sh start_django

Configuring GeoServer OAuth plugin

Make sure the GeoServer OAuth plugin is configured correctly.

  • Adjust the GeoServer PROXY_BASE_URL

sudo vim /opt/data/geoserver_data/global.xml
-<proxyBaseUrl>http://localhost/geoserver</proxyBaseUrl>
+<proxyBaseUrl>http://localhost:8080/geoserver</proxyBaseUrl>
sudo systemctl restart tomcat9.service

image

  • Adjust the REST Role Service

#login: http://localhost:8080/geoserver <-- admin:geoserver

image

  • Adjust the OAuth2 Security Filter

#login: http://localhost:8080/geoserver <-- admin:geoserver

image

image

  • Test the GeoServer logout/login with GeoNode

Let’s Start GeoNode

  • Let’s refresh the datasets’ thumbnails and verify that the settings are correct

./manage_dev.sh sync_geonode_datasets --updatethumbnails

Syncing layer 1/11: a__13tde815295_200803_0x6000m_cl
Regenerating thumbnails...
Syncing layer 2/11: Air_Runways
Regenerating thumbnails...
Syncing layer 3/11: BoulderCityLimits
Regenerating thumbnails...
Syncing layer 4/11: Buildings050714
Regenerating thumbnails...
Syncing layer 5/11: Mainrd
Regenerating thumbnails...
Syncing layer 6/11: Parcels
Regenerating thumbnails...
Syncing layer 7/11: pointlm
Regenerating thumbnails...
Syncing layer 8/11: srtm_boulder
Regenerating thumbnails...
Syncing layer 9/11: Streets
Regenerating thumbnails...
Syncing layer 10/11: Trails
Regenerating thumbnails...
Syncing layer 11/11: Wetlands_regulatory_area
Regenerating thumbnails...
There are 0 datasets which could not be updated because of errors
  • Start GeoNode in development mode

./paver_dev.sh start_django

---> pavement.start_django
 python -W ignore manage.py runserver 0.0.0.0:8000 &
Performing system checks...

System check identified some issues:

WARNINGS:
?: (urls.W005) URL namespace 'rest_framework' isn't unique. You may not be able to reverse all URLs in this namespace

System check identified 1 issue (5 silenced).
September 07, 2021 - 16:07:13
Django version 2.2.20, using settings 'geonode.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
  • Connect to http://localhost:8000 and verify GeoNode has started correctly

Next Section: Create a geonode project