Skip to content

Instantly share code, notes, and snippets.

@jacquesfize
Created May 28, 2025 13:09
Show Gist options
  • Save jacquesfize/4a17edba6be11198df954943483469a6 to your computer and use it in GitHub Desktop.
Save jacquesfize/4a17edba6be11198df954943483469a6 to your computer and use it in GitHub Desktop.
Installation en mode DEV de GeoNature

GeoNature en mode DEV

Cette documentation a pour but de faciliter l'installation de GeoNature en mode DEV pour tout le monde.

Depuis la 2.15.4, il existe deux manières de faire :

  1. Installation classique et lancement des différents services indépendamment.
  2. Mode dev fourni par GeoNature-Docker-services

Pré-Requis

  • Système d'exploitation basé sur Linux
  • Python >=3.9 et < 3.12
  • (Optionnel) Docker

Installation classique

Installation des dépendances

Dans un premier temps, il est nécessaire d'installer les dépendances systèmes avec la commande suivante :

sudo apt install unzip git postgresql-postgis postgis python3-pip python3-venv python3-dev libpq-dev libgdal-dev libffi-dev libpangocairo-1.0-0 apache2 redis

Installation de GeoNature

git clone https://github.com/PnX-SI/GeoNature.git
cd GeoNature
git submodule init && git submodule update
cp config/settings.ini.sample config/settings.ini
cp config/geonature_config.toml.sample config/geonature_config.toml

Remplir settings.ini

Changer la configuration des paramètres d'installations dans le fichier settings.ini.

Indiquer l'url d'accès du serveur angular dans my_url : http://127.0.0.1:4200/ Changer la variable MODE à dev.

Exemple de settings.ini

## Fichier de configuration utilisé lors de l'installation de GeoNature

# Set mode to 'dev' to install GeoNature in dev mode
MODE=dev

# Langue du serveur
# valeur possible : fr_FR.UTF-8, en_US.utf8
# locale -a pour voir la liste des locales disponible
my_local=fr_FR.UTF-8

# URL Configuration
###################

# My host URL or IP, starting with http and with / at the end
my_url=http://127.0.0.1:4200/

# PostgreSQL Configuration
##########################

# Drop eventual existing database during installation
drop_apps_db=true

# DB host
# Attention les scripts d'installation automatique (install_db.sh et install_all.sh) ne fonctionneront
# que si votre BDD est installée en local (localhost). Si vous souhaitez installer votre BDD sur un autre serveur,
# les scripts n'auront pas les droits suffisants pour créer la BDD sur un autre serveur et cela devra être fait manuellement.
db_host=localhost

# PostgreSQL port
db_port=5432

# GeoNature database name
db_name=geonature2db

# GeoNature database owner username
user_pg=geonatadmin

# GeoNature database owner password
user_pg_pass=geonatadmin

# Local projection SRID
srid_local=2154

# Default language (locale)
# Availaible language value : fr
default_language=fr

# Installation de la base de connaissance des statuts
install_bdc_statuts=true

# Permet l'installation des couches SIG des communes et départements
# Seules les couches de métropole en 2154 sont fournies (false conseillé hors métropole)
install_sig_layers=true

# Installe les grilles INPN (1, 5 et 10km)
install_grid_layer=true

# Install default French DEM (Mainland France only - BD alti 250m))
install_default_dem=false

# Vectorise dem raster for more performance. This will increse installation duration and take more disk space
vectorise_dem=false

# Insert sample data (available only in Mainland France with srid_local=2154 ; false otherwise)
add_sample_data=true

# Insert INPN sensitivity referential (will force installation of departments and regions)
install_ref_sensitivity=true

#### Modules GeoNature ####

# Installer le module validation
install_module_validation=true
# Installer le module Occurrence d'habitat
install_module_occhab=true

Remplir geonature_config.toml

Le fichier geonature_config.toml contient les paramètres de configuration de GeoNature. N'oublier surtout pas de modifier l'adresse de connexion à la base de données PSQL dans la variable SQLALCHEMY_DATABASE_URI.

En mode DEV, il faut indiquer l'url d'accès du backend. Par défaut, le backend de GeoNature est accessible sur http://127.0.0.1:8000.

Exemple de geonature_config.toml

#############################################
# GeoNature backend global configuration file
#############################################
# Database
SQLALCHEMY_DATABASE_URI = "postgresql://geonatadmin:geonatadmin@localhost:5432/geonature2db"
URL_APPLICATION = "http://127.0.0.1:4200"
API_ENDPOINT = "http://127.0.0.1:8000"
# Remplacer par une clé alétoire complexe
SECRET_KEY = '3c0ae436-711c-4d2e-87c3-477ytjrtyj28491def8'
# Langue principale par défaut
DEFAULT_LANGUAGE = 'fr'

#######################################################################################
###### Si vous souhaitez surcoucher certains paramètres,
###### compléter les sections ci-dessous à partir du modèle default_config.toml.example
#######################################################################################
[VALIDATION]
AUTO_VALIDATION_ENABLED = true
AUTO_VALIDATION_CRONTAB = "*/1 * * * *"

