diff --git a/VERSION b/VERSION index f0bb29e7..04417676 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.0 +1.3.1.dev0 diff --git a/docs/changelog.rst b/docs/changelog.rst index 561c89c7..40ac31c3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,15 @@ CHANGELOG ========= +1.3.1 (2018-03-15) +------------------ + +**Corrections** + +* Correction de l'installation autonome (sans GeoNature) +* Correction et documentation si l'atlas est accessible dans un sous-répertoire du domaine +* Correction d'une coquille dans le SQL. Merci @lpofredc + 1.3.0 (2018-02-15) ------------------ diff --git a/docs/installation.rst b/docs/installation.rst index 27414b5c..1fb09c43 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -26,8 +26,8 @@ Ce serveur doit aussi disposer de : GeoNature-atlas est susceptible de fonctionner sur d'autres OS (comme Ubuntu par exemple) mais cela n'a pas été testé. -Installation de l'environnement et de l'application -=================================================== +Installation de l'environnement logiciel +======================================== Le script ``install_env.sh`` va automatiquement installer les outils nécessaires à l'application si ils ne sont pas déjà sur le serveur : @@ -88,11 +88,6 @@ Cela installera les logiciels nécessaires au fonctionnement de l'application cd /home/monuser/atlas ./install_env.sh -**4. Lancez l'installation automatique de l'application :** - -:: - - ./install_app.sh Installation de la base de données @@ -151,12 +146,21 @@ Si vous voulez adapter le contenu des vues matérialisées, vous pouvez modifier Si vous souhaitez uniquement recréer la vue ``atlas.vm_observations`` et les 6 autres vues qui en dépendent vous pouvez utiliser le script ``data/update_vm_observations.sql``. +Installtion de l'application +============================ + +**Lancez l'installation automatique de l'application :** + +:: + + ./install_app.sh + Configuration de l'application ============================== Editer le fichier de configuration ``main/configuration/config.py``. -- Renseignez la variable 'database_connection' +- Vérifier que la variable 'database_connection' contient les bonnes informations de connexion à la base - Renseignez l'URL de l'application à partir de la racine du serveur WEB ('/atlas' ou '' par exemple) - Renseignez les autres paramètres selon votre contexte - Rechargez le serveur Web Gunicorn pour que les modifications soient prises en compte (``sudo supervisorctl reload``) diff --git a/initAtlas.py b/initAtlas.py index 61160d58..0a8a3b1f 100644 --- a/initAtlas.py +++ b/initAtlas.py @@ -3,6 +3,9 @@ from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy +from werkzeug.wsgi import DispatcherMiddleware, ProxyMiddleware +from werkzeug.serving import run_simple + from main.configuration import config from sqlalchemy import create_engine, MetaData, Table @@ -13,10 +16,33 @@ APP_DIR = os.path.abspath(os.path.dirname(__file__)) +class ReverseProxied(object): + + def __init__(self, app, script_name=None, scheme=None, server=None): + self.app = app + self.script_name = script_name + self.scheme = scheme + self.server = server + + def __call__(self, environ, start_response): + script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.script_name + if script_name: + environ['SCRIPT_NAME'] = script_name + path_info = environ['PATH_INFO'] + if path_info.startswith(script_name): + environ['PATH_INFO'] = path_info[len(script_name):] + scheme = environ.get('HTTP_X_SCHEME', '') or self.scheme + if scheme: + environ['wsgi.url_scheme'] = scheme + server = environ.get('HTTP_X_FORWARDED_SERVER', '') or self.server + if server: + environ['HTTP_HOST'] = server + return self.app(environ, start_response) def create_app(): # renvoie une instance de app l appli Flask app = Flask(__name__, template_folder=APP_DIR) + app.debug = config.modeDebug from main.atlasRoutes import main as main_blueprint @@ -28,11 +54,16 @@ def create_app(): compress.init_app(app) + app.wsgi_app = ReverseProxied(app.wsgi_app, script_name=config.URL_APPLICATION) + + return app app = create_app() + if __name__ == '__main__': from flask_script import Manager - Manager(app).run() + # Manager(app).run() + run_simple('localhost', 8080, app, use_reloader=True) diff --git a/install_app.sh b/install_app.sh index e48f74a9..6511a930 100755 --- a/install_app.sh +++ b/install_app.sh @@ -22,6 +22,14 @@ virtualenv $venv_dir echo "Installing requirements..." pip install -r requirements.txt +echo "Creating configuration files if they dont already exist" +if [ ! -f ./main/configuration/config.py ]; then + cp ./main/configuration/config.py.sample ./main/configuration/config.py +fi + +sudo sed -i "s/database_connection = .*$/database_connection = \"postgresql:\/\/$user_pg:$user_pg_pass@$db_host:$db_port\/$db_name\"/" ./main/configuration/config.py + + echo "Launching application..." DIR=$(readlink -e "${0%/*}") sudo -s cp atlas-service.conf /etc/supervisor/conf.d/ @@ -35,10 +43,7 @@ if [ ! -d ./static/custom/images/ ]; then mkdir -p ./static/custom/images/ fi -echo "Creating configuration files if they dont already exist" -if [ ! -f ./main/configuration/config.py ]; then - cp ./main/configuration/config.py.sample ./main/configuration/config.py -fi + echo "Creating customisation files if they dont already exist" if [ ! -f ./static/custom/templates/footer.html ]; then diff --git a/install_db.sh b/install_db.sh index aa6085d2..155ff85a 100755 --- a/install_db.sh +++ b/install_db.sh @@ -106,7 +106,7 @@ then echo "Création de la table exemple syntheseff" sudo -n -u postgres -s psql -d $db_name -c "CREATE TABLE synthese.syntheseff ( - id_synthese serial NOT NULL, + id_synthese serial PRIMARY KEY, id_organisme integer DEFAULT 2, cd_nom integer, insee character(5), @@ -115,14 +115,15 @@ then altitude_retenue integer, supprime boolean DEFAULT false, the_geom_point geometry('POINT',3857), - effectif_total integer + effectif_total integer, + diffusable boolean ); INSERT INTO synthese.syntheseff - (cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total) - VALUES (67111, 05122, 'Mon observateur', 1254, '0101000020110F0000B19F3DEA8636264124CB9EB2D66A5541', 3); + (cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusable) + VALUES (67111, 05122, 'Mon observateur', 1254, '0101000020110F0000B19F3DEA8636264124CB9EB2D66A5541', 3, true); INSERT INTO synthese.syntheseff - (cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total) - VALUES (67111, 05122, 'Mon observateur 3', 940, '0101000020110F00001F548906D05E25413391E5EE2B795541', 2);" &>> log/install_db.log + (cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusable) + VALUES (67111, 05122, 'Mon observateur 3', 940, '0101000020110F00001F548906D05E25413391E5EE2B795541', 2, true);" &>> log/install_db.log sudo -n -u postgres -s psql -d $db_name -c "ALTER TABLE synthese.syntheseff OWNER TO "$owner_atlas";" fi @@ -133,22 +134,38 @@ then cd data mkdir taxonomie cd taxonomie - wget https://raw.githubusercontent.com/PnX-SI/TaxHub/master/data/taxhubdb.sql - sudo -n -u postgres -s psql -d $db_name -f taxhubdb.sql &>> ../../log/install_db.log + wget https://raw.githubusercontent.com/PnX-SI/TaxHub/$taxhub_release/data/taxhubdb.sql + #sudo -n -u postgres -s psql -d $db_name -f taxhubdb.sql &>> ../../log/install_db.log + export PGPASSWORD=$owner_atlas_pass;psql -d $db_name -U $owner_atlas -h $db_host -f taxhubdb.sql &>> ../../log/install_db.log + wget http://geonature.fr/data/inpn/taxonomie/TAXREF_INPN_v9.0.zip unzip TAXREF_INPN_v9.0.zip -d /tmp - wget http://geonature.fr/data/inpn/taxonomie/ESPECES_REGLEMENTEES_20161103.zip - unzip ESPECES_REGLEMENTEES.zip -d /tmp - wget https://raw.githubusercontent.com/PnX-SI/TaxHub/master/data/inpn/data_inpn_v9_taxhub.sql + wget http://geonature.fr/data/inpn/taxonomie/ESPECES_REGLEMENTEES_20161103.zip + unzip ESPECES_REGLEMENTEES_20161103.zip -d /tmp + wget http://geonature.fr/data/inpn/taxonomie/LR_FRANCE_20160000.zip + unzip LR_FRANCE_20160000.zip -d /tmp + + wget https://raw.githubusercontent.com/PnX-SI/TaxHub/$taxhub_release/data/inpn/data_inpn_v9_taxhub.sql + # export PGPASSWORD=$owner_atlas_pass;psql -d $db_name -U $owner_atlas -h $db_host -f data_inpn_v9_taxhub.sql &>> ../../log/install_db.log sudo -n -u postgres -s psql -d $db_name -f data_inpn_v9_taxhub.sql &>> ../../log/install_db.log - wget https://raw.githubusercontent.com/PnX-SI/TaxHub/master/data/vm_hierarchie_taxo.sql - sudo -n -u postgres -s psql -d $db_name -f vm_hierarchie_taxo.sql &>> ../../log/install_db.log - wget https://raw.githubusercontent.com/PnX-SI/TaxHub/master/data/taxhubdata.sql - sudo -n -u postgres -s psql -d $db_name -f taxhubdata.sql &>> ../../log/install_db.log + + + wget https://raw.githubusercontent.com/PnX-SI/TaxHub/$taxhub_release/data/materialized_views.sql + #sudo -n -u postgres -s psql -d $db_name -f vm_hierarchie_taxo.sql &>> ../../log/install_db.log + export PGPASSWORD=$owner_atlas_pass;psql -d $db_name -U $owner_atlas -h $db_host -f materialized_views.sql &>> ../../log/install_db.log + + + wget https://raw.githubusercontent.com/PnX-SI/TaxHub/$taxhub_release/data/taxhubdata.sql + #sudo -n -u postgres -s psql -d $db_name -f taxhubdata.sql &>> ../../log/install_db.log + export PGPASSWORD=$owner_atlas_pass;psql -d $db_name -U $owner_atlas -h $db_host -f taxhubdata.sql &>> ../../log/install_db.log + + rm /tmp/*.txt rm /tmp/*.csv + rm /tmp/*.sql cd ../.. rm -R data/taxonomie + fi # Creation des Vues Matérialisées (et remplacement éventuel des valeurs en dur par les paramètres) diff --git a/main/configuration/config.py.sample b/main/configuration/config.py.sample index 351cb405..0a0ef2a6 100644 --- a/main/configuration/config.py.sample +++ b/main/configuration/config.py.sample @@ -24,6 +24,7 @@ NOM_APPLICATION = "Nom de l application" NOM_APPLICATION = unicode(NOM_APPLICATION, 'utf-8') # Fonction permettant d'encoder ce nom en utf-8, à ne pas modifier # URL de l'application depuis la racine du domaine +# ex "/atlas" pour une URL: http://mon-domaine/atlas OU "" si l'application est accessible à la racine du domaine URL_APPLICATION = "" # Code de suivi des statistiques Google Analytics (si AFFICHAGE_FOOTER = True) diff --git a/main/configuration/settings.ini.sample b/main/configuration/settings.ini.sample index 0a0a67fd..a2111e24 100644 --- a/main/configuration/settings.ini.sample +++ b/main/configuration/settings.ini.sample @@ -44,6 +44,11 @@ owner_atlas_pass=monpassachanger # Installer le schéma taxonomie de TaxHub dans la BDD de GeoNature-atlas ? install_taxonomie=false +# Version de TaxHub à utiliser pour installer le schéma taxonomie +# GeoNature-atlas 1.3.0 est compatible avec les versions de Taxhub inférieure ou égale à 1.3.2 +# Numéro de version conseillée et testée : 1.3.2 +taxhub_release=1.3.2 + # GeoNature-atlas est-il connecté à une BDD GeoNature ? geonature_source=true