-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1acdcb3
commit d207082
Showing
78 changed files
with
1,829 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set env | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
|
||
- name: Package | ||
run: | | ||
echo packaging... | ||
tar -czf release-${{ env.RELEASE_VERSION }}.tar.gz microservices | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: release-${{ env.RELEASE_VERSION }} | ||
path: release-${{ env.RELEASE_VERSION }}.tar.gz | ||
|
||
- name: Make Release | ||
uses: softprops/[email protected] | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: | | ||
release-${{ env.RELEASE_VERSION }}.tar.gz | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/ | ||
.git/ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
migrations/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#.env | ||
CONFIGURATION_SETUP="config.ProductionConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FLASK_APP=run.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
.git/ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Dockerfile | ||
FROM python:3.7 | ||
COPY requirements.txt /frontendapp/requirements.txt | ||
WORKDIR /frontendapp | ||
RUN pip install -r requirements.txt | ||
COPY . /frontendapp | ||
ENTRYPOINT ["python"] | ||
CMD ["run.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Running application in docker containers: | ||
#### Using Docker CLI | ||
``` | ||
docker network ls | ||
docker network create --driver bridge micro_network (skip if already created) | ||
docker build -t frontend-srv . | ||
docker run -p 5000:5000 --detach --name frontend-service --net=micro_network frontend-srv | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# application/__init__.py | ||
import config | ||
import os | ||
from flask import Flask | ||
from flask_bootstrap import Bootstrap | ||
from flask_login import LoginManager | ||
|
||
login_manager = LoginManager() | ||
bootstrap = Bootstrap() | ||
UPLOAD_FOLDER = 'application/static/images' | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__, static_folder='static') | ||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | ||
|
||
environment_configuration = os.environ['CONFIGURATION_SETUP'] | ||
app.config.from_object(environment_configuration) | ||
|
||
login_manager.init_app(app) | ||
login_manager.login_message = "You must be login to access this page." | ||
login_manager.login_view = "frontend.login" | ||
|
||
bootstrap.init_app(app) | ||
|
||
with app.app_context(): | ||
from .frontend import frontend_blueprint | ||
app.register_blueprint(frontend_blueprint) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# application/frontend/__init__.py | ||
from flask import Blueprint | ||
|
||
frontend_blueprint = Blueprint('frontend', __name__) | ||
|
||
from . import views |
50 changes: 50 additions & 0 deletions
50
microservices/frontend/application/frontend/api/OrderClient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# application/frontend/api/OrderClient.py | ||
from flask import session | ||
import requests | ||
|
||
|
||
class OrderClient: | ||
@staticmethod | ||
def get_order(): | ||
headers = { | ||
'Authorization': 'Basic ' + session['user_api_key'] | ||
} | ||
url = 'http://corder-service:5003/api/order' | ||
response = requests.request(method="GET", url=url, headers=headers) | ||
order = response.json() | ||
return order | ||
|
||
@staticmethod | ||
def post_add_to_cart(product_id, qty=1): | ||
payload = { | ||
'product_id': product_id, | ||
'qty': qty | ||
} | ||
url = 'http://corder-service:5003/api/order/add-item' | ||
|
||
headers = { | ||
'Authorization': 'Basic ' + session['user_api_key'] | ||
} | ||
response = requests.request("POST", url=url, data=payload, headers=headers) | ||
if response: | ||
order = response.json() | ||
return order | ||
|
||
@staticmethod | ||
def post_checkout(): | ||
url = 'http://corder-service:5003/api/order/checkout' | ||
|
||
headers = { | ||
'Authorization': 'Basic ' + session['user_api_key'] | ||
} | ||
response = requests.request("POST", url=url, headers=headers) | ||
order = response.json() | ||
return order | ||
|
||
@staticmethod | ||
def get_order_from_session(): | ||
default_order = { | ||
'items': {}, | ||
'total': 0, | ||
} | ||
return session.get('order', default_order) |
17 changes: 17 additions & 0 deletions
17
microservices/frontend/application/frontend/api/ProductClient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# application/frontend/api/ProductClient.py | ||
import requests | ||
|
||
|
||
class ProductClient: | ||
|
||
@staticmethod | ||
def get_products(): | ||
r = requests.get('http://cproduct-service:5002/api/products') | ||
products = r.json() | ||
return products | ||
|
||
@staticmethod | ||
def get_product(slug): | ||
response = requests.request(method="GET", url='http://cproduct-service:5002/api/product/' + slug) | ||
product = response.json() | ||
return product |
55 changes: 55 additions & 0 deletions
55
microservices/frontend/application/frontend/api/UserClient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# application/frontend/api/UserClient.py | ||
import requests | ||
from flask import session, request | ||
|
||
|
||
class UserClient: | ||
@staticmethod | ||
def post_login(form): | ||
api_key = False | ||
payload = { | ||
'username': form.username.data, | ||
'password': form.password.data | ||
} | ||
url = 'http://cuser-service:5001/api/user/login' | ||
response = requests.request("POST", url=url, data=payload) | ||
if response: | ||
d = response.json() | ||
print("This is response from user api: " + str(d)) | ||
if d['api_key'] is not None: | ||
api_key = d['api_key'] | ||
return api_key | ||
|
||
@staticmethod | ||
def get_user(): | ||
|
||
headers = { | ||
'Authorization': 'Basic ' + session['user_api_key'] | ||
} | ||
url = 'http://cuser-service:5001/api/user' | ||
response = requests.request(method="GET", url=url, headers=headers) | ||
user = response.json() | ||
return user | ||
|
||
@staticmethod | ||
def post_user_create(form): | ||
user = False | ||
payload = { | ||
'email': form.email.data, | ||
'password': form.password.data, | ||
'first_name': form.first_name.data, | ||
'last_name': form.last_name.data, | ||
'username': form.username.data | ||
} | ||
url = 'http://cuser-service:5001/api/user/create' | ||
response = requests.request("POST", url=url, data=payload) | ||
if response: | ||
user = response.json() | ||
return user | ||
|
||
@staticmethod | ||
def does_exist(username): | ||
url = 'http://cuser-service:5001/api/user/' + username + '/exists' | ||
response = requests.request("GET", url=url) | ||
return response.status_code == 200 | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# application/frontend/forms.py | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField, SubmitField, HiddenField, IntegerField | ||
|
||
from wtforms.validators import DataRequired, Email | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
username = StringField('Username', validators=[DataRequired()]) | ||
password = PasswordField('Password', validators=[DataRequired()]) | ||
submit = SubmitField('Login') | ||
|
||
|
||
class RegistrationForm(FlaskForm): | ||
username = StringField('Username', validators=[DataRequired()]) | ||
first_name = StringField('First name', validators=[DataRequired()]) | ||
last_name = StringField('Last name', validators=[DataRequired()]) | ||
email = StringField('Email address', validators=[DataRequired(), Email()]) | ||
password = PasswordField('Password', validators=[DataRequired()]) | ||
submit = SubmitField('Register') | ||
|
||
|
||
class OrderItemForm(FlaskForm): | ||
product_id = HiddenField(validators=[DataRequired()]) | ||
quantity = IntegerField(validators=[DataRequired()]) | ||
order_id = HiddenField() | ||
submit = SubmitField('Update') | ||
|
||
|
||
class ItemForm(FlaskForm): | ||
product_id = HiddenField(validators=[DataRequired()]) | ||
quantity = HiddenField(validators=[DataRequired()], default=1) |
Oops, something went wrong.