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
Serve angular production application from python flask backend. Quick and Easy

Serve angular production application from python flask backend. Quick and Easy

mark 1 Dec 01, 2022
Flask-Rebar combines flask, marshmallow, and swagger for robust REST services.

Flask-Rebar Flask-Rebar combines flask, marshmallow, and swagger for robust REST services. Features Request and Response Validation - Flask-Rebar reli

PlanGrid 223 Dec 19, 2022
This is a API/Website to see the attendance recorded in your college website along with how many days you can take days off OR to attend class!!

Bunker-Website This is a GUI version of the Bunker-API along with some visualization charts to see your attendance progress. Website Link Check out th

Mathana Mathav 11 Dec 27, 2022
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
Flask-Diamond is a batteries-included Flask framework.

Flask-Diamond Flask-Diamond is a batteries-included Python Flask framework, sortof like Django but radically decomposable. Flask-Diamond offers some o

Diamond Methods 173 Dec 22, 2022
Flask Application Structure with MongoDB

This application aims to serve as a template for APIs that intend to use mongoengine and flask-restx

Tiago Franco 5 Jun 25, 2022
A boilerplate Flask API for a Fullstack Project :rocket:

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

Yasser Tahiri 32 Dec 24, 2022
Map Matching & Weight Completion service - Java (Springboot) & Python(Flask)

Map Matching service to match coordinates to roads using Java and Springboot. Weight Completion service to fill in missing weights in a graph, using Python and Flask.

2 May 13, 2022
Lightweight library for providing filtering mechanism for your APIs using SQLAlchemy

sqlalchemy-filters-plus is a light-weight extendable library for filtering queries with sqlalchemy. Install pip install sqlalchemy-fitlers-plus Usage

Karami El Mehdi 38 Oct 05, 2022
An Instagram Clone using Flask, Python, Redux, Thunk, React

An Instagram Clone using Flask, Python, Redux, Thunk, React

1 Dec 09, 2021
This is a simple web application using Python Flask and MySQL database.

Simple Web Application This is a simple web application using Python Flask and MySQL database. This is used in the demonstration of development of Ans

Alaaddin Tarhan 1 Nov 16, 2021
A Flask application for Subdomain Enumeration

subdomainer-flask A Flask application for Subdomain Enumeration steps to be done git clone https://github.com/gokulapap/subdomainer-flask pip3 install

GOKUL A.P 7 Sep 22, 2022
A team blog based on Flask

A team blog based on Flask This project isn't supported at the moment, please see a newer pypress-tornado Thanks for flask_website and newsmeme at [ht

老秋 549 Nov 10, 2022
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

Tactful.ai 18 Nov 26, 2022
retorna informações de pessoas que não existem

random-person-api API que entrega dados aleatórios sobre pessoas que (provavelmente) não existem. Como usar? Copie o link abaixo https://random-person

Miguel 3 Aug 09, 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
Pagination support for flask

flask-paginate Pagination support for flask framework (study from will_paginate). It supports several css frameworks. It requires Python2.6+ as string

Lix Xu 264 Nov 07, 2022
A web application for a fake pizza store, built in Python with Flask and PostgreSQL.

✨ Pizza Pizza - Pizza Store ✨ A web application for a fake Pizza Store, the app let you create an account and order pizza, complements or drinks. Buil

Bonnie Fave 6 Dec 18, 2022
A live chat built with python(flask + gevent + apscheduler) + redis

a live chat room built with python(flask / gevent / apscheduler) + redis Basic Architecture Screenshot Install cd /path/to/source python bootstrap.py

Limboy 309 Nov 13, 2022
API to get the details of the characters in the Money heist TV show.

Project Heist Description: Project Heist is a RESTful API made using Python and Flask. This API is inspired by the popular Spanish TV show Money Heist

Rahul V 5 Dec 19, 2022