Git Product home page Git Product logo

navneet777 / python-flask-microservices Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudacademy/python-flask-microservices

0.0 0.0 0.0 30 KB

Demonstrates how to use Python, Flask, and Docker to quickly prototype and build microservices

Home Page: https://cloudacademy.com/course/mastering-microservices-with-python-flask-docker-1118

Shell 0.73% Python 72.52% CSS 2.72% HTML 22.00% Dockerfile 2.03%

python-flask-microservices's Introduction

Mastering Microservices with Python, Flask, and Docker

Interested in microservices, and how they can be used for increased agility and scalability?

Microservices is an architectural style and pattern that structures an application as a collection of coherent services. Each service is highly maintainable, testable, loosely coupled, independently deployable, and precisely focused.

This course takes a hands-on look at microservices using Python, Flask, and Docker. You'll learn how Flask can be used to quickly prototype and build microservices, as well as how to use Docker to host and deploy them.

๐Ÿค˜

Project Structure

The Python Flask based microservices project is composed of the following 4 projects:

Microservices Setup and Configuration

To launch the end-to-end microservices application perform the following:

Step 1.

Navigate into the frontend directory, and confirm the presence of the docker-compose.deploy.yml file:

cd frontend
ls -la

Step 1.

Create a new Docker network and name it micro_network:

docker network create micro_network

Step 2.

Build each of the microservice Docker container images:

docker-compose -f docker-compose.deploy.yml build
docker images

Step 3.

Launch the microservice environment:

docker-compose -f docker-compose.deploy.yml build
docker ps -a

Step 4.

Prepare each microservice mysql database:

for service in corder-service cproduct-service cuser-service;
do 
 docker exec -it $service flask db init
 docker exec -it $service flask db migrate
 docker exec -it $service flask db upgrade
done

Step 5.

Populate the product database:

curl -i -d "name=prod1&slug=prod1&image=product1.jpg&price=100" -X POST localhost:5002/api/product/create
curl -i -d "name=prod2&slug=prod2&image=product2.jpg&price=200" -X POST localhost:5002/api/product/create

Step 6.

Using your workstations browser - navigate to the following URL and register:

http://localhost:5000/register

Step 7.

Back within your terminal, use a mysql client to confirm that a new user registration record was created:

mysql --host=127.0.0.1 --port=32000 --user=cloudacademy --password=pfm_2020
mysql> show databases;
mysql> use user;
mysql> show tables;
mysql> select * from user;
mysql> exit

Step 8.

Using your workstations browser - login, and add products into your cart, and then finally click the checkout option

http://localhost:5000/login

Step 9.

Back within your terminal, use a mysql client to confirm that a new order has been created:

mysql --host=127.0.0.1 --port=32002 --user=cloudacademy --password=pfm_2020
mysql> show databases;
mysql> use order;
mysql> show tables;
mysql> select * from order.order;
mysql> select * from order.order_item;
mysql> exit

Microservices Teardown

Perform the following steps to teardown the microservices environment:

Step 1.

Create a new Docker network and name it micro_network:

for container in cuser-service cproduct-service corder-service cproduct_dbase cfrontend-app cuser_dbase corder_dbase;
do
 docker stop $container
 docker rm $container
done

Step 2.

Remove the container volumes

for vol in frontend_orderdb_vol frontend_productdb_vol frontend_userdb_vol;
do
 docker volume rm $vol
done

Step 3.

Remove the container network

docker network rm micro_network

Python extensions reference

The following Python extensions were used:

python-flask-microservices's People

Contributors

jeremycook123 avatar saqibbutt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.