This project was developed as part of a course at the Faculty of Technical Sciences in Novi Sad, for the subject Distributed Computer Systems.
Social Media is a full-stack application designed for connecting users. It features secure user authentication, post sharing, and admin functionality. This project demonstrates how to build and deploy a Dockerized full-stack application with Flask, Angular, MySQL, and Docker.
To run this project, make sure you have the following installed:
- Node.js: Download and install Node.js
- Python: Download and install Python
- MySQL: Download and install MySQL
- MySQL Workbench: Download and install MySQL Workbench
- Docker Desktop: Download and install Docker Desktop
After installing these dependencies, follow the setup instructions to get the project running.
Running with Docker
The easiest way to run the application is by using Docker
-
Clone the project:
Clone the repository and navigate to the Project_DRS_Social_Media project directory:
git clone https://github.com/Acile067/Project_DRS_Social_Media.git cd Project_DRS_Social_Media/backend
-
Build docker image (backend):
docker build -t my-python-app .
-
Build docker image (frontend):
cd .. cd frontend/DRS_frontend docker build -t angular-app .
-
Create docker network:
docker network create my_network
-
Run docker containers:
docker run --name mysql_db --network my_network -e MYSQL_ROOT_PASSWORD=MySQLPassword1 -e MYSQL_DATABASE=appDB -p 3307:3306 -d mysql:8.0 docker run --name python_app --network my_network -p 5000:5000 -d my-python-app docker run --name angular_app --network my_network -p 4200:4200 -d angular-app
-
Migrate tables:
Before migrating the tables, you need to connect to the database and create the
appDB
database.Create a new connection in MySQL Workbench using the following settings:
- Port: 3307
- Password: MySQLPassword1
Create the
appDB
manually then typedocker exec -it python_app /bin/bash flask --app app.app db init flask --app app.app db migrate flask --app app.app db upgrade
-
Add admin in db:
Fill in a row in the table to create an admin with the following values:
- isAdmin: yes
- isNewUser: no
- RejectedPostCount: 0
- Email: x@x
- Fill in the remaining fields as desired (fields must not be null).
Running Locally
Alternatively, you can run the project locally.
-
Clone the project:
Clone the repository and navigate to the Project_DRS_Social_Media project directory:
git clone https://github.com/Acile067/Project_DRS_Social_Media.git cd Project_DRS_Social_Media/
-
Run frontend:
You must have Angular installed globally to run the
ng serve
command.To install Angular globally, use the following command:
npm install -g @angular/cli
cd frontend/DRS_frontend npm i ng serve
If
ng serve
does not work, try running:npm run ng serve
-
Create database:
Create a local database on port 3306 with the password
MySQLPassword1
. You can use a different password, but it is important to remember it.Create the
appDB
manually. -
Run backend:
Navigate to the
backend
folder.py -m venv .venv
or
python -m venv .venv
or
python3 -m venv .venv
It depends on the version of Python you have.
cd .venv/bin
or
cd .venv/Scripts
./activate cd ../../
Replace the following line:
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:MySQLPassword1@mysql_db:3306/appDB'
with this one:
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:MySQLPassword1@127.0.0.1/appDB'
It is important to set the correct password (
MySQLPassword1
).This change can be made in the
app.py
file.
pip3 install -r requirements.txt cd app flask db migrate flask db upgrade
RUN
run.py
cd .. py ./run.py
-
Add admin in db:
Fill in a row in the table to create an admin with the following values:
- isAdmin: yes
- isNewUser: no
- RejectedPostCount: 0
- Email: x@x
- Fill in the remaining fields as desired (fields must not be null).
Q1: What if I encounter an error during table migration?
A1: Ensure the database appDB is created and the password in app.py matches the MySQL credentials.
Q2: The migrations folder is causing issues
A2: Feel free to delete it, as well as the alembic_version table in the database, and try running the migration again.