project layout done
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-03-25 01:19:22 +01:00
parent 265d43f79b
commit 03bf58bab3
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
8 changed files with 177 additions and 13 deletions

View File

@ -1,27 +1,18 @@
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.8-slim
# Copy local code to the container image.
ENV APP_HOME /app
ENV PIP_NO_CACHE_DIR=true
# Set timezone
ENV TZ Europe/Budapest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR $APP_HOME
WORKDIR /app
ARG RELEASE_ID
ENV RELEASE_ID ${RELEASE_ID:-""}
#Copy requirements to install
COPY requirements.txt ./
# Install production dependencies.
RUN pip install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY ./src ./src
COPY ./src .
EXPOSE 8080

30
k8s/deployment.yaml Normal file
View File

@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: input-service
namespace: birbnetes
labels:
app: input-service
spec:
replicas: 1
selector:
matchLabels:
app: input-service
strategy:
type: Recreate
template:
metadata:
labels:
app: input-service
spec:
containers:
- image:
name: registry.kmlabz.com/tormakris/input-service
env:
- name: SENTRY_DSN
valueFrom:
secretKeyRef:
name: sentry-dsn
key: input-service
ports:
- containerPort: 8080

16
k8s/service.yaml Normal file
View File

@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: input-service
namespace: birbnetes
labels:
app: input-service
spec:
ports:
- name: input-service
port: 8080
targetPort: 8080
protocol: TCP
selector:
app: input-service
type: ClusterIP

View File

@ -1,2 +1,6 @@
sentry_sdk
gunicorn
gunicorn
marshmallow
Flask
Flask-RESTful
requests

50
src/app.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
import logging
import sentry_sdk
from flask import Flask
from flask_restful import Api
from sentry_sdk.integrations.flask import FlaskIntegration
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, PORT, DEBUG
from resources import *
"""
Main Flask RESTful API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "app"
__version__text__ = "1"
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[FlaskIntegration()],
send_default_pii=True,
release=RELEASE_ID,
environment=RELEASEMODE
)
app = Flask(__name__)
api = Api(app)
formatter = logging.Formatter(
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
api.add_resource(SampleResource, "/v1/input/sample")
if __name__ == "__main__":
app.run(
debug=bool(DEBUG),
host="0.0.0.0",
port=int(PORT),
)

22
src/config.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import os
"""
Main Flask RESTful API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "app"
__version__text__ = "1"
PORT = os.environ.get("INPUT_SERVICE_PORT", 8080)
DEBUG = os.environ.get("INPUT_SERVICE_DEBUG", True)
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID")
RELEASEMODE = os.environ.get("INPUT_SERVICE_RELEASEMODE")

26
src/resources.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import logging
import os
from flask import request
from flask_restful import Resource
from schemas import *
"""
Flask Restful endpoints
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "endpoints"
__version__text__ = "1"
LOGGER = logging.getLogger(__name__)
class SampleResource(Resource):
"""
Sample endpoint
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
"""
def post(self):
pass

25
src/schemas.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
from marshmallow import Schema, fields
"""
Schemas of input objects
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2019, KSZK"
__module_name__ = "schemas"
__version__text__ = "1"
class SampleSchema(Schema):
""" /v1/email/pay - POST
Parameters:
- date (date)
- device_id (str)
"""
date = fields.Date(required=True)
device_id = fields.Str(required=True)