#35 use gunicorn for running the backend in production

This commit is contained in:
nobohan 2022-07-11 16:32:41 +02:00
parent 7d5d821bae
commit 66f818e54f
4 changed files with 60 additions and 5 deletions

View File

@ -38,13 +38,16 @@ services:
image: registry.gitlab.com/champs-libres/geonature-citizen/back image: registry.gitlab.com/champs-libres/geonature-citizen/back
volumes: volumes:
- ./vendor/GeoNature-citizen/backend/gncitizen/:/home/appuser/citizen/backend/gncitizen/ - ./vendor/GeoNature-citizen/backend/gncitizen/:/home/appuser/citizen/backend/gncitizen/
- ./vendor/GeoNature-citizen/backend/var/log/:/home/appuser/citizen/backend/var/log/
- ./patches/settings.ini:/home/appuser/citizen/config/settings.ini - ./patches/settings.ini:/home/appuser/citizen/config/settings.ini
- ./patches/settings.ini:/home/appuser/citizen/backend/config/settings.ini
- ./patches/back/default_config.toml:/home/appuser/citizen/config/default_config.toml - ./patches/back/default_config.toml:/home/appuser/citizen/config/default_config.toml
- ./patches/back/start_gunicorn.sh:/home/appuser/citizen/backend/start_gunicorn.sh
- ./patches/back/wsgi.py:/home/appuser/citizen/backend/wsgi.py - ./patches/back/wsgi.py:/home/appuser/citizen/backend/wsgi.py
- ./patches/back/server.py:/home/appuser/citizen/backend/server.py - ./patches/back/server.py:/home/appuser/citizen/backend/server.py
ports: ports:
- "5002:5002" - "5002:5002"
command: python wsgi.py command: bash start_gunicorn.sh
taxhub: taxhub:
build: build:
dockerfile: ./Dockerfile-taxhub dockerfile: ./Dockerfile-taxhub
@ -57,7 +60,9 @@ services:
- ./patches/taxhub/server.py:/home/appuser/taxhub/server.py - ./patches/taxhub/server.py:/home/appuser/taxhub/server.py
- ./patches/taxhub/install_db.sh:/home/appuser/taxhub/install_db.sh - ./patches/taxhub/install_db.sh:/home/appuser/taxhub/install_db.sh
- ./patches/taxhub/settings.ini:/home/appuser/taxhub/settings.ini - ./patches/taxhub/settings.ini:/home/appuser/taxhub/settings.ini
command: python server.py - ./patches/taxhub/gunicorn_start.sh:/home/appuser/taxhub/gunicorn_start.sh
- ./vendor/TaxHub/var/log/:/home/appuser/taxhub/var/log/
command: bash gunicorn_start.sh
media: media:
build: build:

30
patches/back/start_gunicorn.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
echo "------------------------------------------------"
echo "GeoNature-citizen backend server is starting ..."
echo "------------------------------------------------"
FLASKDIR=$(readlink -e "${0%/*}")
APP_DIR="$(dirname "$FLASKDIR")"
. $APP_DIR/config/settings.ini
echo "info: Starting $app_name"
echo "info: FLASKDIR: $FLASKDIR"
echo "info: APP_DIR: $APP_DIR"
# Start your gunicorn
LOG_DIR="$APP_DIR/var/log"
echo "LOG_DIR: $LOG_DIR"
if [[ ! -e $LOG_DIR ]]; then
mkdir -p $LOG_DIR
elif [[ ! -d $LOG_DIR ]]; then
echo "LOG_DIR already exists but is not a directory" 1>&2
fi
export PYTHONPATH=`pwd`/${venv_dir}
#echo $PYTHONPATH
echo "info: Starting gunicorn"
echo "--"
exec gunicorn -w ${gun_num_workers:-2} --error-log $APP_DIR/var/log/gunicorn_gncitizen_errors.log --pid="${app_name:-"gncitizen"}.pid" -b ${gun_host:-"0.0.0.0"}:${gun_port:-5002} --timeout=${gun_timeout:-30} --reload -n "geonature-citizen" wsgi:app

View File

@ -1,5 +1,5 @@
# Langue du serveur # Langue du serveur
# valeur possible : fr_FR.UTF-8, en_US.utf8 # valeur possible : fr_FR.UTF-8, en_US.utf8
# locale -a pour voir la liste des locales disponible # locale -a pour voir la liste des locales disponible
my_local=fr_FR.UTF-8 my_local=fr_FR.UTF-8
@ -25,7 +25,7 @@ admin_password=MotDePasseAChanger
################################ ################################
# Localisation du server PostgreSQL. # Localisation du server PostgreSQL.
# Les scripts d'installation automatique ne fonctionnent que si votre BDD est sur le même serveur (localhost) # Les scripts d'installation automatique ne fonctionnent que si votre BDD est sur le même serveur (localhost)
pg_host=db pg_host=db
# Port sur lequel PostgreSQL ecoute # Port sur lequel PostgreSQL ecoute
@ -43,6 +43,6 @@ user_pg_pass=postgres
app_name=gncitizen app_name=gncitizen
gun_num_workers=2 gun_num_workers=2
gun_host=localhost gun_host=0.0.0.0
gun_port=5002 gun_port=5002
gun_timeout=30 gun_timeout=30

View File

@ -0,0 +1,20 @@
#!/bin/bash
FLASKDIR=$(readlink -e "${0%/*}")
APP_DIR="$(dirname "$FLASKDIR")"
echo "Starting $app_name"
echo "$FLASKDIR"
echo "$APP_DIR"
. "$APP_DIR"/settings.ini
# # activate the virtualenv
# cd $FLASKDIR/$venv_dir
# source bin/activate
# export PYTHONPATH=$FLASKDIR:$PYTHONPATH
# Start your unicorn
exec gunicorn server:app --access-logfile $APP_DIR/var/log/taxhub-access.log --pid="${app_name}.pid" --error-log $APP_DIR/var/log/taxhub-errors.log -w "${gun_num_workers}" -b "${gun_host}:${gun_port}" -n "${app_name}"