Skip to content

dmakwana312/DevOps-Course-Starter

Repository files navigation

DevOps Apprenticeship: Project Exercise

If you are using GitPod for the project exercise (i.e. you cannot use your local machine) then you'll want to launch a VM using the following link. Note this VM comes pre-setup with Python & Poetry pre-installed.

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.8+ and install Poetry using one of the following commands (as instructed by the poetry documentation):

Poetry installation (Bash)

curl -sSL https://install.python-poetry.org | python3 -

Poetry installation (PowerShell)

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

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.

Trello Setup

In order to run the application, some setup is required to performed once in order to get the necessary Trello config setup.

Main thing to ensure is that you have a 'To Do' and 'Done' list on your board as the functionality of this app is dependent on that.

Steps are as follows:

  1. Create an account
  2. Generate API key and token
  3. Assign the values obtained to there corresponding variables in the .env file:
    • TRELLO_API_KEY
    • TRELLO_API_TOKEN
    • TRELLO_BOARD_ID

Running the App

Once the all dependencies have been installed, start the Flask app in development mode within the Poetry environment 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.

Running Tests

Tests can be run from the terminal by running poetry run pytest

If you want to skip running the end-to-end tests, you can do this by running poetry run pytest tests. Similarly, if you only want to run the end-to-end tests, you can do this by running poetry run pytest tests_e2e

You can also run tests individually within VSCode by following the instructions on this page

Provision VM via Ansible

Following instructions should be run on control node only

  1. Create a file called 'vault.yaml'
  2. Use the following as a template, but replace placeholders with actual values
trello_api_key: <trello_api_key>
trello_api_token: <trello_api_token>
trello_board_id: <trello_board_id>
  1. Create a file called vault-pass and add a line with what you would like the pasword for the vault to be
  2. Execute the following to encrypt the vault.yaml file created during step 2
ansible-vault encrypt --vault-password-file vault-pass vault.yaml
  1. Run the playbook with following command
ansible-playbook playbook.yaml -i inventory.ini --vault-password-file vault-pass
  1. If you need to view the content of the vault, you can run the following to decrypt
ansible-vault decrypt --vault-password-file vault-pass vault.yaml

Run in Docker

Development

  1. Build the image with the following command
    docker build --target development --tag todo-app:dev .
  2. The container can be run via 2 ways
    1. Using a docker command
      docker run --env-file .env --publish 5000:80 --mount type=bind,source="$(pwd)"/todo_app,target=/app/todo_app/todo_app todo-app:dev
    2. Using Docker Compose, which will also start test runners (this includes unit, integration and end-to-end tests) that will continously rerun tests when a change is detected Note that for docker compose to work you will require the test images to be created. This can either be done manually in a similar way to the previous step, or add '--build' to the below command
      docker compose up

Production

  1. Build the image with the following command
    docker build --target production --tag todo-app:prod .
  2. Run the container
    docker run --env-file .env --publish 5000:80 todo-app:prod

Debug

If you wish to create a container, but not start the application itself to debug, the following command can be used. You can also connect the container to VSCode to debug through that

docker compose -f docker-compose-debug.yaml up

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors