Basic Flask app that lets you store records to MySQL, search from MySQL and also display the number of records on the MySQL Table.
This requires python and pip, or docker if you are using docker, or a kubernetes cluster, if you want to deploy to kubernetes
git clone https://github.com/ruanbekker/flask-mysql-guestbook
cd flask-mysql-guestbook
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
For non docker or kubernetes deployments, the MySQL URi is defined with the environment variables:
MYSQL_USER
MYSQL_PASSWORD
MYSQL_HOST
MYSQL_DATABASE
For non containerized deployments, you can populate the tables like this:
python
>>> from application import db
>>> db.create_all()
For non containerized deployments, you can run the application like this:
$ python application.py
Build and run:
$ docker-compose up --build -d
For database migrations:
$ docker-compose exec app /bin/sh -c 'FLASK_APP=application flask db init'
$ docker-compose exec app /bin/sh -c 'FLASK_APP=application flask db migrate -m "Initial"'
$ docker-compose exec app /bin/sh -c 'FLASK_APP=application flask db upgrade'
To deploy to kubernetes:
$ kubectl apply -f ./kubernetes/
For running the application with python directly and with docker-compose:
For deploying with kubernetes, the endpoint is:
Using this application in Traefik Hub:
Thanks to Anthony from PrettyPrinted for all your Flask tutorials, it helped me tremendously over the last couple of years.