This project aims to implement a standard CI/CD pipeline for a Flask project whose dependencies are managed using Poetry. This repository is a major improvement on my last attempt to create a CI/CD pipeline for a basic python application build using the Flask microframework.
Poetry is a python dependecy manager which is very much analogous to npm for JS projects. With Poetry one can isolate all the dependencies in a Poetry.lock
file which can then ensure that the versions are maintained while shifting via environments. Poetry also helps group dependencies into dev dependecies and main dependencies. It also provides you the advantage of defining scripts just like one would define in package.json. Poetry generates a pyproject.toml
file which has become the standard for defining the package details and configuration of tools like flake8, bandit and PyTest.
- Install Environment -
poetry install
- Run Linting -
poetry run flake8 .
- Vulnerability Check -
poetry run bandit -r . -c "pyproject.toml"
- Run Unit Test -
poetry run pytest .
- Bump Version -
poetry version patch
- Commit Version Update and Push Changes
- Build Docker Image from Dockerfile
- Docker Login
- Push Image to DockerHub Repository
A multibranch project has been setup with a Multibranch webhook trigger setup to build the latest release on a commit. The Jenkins has also been configured with Build Trigger Extension to prevent build on certain file changes like README.md etc. The Embeddable Status Plugin was used to create the badge shown on the top of the README.md file. Jenkins is making use of two custom defined libraries one for poetry and one for normal python build commands. These repo's can be found here and here