This is a simple Python Flask application that performs CRUD operations on a MySQL database, the project contains Docker and Docker Compose files for running the Python application with Mysql Database Locally.
Before you begin, ensure you have met the following requirements:
- Python
- MySQL For Ubuntu | MySQL For Windows
- Docker installed and configured
- Beekeeper-Studio
For Database Access
-
Start your MySQL server.
-
Create a new MySQL database for the application.
-
Update the database configuration in
app.py
to match your local MySQL settings:- DB_HOST: localhost
- DB_USER: your MySQL username
- DB_PASSWORD: your MySQL password
- DB_DATABASE: your database name
-
Create a table in the database that will be used by your application
CREATE TABLE tasks ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT, is_complete BOOLEAN DEFAULT false );
-
Clone the repository:
git clone https://github.com/johnbedeir/End-to-end-DevOps-Python-MySQL cd End-to-end-DevOps-Python-MySQL/todo-app
-
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required dependencies:
pip3 install -r requirements.txt
-
Start the Flask application:
python3 app.py
-
Access the application at
http://localhost:5000
.
-
Build the Docker image:
docker build -t my-flask-app .
-
Run the Docker container with host network (to access the local MySQL server):
docker run --network=host my-flask-app
-
Access the application at
http://localhost:5000
.
To run the application using docker compose:
docker-compose up
This will Run both the application and the database containers and will also create a table in the database using the sql script init-db.sql
To take it down run the following command:
docker-compose down