Split into docker containers

This commit is contained in:
Marc Ducobu
2021-05-31 15:42:58 +02:00
parent eac9028900
commit 53ae96e0a9
21 changed files with 1557 additions and 8 deletions

29
patches/taxhub/config.py Normal file
View File

@@ -0,0 +1,29 @@
'''
TaxHub global settings file
'''
# Database settings
SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@db/referentielsdb"
SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG=True
SESSION_TYPE = 'filesystem'
SECRET_KEY = 'super secret key'
COOKIE_EXPIRATION = 3600
COOKIE_AUTORENEW = True
# File
import os
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
UPLOAD_FOLDER = 'static/medias'
# Authentification crypting method (hash or md5)
PASS_METHOD='hash'
# ID APPLICATION TaxHub
# User in the authentification submodule to avoid token conflict between app on the same server
ID_APP = 2

View File

@@ -0,0 +1,144 @@
#!/bin/bash
# Make sure only root can run our script
if [ "$(id -u)" == 0 ]; then
echo "This script must not be run as root" 1>&2
exit 1
fi
#Création des répertoires systèmes
. create_sys_dir.sh
create_sys_dir
if [ ! -f settings.ini ]; then
cp settings.ini.sample settings.ini
fi
# nano settings.ini
#include user config = settings.ini
. settings.ini
#get app path
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
LOG_DIR=$DIR/var/log
function database_exists () {
# /!\ Will return false if psql can't list database. Edit your pg_hba.conf
# as appropriate.
if [ -z $1 ]
then
# Argument is null
return 0
else
# Grep db name in the list of database
sudo -u postgres -s -- psql -tAl | grep -q "^$1|"
return $?
fi
}
if database_exists $db_name
then
if $drop_apps_db
then
echo "Suppression de la base..."
sudo -u postgres -s dropdb $db_name
else
echo "La base de données existe et le fichier de settings indique de ne pas la supprimer."
fi
fi
if ! database_exists $db_name
then
echo "Création de la base..."
sudo -u postgres -s createdb -O $user_pg $db_name
sudo -n -u postgres -s psql -d $db_name -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" &> $LOG_DIR/installdb/install_db.log
sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' &>> $LOG_DIR/installdb/install_db.log
sudo -n -u postgres -s psql -d $db_name -c 'CREATE EXTENSION IF NOT EXISTS "pg_trgm";' &>> $LOG_DIR/installdb/install_db.log
# Mise en place de la structure de la base et des données permettant son fonctionnement avec l'application
echo "Création de la structure de la base..."
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/taxhubdb.sql &> $LOG_DIR/installdb/install_db.log
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/generic_drop_and_restore_deps_views.sql &> $LOG_DIR/installdb/install_db.log
echo "Décompression des fichiers du taxref..."
array=( TAXREF_INPN_v13.zip ESPECES_REGLEMENTEES_v11.zip LR_FRANCE_20160000.zip BDC_STATUTS_13.zip)
for i in "${array[@]}"
do
if [ ! -f '/tmp/taxhub/'$i ]
then
wget http://geonature.fr/data/inpn/taxonomie/$i -P /tmp/taxhub
unzip /tmp/taxhub/$i -d /tmp/taxhub
else
echo $i exists
fi
done
echo "Insertion des données taxonomiques de l'inpn... (cette opération peut être longue)"
cd $DIR
sudo -u postgres -s psql -d $db_name -f data/inpn/data_inpn_taxhub.sql &>> $LOG_DIR/installdb/install_db.log
echo "Création de la vue représentant la hierarchie taxonomique..."
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/materialized_views.sql &>> $LOG_DIR/installdb/install_db.log
echo "Insertion de données de base"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/taxhubdata.sql &>> $LOG_DIR/installdb/install_db.log
echo "Insertion de fonctions génériques de détection de vues dépendantes"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/generic_drop_and_restore_deps_views.sql &>> $LOG_DIR/installdb/install_db.log
if $insert_geonatureatlas_data
then
echo "Insertion de données nécessaires à GeoNature-atlas"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/taxhubdata_atlas.sql &>> $LOG_DIR/installdb/install_db.log
fi
if $insert_attribut_example
then
echo "Insertion d'un exemple d'attribut"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/taxhubdata_example.sql &>> $LOG_DIR/installdb/install_db.log
fi
if $insert_taxons_example
then
echo "Insertion de 8 taxons exemple"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/taxhubdata_taxons_example.sql &>> $LOG_DIR/installdb/install_db.log
fi
if [ $users_schema = "local" ]
then
echo "Création du schéma Utilisateur..."
wget https://raw.githubusercontent.com/PnX-SI/UsersHub/$usershub_release/data/usershub.sql -P /tmp
wget https://raw.githubusercontent.com/PnX-SI/UsersHub/$usershub_release/data/usershub-data.sql -P /tmp
wget https://raw.githubusercontent.com/PnX-SI/UsersHub/$usershub_release/data/usershub-dataset.sql -P /tmp
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f /tmp/usershub.sql &>> $LOG_DIR/installdb/install_db.log
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f /tmp/usershub-data.sql &>> $LOG_DIR/installdb/install_db.log
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f /tmp/usershub-dataset.sql &>> $LOG_DIR/installdb/install_db.log
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -f data/adds_for_usershub.sql &>> $LOG_DIR/installdb/install_db.log
else
echo "Connexion à la base Utilisateur..."
cp data/create_fdw_utilisateurs.sql /tmp/taxhub/create_fdw_utilisateurs.sql
cp data/grant.sql /tmp/taxhub/grant.sql
sed -i "s#\$user_pg#$user_pg#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_host#$usershub_host#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_db#$usershub_db#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_port#$usershub_port#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_user#$usershub_user#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_pass#$usershub_pass#g" /tmp/taxhub/create_fdw_utilisateurs.sql
sed -i "s#\$usershub_user#$usershub_user#g" /tmp/taxhub/grant.sql
sudo -u postgres -s psql -d $db_name -f /tmp/taxhub/create_fdw_utilisateurs.sql &>> $LOG_DIR/installdb/install_db.log
sudo -u postgres -s psql -d $db_name -f /tmp/taxhub/grant.sql &>> $LOG_DIR/installdb/install_db.log
fi
# Vaccum database
echo "Vaccum database ... (cette opération peut être longue)"
export PGPASSWORD=$user_pg_pass;psql -h $db_host -U $user_pg -d $db_name -c "VACUUM FULL VERBOSE;" &>> $LOG_DIR/installdb/install_db.log
fi

