Webapp used in devops-360 project
- Install a Mysql-Server
- Database schemas and the intial mysql dump are located in the database folder.
- Developers will make sure to provide database schema upgrades in
database/schemas/vX/beerbattle.sql
whereX
is the major realease number of the version.
For example v1.0.0 requires
database/schemas/v1/beerbattle.sql
.
If you install v2.0.0 right away, you need to make sure to import the following schemas
database/schemas/v1/beerbattle.sql
anddatabase/schemas/v2/beerbattle.sql
.
It is safe to rerun multiple times the schemas/vX/beerbattle.sql imports as they include
IF NOT EXISTS
statements.
- When you setup the database for the first time, you need to make sure to populate the
beer
table with the initial data dump file named beerbattle.sql (Also available as a CSV file if needed beerbattle.csv).
⚠️ Do not run the data import twice otherwise you will end up with duplicated data!
- Install the project dependencies in a virtualenv with
cd <application-root>/
# Once the virtualenv is activated
pip install -r requirements.txt
- In order to override the developement configuration for production, configure the following template and place it under
<application-root>/app/config/prod.py
:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from app.config.config import Config
class ProductionConfig(Config):
### Mysql config
MYSQL_SERVER = '127.0.0.1'
MYSQL_DB = 'beerbattle'
MYSQL_USER = 'root'
MYSQL_PWD = 'password'
### Webapp custom settings
# Restrict battles to a specific ID interval [min_id, max_id]
# BEER_BATTLE_ID_INTERVAL = (1,10)
-
Once the configuration is in place, make sure the following environment variable is set:
export FLASK_ENV=prod
. -
Now run
python run.py
and that's it :)
Please note that in production you should not run
python run.py
. You should instead run the application with a tool like (UWSGI)[https://uwsgi-docs.readthedocs.io/en/latest/]
Returns 200 and a the following message if the application is healthy:
The Flask WebApp is healthy
Returns information about the Webapp:
db_conn
(string
): Database connection stringdb_conn_state
(boolean
): Is the webapp connected to the databasegit_revision
(string
): First 7 digit of the SHA commitgit_tag
(string
): Tag applied to the current commit (This is the application version)server_name
(string
): Ip address of the server
{
"db_conn": "mysql://root:***@127.0.0.1/beerbattle",
"db_conn_state": false,
"git_revision": "18281ca",
"git_tag": "v1.0.0",
"server_name": "127.0.0.1"
}
Home page of the webapp (HTML content).
List all beers present in the beer
table from the database.
List beers present in the battle
table from the database, and display them ordered by people votes.
Run a battle versus two beers picked up randomly from the database. The user can vote for his favorite one. Once the use vote, an other battle starts!
Made with ♥ for teaching people