Backend Python Flask Quickstarter (be-python-flask)

The project supports generation of Python Flask project boilerplate and quick installation and integration of it with OpenShift CD pipelines.

Purpose of this quickstarter

The quickstarter is simmple WEB-server written on Python using Flask framework. The package allows easily build a Python project, using different Python modules and frameworks. It contains the basic setup for Docker, Jenkins, SonarQube and OpenShift.

What files / architecture is generated?

├── Jenkinsfile - This file contains Jenkins build configuration settings
├── README.md
├── docker - This folder contains Docker configuration settings
│   ├── Dockerfile
│   └── run.sh - This bash script solves issue with permissions for a container user
├── src
│    ├── main.py - This file is the main entry point in the project.
│    └── requirements.txt - This file contains a list of required Python modules to run application
├── tests
│        ├── __init__.py
│        ├── main_test.py - Unit testing src/main.py
│        ├── pytest.ini - pytest configuration file
│        └── requirements.txt - required Python modules for the Test Suite and IDE integration
├── .coveragerc - Coverage configuration file
├── metadata.yml - Component metadata
├── mypy.ini - mypy configuration file
├── release-manager.yml - Configuration file for the Release Manager
└── sonar-project.properties - This file contains SonarQube configuration settings

Usage - how do you start after you provisioned this quickstarter

The project is production ready when deployed in OpenShift thanks to gunicorn.

It is recommended when you are developing a Python project to use separated environments. For this purpose usually one can use virtualenv package.

# Command install virtualenv package (run only once)
pip install virtualenv

# Creates virtual environment 'mylocaldevelopment' (will be located in the folder mylocaldevelopment) (run only once)
virtualenv mylocaldevelopment

# Initiate virtual environment for the project (every time)
source mylocaldevelopment/bin/activate

# Runs installation of required modules in the virtual environment (run only once)
pip install -r src/requirements.txt

# Start your application
python src/main.py

How this quickstarter is built through Jenkins

The Jenkinsfile is provisioned with this quick starter to ease CI/CD process. In Jenkinsfile, there are various stages:

  • Prepare Test Suite - Prepares the virtual environment for testing and linting:

      pip install -r tests/requirements.txt
  • Lint - Runs mypy and flake8 for increasing code quality:

      mypy src
      flake8 --max-line-length=120 src
  • Test - Runs pytest and generates xUnit and code coverage reports:

      cd src/
      python -m pytest --junitxml=tests.xml --cov-report term-missing --cov-report xml --cov=. ../tests/
  • Build - Builds the application: copies src folder into docker/dist folder.

Builder agent used

This quickstarter uses Python builder agent Jenkins builder agent.

Known limitations

NA