Skip to content

CharlieCumber/DevOps-Course-Project

 
 

Repository files navigation

DevOps Apprenticeship: Project Exercise

System Requirements

The project uses vagrant to create an isolated application environment within a virtual machine. To prepare your system, ensure you have an official distribution of Python version 3.7+ and install vagrant by following the instructions here. Addtitionaly you will need a provider such as VirtualBox or Hyper-V installed.

Set up

Configuration variables

You need to clone a new .env file from the .env.tempalate 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.

GitHub Authentication (OAuth) for local

You will need to create an OAuth app under a GitHub account. Follow the instructions 'here'. You will need to provide the following values:

  • Homepage URL = "http://localhost:5000/"
  • Authorization callback URL = "http://localhost:5000/auth/authorize" You will be provided with a "Client Id" upon creating the application, you need to set the AUTH_CLIENT_ID variable in your .env file to this value. From the app managment page you will see an option to "Generate a new client secret", you should do so and set AUTH_CLIENT_SECRET in the .env file to it's value.

Run the database locally

$ docker run --name to-do-database -p 27017:27017 -d mongo

Running the App

Option 1: Docker

Docker compose configurations are provided for both production and development modes. The production configuration uses Gunicorn, while the development configuration uses Flask development server which has the additional benifit of hot reloading.

To start the application within a docker container, firstly ensure you have docker desktop installed and running, then you can run either command from your terminal:

# Production Mode
$ docker-compose up
# Development Mode
$ docker-compose -f docker-compose.development.yml up

Option 2: Vagrant

To start the application in a vagrant virtual machine by running:

$ vagrant up

Option 3: Poetry

Alternatively you can start the app on your own machine with poetry by running:

$ poetry install
$ poetry run flask run

Accessing the application:

After the project dependancies are installed, 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.

Testing

Option 1: Poetry

The end to end tests require you have the Chrome browser installed and that you download the corresponding version of the ChromeDriver:

  • Download and install Chrome from here
  • Download ChromeDriver from here and add the executable file to the root of the project.

Once the test setup requirments are completed, execute the tests by running:

$ poetry run pytest

Option 2: Docker

To build the docker image by running:

$ docker build --target test --tag todo-app:test .

To execute the unit and integration tests by running:

$ docker run todo-app:test tests

To execute the E2E tests by running:

$ docker run --env-file .env todo-app:test e2e_tests

Deploying the application

The application is deployed with azure and is accessible at https://charlie-devops-to-do.azurewebsites.net/

New deployments are automatically triggered when commits are made to the main branch.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 75.9%
  • HTML 17.8%
  • Dockerfile 4.6%
  • Shell 1.7%