# Configuration liée à la page d’accueil
[HOME]
TITLE = "Bienvenue dans GeoNature"
INTRODUCTION = "Texte d'introduction, configurable pour le modifier régulièrement ou le masquer<p style='color:red;'>Couleur</p>"
FOOTER = ""

# Configuration liée aux ID de BDD
[BDD]

# Configuration générale du frontend
[FRONTEND]

# Configuration cartographique
[MAPCONFIG]

BASEMAP = [
{
name="IGN Scan 25",
url="https://data.geopf.fr/private/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&apikey=ign_scan_ws&LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&EXCEPTIONS=text/xml&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image/jpeg&STYLE=normal",
attribution="&copy IGN"
},
{name ="IGN Cadastre",
url = "https://data.geopf.fr/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=CADASTRALPARCELS.PARCELS&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image/png&STYLE=normal",
attribution = "&copy IGN"}
]

REF_LAYERS=[
    {
        code="znieff1",
        type="wms",
        label="Znieff de Bretagne",
        activate=false,
        url="https://geobretagne.fr/geoserver/dreal_b/znieff1/wms",
        params={layers="znieff1", crs="EPSG:4326", service="wms", format="image/png", version="1.3.0", request="GetMap", transparent=true}
    }, {
        code="COM_LYON",
        type="wfs",
        label="Communes du Grand Lyon",
        activate=false,
        style={
            color= "red",
            fill= true,
            fillOpacity= "0.2",
            weight= 2,
            fillColor= "blue"
        },
        url="https://download.data.grandlyon.com/wfs/grandlyon?SERVICE=WFS&VERSION=2.0.0&request=GetFeature&typename=adr_voie_lieu.adrcomgl&outputFormat=geojson&SRSNAME=EPSG:4326"
    }, {
        code="VEGE_POST_ELEC",
        type="geojson",
        label="Végétation dans les postes élec.",
        activate=false,
        style={
            color= "#ffa43b",
            fill= false,
            fillOpacity= "0.0",
            weight= 2
        },
        url="https://www.data.gouv.fr/fr/datasets/r/02aaadfa-f774-4b92-b81f-9f1436182701"
    }, {
        code="COM",
        label="Communes",
        activate=true,
        type="area",
        style={
            color= "grey",
            fill= false,
            fillOpacity= "0.0",
            weight= 2
        },
        params= {limit= 2000}
    },
]

# Configuration médias
[MEDIAS]

[USERSHUB]
URL_USERSHUB = 'http://127.0.0.1:5001' # sans slash final
# Administrateur de mon application
ADMIN_APPLICATION_LOGIN = "admin"
ADMIN_APPLICATION_PASSWORD = "admin"

Lancer l'installation de GeoNature

cd <chemin vers dossier GeoNature>
cd install
./00_install_nvm.sh
./01_install_backend
./03_create_db.sh
./04_install_gn_modules.sh
./05_install_frontend.sh

Lancer les services pour faire fonctionner GeoNature

Pour lancer le backend:

cd <chemin vers dossier GeoNature>
source backend/venv/bin/activate
geonature dev-back

Pour lancer le frontend:

cd <chemin vers dossier GeoNature>
cd frontend
nvm use
npm run start

Se rendre sur l'url : http://127.0.0.1:4200

Installation avec Docker

Installation des dépendances

sudo apt install make jq git-lfs

Installation de Docker

Vérifier que docker est bien installé sur votre machine. Pour cela, juste tapez la commande docker run hello-world dans le terminal. Si le message suivant s'affiche alors docker est bien installé.

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Dans le cas contraire, référez-vous à la documentation officielle ici.

Récupération de GeoNature-Docker-services

git clone https://github.com/PnX-SI/GeoNature-Docker-services.git

Initialisation de l'environnement

cp .env.sample .env
./init-config.sh
make submodule_init

Lancement de l'environnement de dev

make dev

Où modifier les sources ?

Pour faire des modifications, il suffit de modifier comme sur une installation classique, les fichiers présents dans le dossier sources/GeoNature.

Comment utiliser les commandes GeoNature ?

docker exec <nom_ou_id_container_backend> <commande>
# Par exemple: docker exec geonature-backend-1 geonature db status
@MoulinZ
Copy link

MoulinZ commented May 28, 2025

J'ai voulu l'installer sur mon WSL, et j'ai cette erreur :

./03_create_db.sh
could not change directory to "/home/zacharie/dev/GeoNature": Permission denied
Check GeoNature database user 'geonatadmin' exists…
could not change directory to "/home/zacharie/dev/GeoNature": Permission denied
Creating GeoNature database...
could not change directory to "/home/zacharie/dev/GeoNature": Permission denied

En sachant que j'avais déjà un postgres d'installé en 15.

@MoulinZ
Copy link

MoulinZ commented Jun 2, 2025

Juste un problème de locale au final. Mon WSL tout neuf était en en_US...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment