initial commit

This commit is contained in:
Christophe Siraut 2021-03-26 09:11:10 +01:00
commit f45f5bb274
7 changed files with 480 additions and 0 deletions

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
GEONATURE_CITIZEN_TAG = 0.99.1-dev
.PHONY: start init
dev: init
docker image inspect geonature >/dev/null 2>&1 || docker build -f vendor/GeoNature-citizen/Dockerfile -t geonature
docker container inspect geonature >/dev/null 2>&1 || (\
docker run -it -d -p 8080:80 --name geonature geonature &&\
docker cp patches/settings.ini geonature:config/ &&\
docker cp patches/start.sh geonature:. &&\
#docker cp patches/install_app.sh geonature:install/ &&\
#docker cp patches/models.py geonature:backend/gncitizen/core/taxonomy/ &&\
#docker cp patches/tsconfig.server.json geonature:frontend/src/ &&\
docker exec -it geonature install/install_app.sh)
xdg-open http://localhost:8080
init: vendor/GeoNature-citizen
git submodule update --init --recursive
vendor/GeoNature-citizen:
-mkdir -p vendor
git submodule add https://github.com/Champs-Libres/GeoNature-citizen.git vendor/GeoNature-citizen
git commit -m "added submodule GeoNature-citizen"
#cd $@ && git checkout $(GEONATURE_CITIZEN_TAG)
doc:
cd vendor/GeoNature-citizen/docs && make html
xdg-open $(shell pwd)/vendor/GeoNature-citizen/docs/_build/html/index.html
clean:
docker stop geonature
docker rm geonature
docker volume prune

11
README Normal file
View File

@ -0,0 +1,11 @@
# gl-geonature
L'instance Geonature-Citizen de Champs-Libres.
Installation développeur :
$ make dev
Documentation :
$ make doc

253
patches/install_app.sh Executable file
View File

