The app environment is built referencing TezRomacH/python-package-template with some modifications
The app shows datetime in Moscow timezone (GMT+3)
- App runs on port
8000 - Swagger is available at
/docs - Application metrics are available at
/metrics - Root endpoint access time is recorded and can be retrieved at
/visits
Usage of Makefile to build docker container is specified at Makefile usage section of this readme. Subsection 8.
For more specific information refer README.md inside docker folder.
Running a container from pre-built image:
docker run -it -p 8000:8000 -d winnerokay/app_python
Checkout available tags at dockerhub
- Fill
~/.aws/credentialsin the following format (in order for dynamic inventory to work properly):[default] aws_access_key_id=<your aws key id> aws_secret_access_key=<your aws access key> - Fill in
IaC/terraform/variables.tfvarsasIaC/terraform/example.tfvars - Go to IaC/terraform folder
- Run terraform:
If everything goes as expected, run
terraform planterraform apply - Go to ansible folder:
- Install ansible dependencies
pip3 install -r requirements.txt ansible-galaxy install -r requirements.yml - Verify the dynamic inventory
ansible-inventory -i ./inventory --graph - Run ansible:
In case needed, you can overwrite ansible varibles from command line
ansible-playbook -i ./inventory --private-key <path to your private key> provision_app.yml
The code is tested using pytest framework.
Tests are located at /tests folder
Run tests executing either:
poetry run pytestor
make testThe repository contains a Loki + Promtail + Grafana + Prometheus as monitoring stack.
Monitoring currently inspects itself and the application running at 0.0.0.0:8000.
You can check out the stack in monitoring folder, where you can also find the demonstration
- Clone repo
- If you don't have
Poetryinstalled run:
make poetry-download- Initialize poetry and install
pre-commithooks:
make install
make pre-commit-installMakefile contains often used commands
1. Download and remove Poetry
Download and install Poetry:
make poetry-downloadUninstall Poetry
make poetry-remove2. Install all dependencies and pre-commit hooks
Install requirements:
make installInstall pre-commit hooks:
make pre-commit-install3. Codestyle
Automatic formatting uses pyupgrade, isort and black.
make formatCodestyle checks only, without rewriting files (uses isort, black and darglint):
make check-codestyle4. Code security
Launch `Poetry` integrity checks, dependency vulnerability checks via `Safety` and code analysis using `Bandit`.
make check-safety5. Type checks
Run mypy type checker
make mypy6. Tests
Run pytest
make test7. All linters
test, codestyle checks, mypy checks and safety checks: ```bash make lint ```
8. Docker
make docker-buildwhich is equivalent to:
make docker-build VERSION=latestRemove docker image with
make docker-removeDocker readme.
9. Cleanup
Delete pycache files
make pycache-removeOr to remove pycache, build and docker image run:
make clean-all