Simple Microservices Project Using Docker
Default access on http://127.0.0.1:5000/
Libraries / Packages used:
Flask - https://flask.palletsprojects.com/en/2.1.x/
Celery - https://docs.celeryq.dev/en/stable/
Redis - https://redis.io/docs/
Elastichsearch - https://www.elastic.co/guide/index.html
This microservices is also deployed on Docker using docker-compose
docker-compose - https://docs.docker.com/compose/
Image used :
MySQL - https://hub.docker.com/_/mysql
phpMyAdmin - https://hub.docker.com/r/phpmyadmin/phpmyadmin/
There are 3 simple microservices written here:
- Student Storage
How to Access : /student
Page :
/login
/logout
/register
/paper/upload - Upload File
/paper/(name) - Look for paper based on filename
/paper/download/(name) - Download paper based on filename
*Accepted Extensions : pdf
-
Simple Calculator
How to Access : /api
Page :
/prime/(index) - result of prime n-th
/prime/palindrome/(index) - result of prime palindrome n-th -
Simple Cloud Storage
How to Access : /cloud
Page :
/upload/ - Upload File
/download/(name) - Download File
*Accepted Extensions : txt, pdf, png, jpg, jpeg, gif
Dependencies
Python
pip install gevent
pip install -U Celery
pip install "celery[redis]"
pip install Flask
*See more at requirements.txt
Running Without Docker
Warning : Might not work. you need to change a few line of codes.
Install Virtual Environtment
py -3 -m venv venv
Activate venv
venv\Scripts\activate
Initialize Flask
set FLASK_APP=routes.py
flask run
activate celery
celery -A tasks worker --loglevel=info -P gevent
*use gevent if on Windows. skip if using Linux
redis for celery
broker, backend : redis://localhost:6379/0
Running With Docker
docker-compose build
docker-compose up
redis for celery
broker, backend : redis://redis:6379/0
Use code below to re-index
es.indices.delete(index='paper', ignore=[400, 404])
es.create(index='paper', id=1, ignore=400, body=mapping)