@ -0,0 +1,253 @@
#!/bin/bash
set -ex
cd $(dirname $(dirname "${BASH_SOURCE[0]:-$0}"))
DIR=$(pwd)
#création d'un fichier de configuration pour api/back
if [ ! -f config/settings.ini ]; then
echo 'Fichier de configuration du projet non existant, copie du template...'
cp config/settings.ini.template config/settings.ini
echo "Fichier de config disponible : $DIR."
echo "Merci de renseigner le fichier et de relancer la commande install_app.sh."
exit
fi
. config/settings.ini
#Installation de python / gunicorn / supervisor + dépendances
sudo apt update && sudo apt -y install python2.7 git gcc curl gunicorn python-setuptools lsb-release apt-transport-https wget
sudo apt -y install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev curl libbz2-dev
sudo apt -y install apache2 python-dev libpq-dev libgeos-dev supervisor unzip virtualenv libcurl4-openssl-dev libssl-dev
sudo apt -y install libglib2.0-0 libsm6 libxext6 libxrender-dev
RELEASE=$(cat /etc/os-release | grep VERSION_CODENAME |cut -d "=" -f2)
sudo apt install python3 python3-dev python3-pip -y
sudo apt-get clean
echo `python3 --version`
sudo service supervisor start && sudo supervisorctl stop all
#Maj de pip
pip3 install --upgrade pip
#Installation de nvm / npm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#cp -r ${HOME}/.nvm /home/synthese/.nvm
#chown -R synthese:synthese /home/synthese/.nvm
set +ex
cd ${DIR}/frontend
nvm install
echo `npm -v`
cd ${DIR}
set -ex
#Installation de taxhub
#if [ ! -d /home/synthese ]; then
#adduser --gecos "" --home /home/citizen citizen
#sudo passwd -d citizen
#adduser citizen sudo
#adduser citizen root
#adduser synthese www-data
#fi
cd $HOME
python3 -m pip install virtualenv==20.0.1 --user
sudo a2enmod rewrite proxy proxy_http
sudo apache2ctl restart
sudo apt-get install postgresql postgresql-client postgresql postgresql-postgis -y
sudo adduser postgres sudo
sudo service postgresql start
sudo -n -u postgres psql -c "CREATE ROLE $user_pg WITH PASSWORD '$user_pg_pass';"
sudo -n -u postgres psql -c "ALTER ROLE $user_pg WITH LOGIN;"
sudo -n -u postgres createdb -O $user_pg $pg_dbname -T template0 -E UTF-8
cd $HOME
if [ ! -d $HOME/taxhub ] && [ $install_taxhub ]; then
wget https://github.com/PnX-SI/TaxHub/archive/$taxhub_version.zip
unzip $taxhub_version.zip
mv TaxHub-$taxhub_version/ taxhub/
rm ${taxhub_version}.zip
fi
cd $HOME/taxhub
if [ ! -f settings.ini ]; then
cp settings.ini.sample settings.ini
fi
sed -i "s,db_host=.*$,db_host=$pg_host,g" settings.ini
sed -i "s,db_name=.*$,db_name=$pg_dbname,g" settings.ini
sed -i "s,user_pg=.*$,user_pg=$user_pg,g" settings.ini
sed -i "s,user_pg_pass=.*$,user_pg_pass=$user_pg_pass,g" settings.ini
sed -i "s,db_port=.*$,db_port=$pg_port,g" settings.ini
sed -i "s,usershub_release=.*$,usershub_release=2.1.3,g" settings.ini
sudo printf "
<Location /taxhub> \n
ProxyPass http://127.0.0.1:5000/ retry=0 \n
ProxyPassReverse http://127.0.0.1:5000/ \n
</Location> \n
\n
Alias '/static' 'HOME_PATH/taxhub/static' \n
<Directory 'HOME_PATH/taxhub/static'> \n
AllowOverride None \n
Order allow,deny \n
Allow from all \n
</Directory> \n
" | sed "s,HOME_PATH,$HOME,g" | sudo tee /etc/apache2/sites-available/taxhub.conf
sudo printf '
RewriteEngine on \n
RewriteRule "taxhub$" "taxhub/" [R] \n
' | sudo tee /etc/apache2/sites-available/000-default.conf
sudo a2ensite taxhub.conf
sudo apache2ctl restart
cd $HOME/taxhub
mkdir -p var/log
mkdir -p $DIR/var/log
touch $DIR/var/log/api_geonature-errors.log
mkdir -p /tmp/taxhub/
mkdir -p /tmp/usershub/
sudo chown -R $(whoami) $HOME/taxhub
sudo chown -R $(whoami) /tmp/taxhub
sudo chown -R $(whoami) /tmp/usershub
#sed -i "s,nano.*$,#,g" install_db.sh
#sed -i "s,PnEcrins,PnX-SI,g" install_db.sh
sed -i "s,^nano,," install_db.sh
./install_db.sh
./install_app.sh
cd $DIR
. config/settings.ini
sudo -u postgres psql $pg_dbname -c 'create extension postgis;'
if [ ! -f config/default_config.toml ]; then
echo 'Fichier de configuration API non existant, copie du template...'
cp config/default_config.toml.template config/default_config.toml
sed -i "s/SQLALCHEMY_DATABASE_URI = .*$/SQLALCHEMY_DATABASE_URI = \"postgresql:\/\/$user_pg:$user_pg_pass@$pg_host:$pg_port\/$pg_dbname\"/" config/default_config.toml
sed -i "s,URL_APPLICATION = .*$,URL_APPLICATION = \"$url_application\",g" config/default_config.toml
sed -i "s,API_ENDPOINT = .*$,API_ENDPOINT = \"$api_endpoint\",g" config/default_config.toml
sed -i "s,API_PORT = .*$,API_PORT = \"$api_port\",g" config/default_config.toml
sed -i "s,API_TAXHUB = .*$,API_TAXHUB = \"$api_taxhub\",g" config/default_config.toml
fi
sudo -u postgres psql -c 'CREATE SCHEMA taxonomie AUTHORIZATION dbuser' dbname
#Création d'un fichier de configuration pour le front
cd frontend
if [ ! -f src/conf/app.config.ts ]; then
echo 'Fichier de configuration frontend non existant, copie du template...'
cp src/conf/app.config.ts.template src/conf/app.config.ts
sed -i "s|API_ENDPOINT:.*$|API_ENDPOINT:\"$api_endpoint\",|g" src/conf/app.config.ts
sed -i "s|API_TAXHUB:.*$|API_TAXHUB:\"$api_taxhub\",|g" src/conf/app.config.ts
sed -i "s|URL_APPLICATION:.*$|URL_APPLICATION:\"$url_application\",|g" src/conf/app.config.ts
fi
if [ ! -f src/conf/map.config.ts ]; then
echo 'Fichier map non existant, copie du template...'
cp src/conf/map.config.ts.template src/conf/map.config.ts
fi
#Copie des fichiers custom
if [ ! -f src/custom/custom.css ]; then
echo 'Fichier custom.css non existant, copie du template...'
cp src/custom/custom.css.template src/custom/custom.css
fi
if [ ! -f src/custom/about/about.css ]; then
echo 'Fichiers about non existant, copie du template...'
cp src/custom/about/about.css.template src/custom/about/about.css
cp src/custom/about/about.html.template src/custom/about/about.html
fi
if [ ! -f src/custom/footer/footer.css ]; then
echo 'Fichiers footer non existant, copie du template...'
cp src/custom/footer/footer.css.template src/custom/footer/footer.css
cp src/custom/footer/footer.html.template src/custom/footer/footer.html
fi
if [ ! -f src/custom/home/home.css ]; then
echo 'Fichiers footer non existant, copie du template...'
cp src/custom/home/home.css.template src/custom/home/home.css
cp src/custom/home/home.html.template src/custom/home/home.html
fi
#Install and build
export NG_CLI_ANALYTICS=ci # Désactive le prompt pour angular metrics
URL=`echo $my_url |sed 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'`
echo "L'application sera disponible à l'url $my_url"
nvm use
npm install
# Installation de la conf
sudo cp ../install/supervisor/gncitizen_frontssr-service.conf /etc/supervisor/conf.d/
sudo sed -i "s%APP_PATH%${DIR}%" /etc/supervisor/conf.d/gncitizen_frontssr-service.conf
sudo sed -i "s%SYSUSER%$(whoami)%" /etc/supervisor/conf.d/gncitizen_frontssr-service.conf
sudo cp ../install/apache/gncitizen.conf /etc/apache2/sites-available/gncitizen.conf
if [ ${backoffice_password:=MotDePasseAChanger} = MotDePasseAChanger ]; then
backoffice_password=$(date +%s | sha256sum | base64 | head -c 30 ; echo)
fi
echo "Backoffice password
===================
url: (${URL}/api/admin)
username: ${backoffice_username:=citizen}
password: ${backoffice_password}" > ${DIR}/config/backoffice_access
htpasswd -b -c ${DIR}/config/backoffice_htpasswd ${backoffice_username} ${backoffice_password}
sudo sed -i "s%APP_PATH%${DIR}%" /etc/apache2/sites-available/gncitizen.conf
sudo sed -i "s%mydomain.net%${URL}%" /etc/apache2/sites-available/gncitizen.conf
sudo sed -i "s%backoffice_username%${backoffice_username}%" /etc/apache2/sites-available/gncitizen.conf
if [ $server_side = "true" ]; then
echo "Build server side project"
npm run build:i18n-ssr
else
echo "Build initial du projet"
npm run build
fi
cd ..
# Création du venv
venv_path=$DIR/backend/${venv_dir:-"venv"}
if [ ! -f $venv_path/bin/activate ]; then
python3 -m virtualenv $venv_path
fi
source $venv_path/bin/activate
pip install --upgrade pip
pip install -r backend/requirements.txt
deactivate
# Copy main medias to media
mkdir -p $DIR/media
cp -r $DIR/frontend/src/assets/* $DIR/media
touch init_done
#Création de la conf supervisor
sudo cp install/supervisor/gncitizen_api-service.conf /etc/supervisor/conf.d/
sudo sed -i "s%APP_PATH%${DIR}%" /etc/supervisor/conf.d/gncitizen_api-service.conf
sudo sed -i "s%SYSUSER%$(whoami)%" /etc/supervisor/conf.d/gncitizen_api-service.conf
# Prise en compte de la nouvelle config Apache
sudo a2ensite gncitizen.conf
sudo apache2ctl restart
# Prise en compte de la nouvelle config Supervisor
sudo supervisorctl reread
sudo supervisorctl reload
echo "install municipalities"
./data/ref_geo.sh
echo "End of installation
You can now access to GeoNature-citizen at ${my_url}
Backoffice access informations are stored in ${DIR}/config/backoffice_access as follows:
"
cat ${DIR}/config/backoffice_access

118
patches/models.py Normal file
View File

@ -0,0 +1,118 @@
from sqlalchemy import ForeignKey
from gncitizen.utils.sqlalchemy import serializable
from server import db
@serializable
class BibNoms(db.Model):
__tablename__ = "bib_noms"
__table_args__ = {"schema": "taxonomie", "extend_existing": True}
id_nom = db.Column(db.Integer, primary_key=True)
cd_nom = db.Column(db.Integer, nullable=True, unique=True)
cd_ref = db.Column(db.Integer, unique=True)
nom_francais = db.Column(db.Unicode)
comments = db.Column(db.Unicode)
@serializable
class BibListes(db.Model):
__tablename__ = "bib_listes"
__table_args__ = {"schema": "taxonomie", "extend_existing": True}
id_liste = db.Column(db.Integer, primary_key=True)
nom_liste = db.Column(db.Unicode)
desc_liste = db.Column(db.Text)
picto = db.Column(db.Unicode)
regne = db.Column(db.Unicode)
group2_inpn = db.Column(db.Unicode)
# cnl = db.relationship("CorNomListe", lazy='select')
def __repr__(self):
return "<BibListes %r>" % self.nom_liste
@serializable
class CorNomListe(db.Model):
__tablename__ = "cor_nom_liste"
__table_args__ = {"schema": "taxonomie", "extend_existing": True}
id_liste = db.Column(
db.Integer,
ForeignKey("taxonomie.bib_listes.id_liste"),
nullable=False,
primary_key=True,
)
id_nom = db.Column(
db.Integer,
ForeignKey("taxonomie.bib_noms.id_nom"),
nullable=False,
primary_key=True,
)
bib_nom = db.relationship("BibNoms")
bib_liste = db.relationship("BibListes")
def __repr__(self):
return "<CorNomListe %r>" % self.id_liste
# listes = db.relationship("CorNomListe", lazy='select')
# medias = db.relationship("TMedias", lazy='select')
#
@serializable
class TMedias(db.Model):
__tablename__ = "t_medias"
__table_args__ = {"schema": "taxonomie", "extend_existing": True}
id_media = db.Column(db.Integer, primary_key=True)
cd_ref = db.Column(
db.Integer,
ForeignKey("taxonomie.bib_noms.cd_ref"),
nullable=False,
primary_key=False,
)
titre = db.Column(db.Unicode)
url = db.Column(db.Unicode)
chemin = db.Column(db.Unicode)
auteur = db.Column(db.Unicode)
desc_media = db.Column(db.Text)
is_public = db.Column(db.BOOLEAN)
supprime = db.Column(db.BOOLEAN)
id_type = db.Column(db.Integer)
source = db.Column(db.Text)
licence = db.Column(db.Text)
def __repr__(self):
return "<TMedias %r>" % self.titre
@serializable
class Taxref(db.Model):
__tablename__ = "taxref"
__table_args__ = {"schema": "taxonomie"}
cd_nom = db.Column(db.Integer, primary_key=True)
id_statut = db.Column(db.Unicode)
id_habitat = db.Column(db.Integer)
id_rang = db.Column(db.Unicode)
regne = db.Column(db.Unicode)
phylum = db.Column(db.Unicode)
classe = db.Column(db.Unicode)
ordre = db.Column(db.Unicode)
famille = db.Column(db.Unicode)
sous_famille = db.Column(db.Unicode)
tribu = db.Column(db.Unicode)
cd_taxsup = db.Column(db.Integer)
cd_sup = db.Column(db.Integer)
cd_ref = db.Column(db.Integer)
lb_nom = db.Column(db.Unicode)
lb_auteur = db.Column(db.Unicode)
nom_complet = db.Column(db.Unicode)
nom_complet_html = db.Column(db.Unicode)
nom_vern = db.Column(db.Unicode)
nom_valide = db.Column(db.Unicode)
nom_vern_eng = db.Column(db.Unicode)
group1_inpn = db.Column(db.Unicode)
group2_inpn = db.Column(db.Unicode)
url = db.Column(db.Unicode)
def __repr__(self):
return "<Taxref %r>" % self.nom_complet

48
patches/settings.ini Normal file
View File

@ -0,0 +1,48 @@
# 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
# My host URL or IP with / at the end
my_url=http://localhost:8080/
url_application=http://localhost:8080/ # Url For the frontend
api_endpoint=http://localhost:8080/api # Url for the geonature api don't forget /api
api_port=5002
api_taxhub=http://localhost/taxhub/api/ # Url for the taxhub api
install_taxhub=1
taxhub_version=1.7.3
# Configuration front
server_side=true # Server side rendering heavy recommanded
# BackOffice admin passsword
admin_password=MotDePasseAChanger
################################
### CONFIGURATION PostgreSQL ###
################################
# Localisation du server PostgreSQL.
# Les scripts d'installation automatique ne fonctionnent que si votre BDD est sur le même serveur (localhost)
pg_host=localhost
# Port sur lequel PostgreSQL ecoute
pg_port=5432
#Base de donnée Geonature
pg_dbname=dbname
# Nom de l'utilisateur propriétaire des bases UsersHub, GeoNature, TaxHub
user_pg=dbuser
# Pass de l'utilisateur propriétaire des bases UsersHub, GeoNature, TaxHub
user_pg_pass=dbpwd
#########################
### Gunicorn settings ###
#########################
app_name=gncitizen
gun_num_workers=2
gun_host=localhost
gun_port=5002
gun_timeout=30

7
patches/start.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
set -e
sudo /etc/init.d/postgresql start
sudo /etc/init.d/apache2 start
test -f /var/run/supervisor.* && sudo rm /var/run/supervisor.*
sudo /etc/init.d/supervisor start

View File

@ -0,0 +1,11 @@
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"outDir": "../out-tsc/app-server",
"baseUrl": ".",
"module": "commonjs"
},
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}