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/get-poetry.py | python
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-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 install
You'll also 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.
This app uses a web service called trello to manage the to-do items. You will therefore need to set up the Trello API authentification for it to work properly:
Add API key, token and Trello board id .env file
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.
A number of unit tests have been added in /tests folder. This tests make use of items_pickle file to load a hardcoded set of items.
Add chromedriver.exe to your project path
Using VSCode add Test Explorer UI extension and Python Test Explorer for Visual Studio Code. Navigate to extension GUI and execute tests.
To run from command line:
$ poetry run pytest
Navigate to repository root directory and run:
$ vagrant up
This command will provision a VM with the requirements needed for the To-Do app and start it automatically.
The app is accessible on http://127.0.0.1:5000/
A production and a development container are available.
To build the production container:
$ docker build --target production --tag todo-app:prod .
To run the app within the production container:
$ docker run --env-file .env -p 8000:8000 todo-app:prod
Docker will pick your environment variables from your local .env file. Make sure to have it up to date.
The app is accesible locally on: http://localhost:8000/
To build the development container:
$ docker build --target development --tag todo-app:dev .
To run the development application with the local repository binded to the container:
$ docker run --env-file ./.env -p 5000:5000 --mount type=bind,source="$(pwd)"/todo_app,target=/usr/DevOps-Course-Starter/todo_app todo-app:dev
Docker will pick your environment variables from your local .env file. Make sure to have it up to date.
The app is accesible locally on: http://localhost:5000/
To build the testing container:
$ docker build --target test --tag todo-app:test .
To run the testing container:
$ docker run --env-file ./.env todo-app:test
Travis will build each push and run the dockerized tests.
Check build status at Travis
Travis will take care of deployment to Heroku.
To run your Heroku app, go to gontx-todo-app
In case you want to locally push your application to Heroku manually, run on Heroku CLI:
# Log in
$ heroku login
$ heroku container:login
# Build production latest image and push it
$ docker login
$ docker build --target production --tag gontx/todo-app:latest .
$ docker push gontx/todo-app:latest
# Pull latest image
$ docker pull gontx/todo-app:latest
# Tag the image
$ docker tag gontx/todo-app:latest registry.heroku.com/gontx-todo-app/web
# Push the image to heroku
$ docker push registry.heroku.com/gontx-todo-app/web
# Release the Container
$ heroku container:release web
# Open web
$ heroku open
To connect to MongoDB Atlas:
$ client = pymongo.MongoClient("mongodb+srv://<USER_NAME>:<PASSWORD>@<MONGO_URL>/<DEFAULT_DATABASE>?w=majority")
$ client.list_database_names()['admin', 'local']
Log in to Azure:
az login
az account list
Select the desired subscription:
az account set --subscription="SUBSCRIPTION_ID"
The infrastructure provisioning is handled using Terraform. Chech main.tf file.
To initialize Terraform:
terraform init
To apply Terraform with given environment variables:
terraform apply -var 'client_id=client_id' -var 'client_secret=client_secret' -var 'secret_key=secret_key'
To trigger webhook:
curl -dH -X POST "$(terraform output webhook_url)"
The application can be accessed at: http://gontx-todo-app.azurewebsites.net/
Logs available at Loggly: https://devopscourse.loggly.com/