The project uses poetry for Python to create an isolated environment and manage package dependencies. To prepare your system, ensure you have an official distribution of Python version 3.7+ and install Poetry using one of the following commands (as instructed by the poetry documentation):
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python -The project uses a virtual environment to isolate package dependencies. To create the virtual environment and install required packages, run the following from your preferred shell:
$ poetry installYou'll also need to clone a new .env file from the .env.template to store local configuration options. This is a one-time operation on first setup:
$ cp .env.template .env # (first time only)The .env file is used by flask to set environment variables when running flask run. This enables things like development mode (which also enables features like hot reloading when you make a file change). There's also a SECRET_KEY variable which is used to encrypt the flask session cookie.
This project uses MongoDB to store To Do items. The MongoDB database name and primary connection string must be defined in the .env file. A list of required fields can be found in .env.template.
Once all of the dependencies have been installed, start the Flask app in development mode within a Docker container by running the following command:
$ docker-compose -f docker-compose.development.yml up --buildAlternatively, development mode can be run within the Poetry environment outside a container by running:
$ poetry run flask runYou should see output similar to the following:
* Serving Flask app "app" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with fsevents reloader
* Debugger is active!
* Debugger PIN: 226-556-590Now visit http://localhost:5000/ in your web browser to view the app.
Once all of the dependencies have been installed, start the Flask app in development mode within a Docker container by running the following command:
$ docker-compose up --buildOn the control node, run the following:
ansible-playbook playbook.yml -i ansible-inventory
Once all of the dependencies have been installed, all unit and integration tests can be run with:
$ poetry run pytestIndividual tests can be run with the keyword -k flag, for example:
$ poetry run pytest -k test_view_model_with_no_itemsTo set the tests to re-run on code changes, run:
$ poetry run ptwTo run the tests in a Docker container, run:
$ docker-compose -f docker-compose.test.yml up --buildTo run the tests in a Docker container and set them to re-run on code changes, run:
$ docker-compose -f docker-compose.test-reload.yml up --buildThe app is deployed to Azure via a CD pipeline on the main branch and can be viewed at the following URL: https://preview-todo-app.azurewebsites.net/
App logs can be found at https://cammccdevops.loggly.com.