Package: devopstemplate
Python Devops Template ToolCommand-line interface for setting up a Python project based on a dev-opstemplate.Sample projectfor this template (including detailed documentation).Cookiecutterfor this template.Also check outaudreyr/cookiecutter-pypackagefor additional Python package templates.FeaturesThis command-line interface supports the creation and the management of a Python dev-ops template that provides:testing and deployment in a multi-stageDockerenvironment,packaging withsetuptools,code analysis withpylint,bandit,pytestandcoverage,code quality monitoring withSonarQube.The dev-ops pipeline is mostly implemented in aMakefileand aDockerfilewhich are
independent of your Python code. A SonarQube server is started withdocker-compose.Creation and management of the template:create a new instance of the template (very similar toCookiecutter),manage an existing instance/project by adding template components as the project evolves,generate a Cookiecutter template (seelrothack/cookiecutter-pydevops),packages the template code in a Python distributions, e.g., binary wheel package,configure the template with boolean command-line flags or in interactive mode,resolves author information automatically withgit config.Optional template components:MongoDBMlFlow(withPostgreSQLandMinIObackends)These components have been developed injkortner/ml-ops.InstallationInstall the latest version frompypi.org:pipinstall-UdevopstemplateFrom source:# Obtain sourcesgitclone--recurse-submoduleshttps://github.com/lrothack/dev-ops-admin.git# Install and activate virtual environmentcddev-ops-admin
python3-mvenvvenvsourcevenv/bin/activate# Build packagemakedistThe binary wheel package is located in thedistdirectory and can be installed withpip.Create and manage projectsAfter installation, the executabledevopstemplateis available. It provides the sub-commands:createmanagecookiecutterAn overview of the functionalities is shown on the help screens:devopstemplate--help
devopstemplate<sub-command>--helpThe working directory is always the root directory of your project, for example:mkdirsampleprojectcdsampleproject
devopstemplatecreateUsing the dev-ops templateAfter creating a new project or after switching to the project directory:Set up a virtual environment for your project and activate it (requires Python >= 3.6).Runmake helpin order to get an overview of the targets provided byMakefile.
Note: Runningmakeis only supported from project directory.Runmake install-devin order to install the package (and all dependencies) in development mode.Runmake lintin order to run code analysis with pylint and bandit.Runmake testin order to run unit tests with pytest and coverage.Runmake distin order to build a Python package (binary and source).Make sure you haveDockerinstalled and the Docker daemon is running. Allocate at least 4GB RAM in the Docker resource configuration.Rundocker-compose -p sonarqube -f sonarqube/docker-compose.yml up -din order to start a SonarQube server. Configure your server through its web interface and obtain an authentication token. The SonarQube URL can be configured through theMakefilevariableSONARURL. The authentication token can be stored in the local file.sonartoken.Runmake sonarin order to runsonar-scannerand report results to your SonarQube server.Runmake docker-buildin order to analyze, test, package and deploy in a multi-stage Docker build. Analysis results and test results are shown after the build.Advanced configurations can be made in theconfigurationsections ofMakefile. Seelrothack/dev-opsfor more information.Additional componentsmongodbmlflowAdditional components can be installed when creating a new project or with themanagecommand at a later time (replace<component>with a component from the list above, also seedevopstemplate manage --help):cdsampleproject
devopstemplatemanage--add-<component>Start the corresponding Docker containers withdocker-compose:docker-compose-p<component>-f<component>/docker-compose.ymlup-dAlso check out the README file in the<component>directory and run the sample script.