Intranet de la Rez Flask web app

Related tags

Flaskintrarez
Overview

IntraRez

Application Flask de l'Intranet de la Rez.

Exigences

  • Python : Probablement >= 3.10 à terme, pour l'instant >= 3.8 suffit ;
  • Autres packages Linux : mysql-server postfix git, plus pour le déploiement : supervisor nginx ;
  • Packages Python : Voir requirements.txt, plus pour le déploiement : gunicorn pymysql cryptography ;
  • Pour le déploiement : un utilisateur Linux intrarez dédié.

Installation

Je reprends pour l'essentiel le déploiement conseillé dans le tutoriel : https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux

  • Installer l'application :

    cd /home/intrarez
    git clone https://github.com/GRI-ESPCI/intrarez
    cd intrarez
    python3 -m venv env
    source env/bin/activate
    pip install -r requirements.txt
    pip install gunicorn pymysql cryptography
    cp .conf_models/model.env .env
    
  • Créer et initialiser la base de données MySQL :

    sudo mysql -u root
    
    CREATE DATABASE intrarez CHARACTER SET utf8 COLLATE utf8_bin;
    CREATE USER 'intrarez'@'localhost' IDENTIFIED BY '<mdp-db>';
    GRANT ALL PRIVILEGES ON intrarez.* TO 'intrarez'@'localhost';
    FLUSH PRIVILEGES;
    QUIT;
    flask db upgrade
    
  • Modifier le fichier .env créé depuis le modèle. Pour générer une SECRET_KEY aléatoire :

    python3 -c "import uuid; print(uuid.uuid4().hex)"
    
  • Enregistrer l'application dans les variables d'environment :

    echo "export FLASK_APP=intrarez.py" >> ~/.profile
    
  • Compiler les traductions (fichiers binaires) :

    flask translate compile
    

L'application peut alors normalement être lancée avec flask run.

On a alors une version de développement installée : flask run n'est pas approprié à de la production (peu optimisé), et il faut configurer l'accès depuis l'extérieur (même si c'est un extérieur interne, dans notre cas).

Passage en production

On utilise Gunicorn en interne : le serveur Python n'est pas accessible de l'extérieur, c'est Nginx qui lui servira les requêtes non-statiques.

Gunicorn est lancé et contrôlé par Supervisor, qui fait à peu près le travail d'un service mais en plus pratique :

sudo cp .conf_models/supervisor.conf /etc/supervisor/conf.d/intrarez.conf
sudo supervisorctl reload

Le nombre de workers de Gunicorn (le -w 4 dans le fichier de conf) peut être adapté selon la machine.

Configuration de Nginx :

sudo cp .conf_models/nginx.conf /etc/nginx/sites-enabled/intrarez
sudo service nginx reload

Note : pour l'instant, l'application est configurée pour ne fonctionner qu'en HTTP, pas en HTTPS (problèmes de certificats en réseau interne).

Il faudra tester et voir ce qui marche mieux en terme d'avertissements des navigateurs et autres entre ça et un certificat auto-host : voir .conf_models/nginx.conf, avec

mkdir certs
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
  -keyout certs/key.pem -out certs/cert.pem

Compliqué d'avoir un vrai certificat, parce qu'il faut un nom de domaine associé, mais si on veut mettre des services accessibles depuis l'extérieur ce sera une étape obligée.

Mise à jour

Pour mettre à jour l'application, dans le dossier intrarez :

git pull
source env/bin/activate
supervisorctl stop intrarez
flask db upgrade
flask translate compile
sudo supervisorctl start intrarez

(côté développement, voir plus bas)

Notes de développement

Je vais ici noter pas à pas ce que je fais, pour simplifier au maximum l'appréhension du code par d'éventuels GRI futurs.

Début de l'installation

11/09/2021 - Loïc 137

Tout a été créé en suivant ce tutoriel : https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

Requirements : je pars sur Python 3.10, parce que le nouveau statement match me fait beaucoup trop de l'oeil.

