Skip to content

cameronmccormack/DevOps-Course-Starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevOps Apprenticeship: Project Exercise

System Requirements

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):

Poetry installation (Bash)

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -

Poetry installation (PowerShell)

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python -

Dependencies

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 install

You'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.

MongoDB Integration

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.

Running the App

Development mode

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 --build

Alternatively, development mode can be run within the Poetry environment outside a container by running:

$ poetry run flask run

You 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-590

Now visit http://localhost:5000/ in your web browser to view the app.

Production mode

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 --build

Running the App on the VM

On the control node, run the following:

 ansible-playbook playbook.yml -i ansible-inventory

Test Coverage

Once all of the dependencies have been installed, all unit and integration tests can be run with:

$ poetry run pytest

Individual tests can be run with the keyword -k flag, for example:

$ poetry run pytest -k test_view_model_with_no_items

To set the tests to re-run on code changes, run:

$ poetry run ptw

To run the tests in a Docker container, run:

$ docker-compose -f docker-compose.test.yml up --build

To 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 --build

Deployed App

The 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/

Logs

App logs can be found at https://cammccdevops.loggly.com.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published