Cookiecutter template for a dockerized dev-ops pipeline with SonarQube code-quality monitoring. Cookiecutter provides a command-line interface for creating projects from templates.
- Sample project for this cookiecutter (including detailed documentation).
- This cookiecutter has been generated with the command-line client devopstemplate.
- Also check out audreyr/cookiecutter-pypackage for additional Python package templates.
The template provides a minimal dev-ops pipeline that supports:
- testing and deployment in a multi-stage Docker environment,
- packaging with setuptools,
- code analysis with pylint, bandit, pytest and coverage,
- code quality monitoring with SonarQube.
The dev-ops pipeline is mostly implemented in a Makefile
and a Dockerfile
which are
independent of your Python code.
Install the latest cookiecutter:
pip install -U cookiecutter
Generate an instance of the template:
cookiecutter https://github.com/lrothack/cookiecutter-pydevops.git
Then switch to the project directory and:
- Set up a virtual environment for your project and activate it (requires Python >= 3.6).
- Run
make help
in order to get an overview of the targets provided byMakefile
. - Run
make install-dev
in order to install the package (and all dependencies) in development mode. - Run
make lint
in order to run code analysis with pylint and bandit. - Run
make test
in order to run unit tests with pytest and coverage. - Run
make dist
in order to build a Python package (binary and source). - Run
docker-compose -p sonarqube -f sonarqube/docker-compose.yml up -d
in order to start a SonarQube server. - Run
make sonar
in order to runsonar-scanner
and report results to your local SonarQube server. Make sure to create a SonarQube authentication token before. Save the token in the file.sonartoken
within your project directory. - Run
make docker-build
in order to analyze, test, package and deploy in a multi-stage Docker build. Test your docker image withdocker run
.
Advanced configurations can be made in the configuration sections of Makefile
. See lrothack/dev-ops for more information.