À ce jour, Python 3.10 n'est disponible qu'en version release candidate 2 (donc quasiment finale), et devrait sortir début octobre (donc avant la release de l'IntraRez).

Installation propre de plusieurs versions de Python sur un même OS : https://hackersandslackers.com/multiple-python-versions-ubuntu-20-04

Installation d'un virtual env fresh

Utilisation de SQLAlchemy 1.4 (2.x pas prêt)

Gestion des migrations de db : lors du développement d'une nouvelle version modifiant le modèle de données,

  • En local : flask db migrate -m "Migration to <version>" ;
  • Vérifier le fichier créé dans migrations/versions ;
  • flask db upgrade pour appliquer localement ;
  • (autres modifs hors db)
  • Release de la version ;
  • En prod : pull puis flask db upgrade.

Je pars sur une structure en modules (basée sur les blueprints Flask), détaillée au chapitre XV du tuto : https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xv-a-better-application-structure

Application bilingue (utilisant Flask-Babel) : lorsque le code est modifié,

  • Exécuter flask translate update ;
  • Modifier/ajouter les clés de traduction dans app/translations/en/LC_MESSAGES/messages.po. Les entrées modifiées sont indiquées avec #, fuzzy : supprimer ce commentaire après avoir vérifié qu'il n'y avait pas d'erreur / modifié la traduction ;
  • Exécuter flask translate compile.
You might also like...
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Flask Project Template A full feature Flask project template.

Flask Project Template A full feature Flask project template. See also Python-Project-Template for a lean, low dependency Python app. HOW TO USE THIS

A Fast API style support for Flask. Gives you MyPy types with the flexibility of flask
A Fast API style support for Flask. Gives you MyPy types with the flexibility of flask

Flask-Fastx Flask-Fastx is a Fast API style support for Flask. It Gives you MyPy types with the flexibility of flask. Compatibility Flask-Fastx requir

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Flask-Discord-Bot-Dashboard - A simple discord Bot dashboard created in Flask Python
Flask-Discord-Bot-Dashboard - A simple discord Bot dashboard created in Flask Python

Flask-Discord-Bot-Dashboard A simple discord Bot dashboard created in Flask Pyth

Open-source Flask Sample built on top of flask-dance library
Open-source Flask Sample built on top of flask-dance library

Open-source Flask Sample built on top of flask-dance library. The project implements the social login for Github and Twitter - Originally coded by TestDriven.IO.

Flask-redmail - Email sending for Flask

Flask Red Mail: Email Sending for Flask Flask extension for Red Mail What is it?

Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications.

Flask Sitemapper Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications. This allows you to create a nice and

Comments
  • Ban is not terminated when a subscription is taken

    Ban is not terminated when a subscription is taken

    Cause: Ban termination is done in scripts/update_sub_states, which never detects new subscriptions as the sub state is instantly changed when subing.

    Solution: Add ban termination in subscription validation

    bug 
    opened by loic-simon 0
Geometry Dash Song Bypass with Python Flask Server

Geometry Dash Song Bypass with Python Flask Server

pixelsuft‮ 1 Nov 16, 2021
A simple way to demo Flask apps from your machine.

flask-ngrok A simple way to demo Flask apps from your machine. Makes your Flask apps running on localhost available over the internet via the excellen

117 Dec 27, 2022
A gRpc server like Flask (像Flask一样的gRpc服务)

Mask A gRpc server just like Flask. Install Mask support pypi packages, you can simply install by: pip install mask Document Mask manual could be fou

吴东 16 Jun 14, 2022
Flaskr: Intro to Flask, Test-Driven Development (TDD), and JavaScript

Flaskr - Intro to Flask, Test-Driven Development, and JavaScript Share on Twitter As many of you know, Flaskr -- a mini-blog-like-app -- is the app th

Michael Herman 2.2k Jan 04, 2023
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
a flask profiler which watches endpoint calls and tries to make some analysis.

Flask-profiler version: 1.8 Flask-profiler measures endpoints defined in your flask application; and provides you fine-grained report through a web in

Mustafa Atik 718 Dec 20, 2022
The Snoopy boilerplate in flask framework for development enterprise application.

Snoopy What is snoopy! The "Snoopy" boilerplate in flask framework for development enterprise application. Motivation In my 10 years of development ex

Bekhzod 2 Sep 29, 2022
Beautiful Interactive tables in your Flask templates.

flask-tables Beautiful interactive tables in your Flask templates Resources Video demonstration: Go to YouTube video. Learn how to use this code: Go t

Miguel Grinberg 209 Jan 05, 2023
Flask Project Template A full feature Flask project template.

Flask Project Template A full feature Flask project template. See also Python-Project-Template for a lean, low dependency Python app. HOW TO USE THIS

Bruno Rocha 96 Dec 23, 2022
Free casino website. Madden just for learning / fun

Website Casino Free casino website. Madden just for learning / fun. Uses Jinja2 (HTML), Flask, JavaScript, etc. Dice game Preview

Kirill Zhosul 0 Jun 22, 2022
Learn REST API with Flask, Mysql and Docker

Learn REST API with Flask, Mysql and Docker A project for you to learn to work a flask REST api with docker and the mysql database manager! Table of C

Aldo Matus 0 Jul 31, 2021
MongoEngine flask extension with WTF model forms support

Flask-MongoEngine Info: MongoEngine for Flask web applications. Repository: https://github.com/MongoEngine/flask-mongoengine About Flask-MongoEngine i

MongoEngine 815 Jan 03, 2023
Seamlessly serve your static assets of your Flask app from Amazon S3

flask-s3 Seamlessly serve the static assets of your Flask app from Amazon S3. Maintainers Flask-S3 is maintained by @e-dard, @eriktaubeneck and @SunDw

Edd Robinson 188 Aug 24, 2022
SqlAlchemy Flask-Restful Swagger Json:API OpenAPI

SAFRS: Python OpenAPI & JSON:API Framework Overview Installation JSON:API Interface Resource Objects Relationships Methods Custom Methods Class Method

Thomas Pollet 365 Jan 06, 2023
flask extension for integration with the awesome pydantic package

Flask-Pydantic Flask extension for integration of the awesome pydantic package with Flask. Installation python3 -m pip install Flask-Pydantic Basics U

248 Dec 26, 2022
A web application that consists of a collection of board games

PyBoardGame About This website contains a collection of board games for users to enjoy, as well as various guides for the games. The web app is built

Larry Shi 0 Aug 11, 2021
A weather report application build with Python, Flask, and Geopy.

A weather report application build with Python, Flask, and Geopy. Requirements Python 3

Brandon Wallace 6 May 07, 2022
Easy file uploads for Flask.

Library that works with Flask & SqlAlchemy to store files on your server & in your database Read the docs: Documentation Installation Please install t

Joe Gasewicz 145 Jan 06, 2023
Quick and simple security for Flask applications

Note This project is non maintained anymore. Consider the Flask-Security-Too project as an alternative. Flask-Security It quickly adds security featur

Matt Wright 1.6k Dec 19, 2022