65
patches/taxhub/server.py Normal file
View File

@@ -0,0 +1,65 @@
# coding: utf8
from flask import Flask
from flask_cors import CORS
from apptax.database import db
db = db
app_globals = {}
def init_app():
if app_globals.get('app', False):
app = app_globals['app']
else:
app = Flask(__name__)
with app.app_context():
app.config.from_pyfile('config.py')
db.init_app(app)
db.app = app
app.config['DB'] = db
@app.teardown_request
def _manage_transaction(exception):
if exception:
db.session.rollback()
else:
db.session.commit()
db.session.remove()
from pypnusershub import routes
app.register_blueprint(routes.routes, url_prefix='/api/auth')
from apptax.index import routes
app.register_blueprint(routes, url_prefix='/')
from apptax.taxonomie.routesbibnoms import adresses
app.register_blueprint(adresses, url_prefix='/api/bibnoms')
from apptax.taxonomie.routestaxref import adresses
app.register_blueprint(adresses, url_prefix='/api/taxref')
from apptax.taxonomie.routesbibattributs import adresses
app.register_blueprint(adresses, url_prefix='/api/bibattributs')
from apptax.taxonomie.routesbiblistes import adresses
app.register_blueprint(adresses, url_prefix='/api/biblistes')
from apptax.taxonomie.routestmedias import adresses
app.register_blueprint(adresses, url_prefix='/api/tmedias')
from apptax.taxonomie.routesbibtypesmedia import adresses
app.register_blueprint(adresses, url_prefix='/api/bibtypesmedia')
from apptax.utils.routesconfig import adresses
app.register_blueprint(adresses, url_prefix='/api/config')
return app
app = init_app()
CORS(app, supports_credentials=True)
if __name__ == '__main__':
app.run(host="0.0.0.0", debug=True)

View File

@@ -0,0 +1,74 @@
##########################################
###### TAXHUB installation settings ######
##########################################
app_name=taxhub
#######################
### Python settings ###
#######################
venv_dir=venv
python_path=/usr/bin/python3
###########################
### PostgreSQL settings ###
###########################
# Drop eventual existing database during installation
drop_apps_db=false
# DB host
db_host=db
# PostgreSQL port
db_port=5432
# Database name
db_name=referentielsdb
# Database owner username
user_pg=postgres
# Database owner password
user_pg_pass=postgres
### Users schema localisation
# Possible values : 'local' or 'foreign'
# 'local' means that the 'utilisateurs' schema has to be installed in TaxHub database.
# 'foreign' means that the 'utilisateurs' schema is in another database. An FDW schema will be created on it.
# Nota : foreign requires UsersHub to be already installed
usershub_release=2.1.1
users_schema=local
### UsersHub relation settings - Required if users_schema=foreign
usershub_host=db
usershub_db=referentielsdb
usershub_port=5432
usershub_user=postgres
usershub_pass=postgres
###############
### Options ###
###############
# Insert GeoNature-atlas data (theme & attributs)
insert_geonatureatlas_data=true
# Insert an example of attribute (Migrateur)
insert_attribut_example=false
# Insert 8 examples of taxons and add it to the Occtax list
insert_taxons_example=true
#########################
### Gunicorn settings ###
#########################
gun_num_workers=4
gun_host=0.0.0.0
gun_port=5000