Added skeleton
continuous-integration/drone/push Build was killed Details

This commit is contained in:
Pünkösd Marcell 2021-04-14 19:22:22 +02:00
commit 7a3cb2afd8
12 changed files with 164 additions and 0 deletions

25
.drone.yml Normal file
View File

@ -0,0 +1,25 @@
kind: pipeline
type: docker
name: default
steps:
-
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
sonar_host:
from_secret: SONAR_HOST
sonar_token:
from_secret: SONAR_CODE
- name: kaniko
image: banzaicloud/drone-kaniko
settings:
registry: registry.kmlabz.com
repo: universalrobots/${DRONE_REPO_NAME}
username:
from_secret: DOCKER_USERNAME
password:
from_secret: DOCKER_PASSWORD
tags:
- latest
- ${DRONE_BUILD_NUMBER}

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
*.swp
venv
*.pyc
__pycache__/*
__pycache__
*.wpr
*.log
.idea

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3.9
ADD program_service requirements.txt /program_service/
WORKDIR /program_service/
RUN pip3 install -r requirements.txt && pip3 install gunicorn
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]

35
program_service/app.py Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
from config import Config
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
from utils import register_all_error_handlers
# import views
from views import ProgramView
# Setup sentry
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration()],
send_default_pii=True,
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE
)
# create flask app
app = Flask(__name__)
app.config.from_object(Config)
register_all_error_handlers(app)
# register views
for view in [ProgramView]:
view.register(app, trailing_slash=False)
# start debuggig if needed
if __name__ == "__main__":
app.run(debug=True)

15
program_service/config.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
import os
"""
Configuration
"""
class Config:
SECRET_KEY = os.environ.get("SECRET_KEY", os.urandom(12))
CORS_ORIGINS = os.environ.get("ALLOWED_ORIGINS", "*")
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")

View File

@ -0,0 +1 @@
#!/usr/bin/env python3

View File

@ -0,0 +1,3 @@
#!/usr/bin/env python3
from .require_decorators import json_required
from .error_handlers import register_all_error_handlers

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
def get_standard_error_handler(code: int):
def error_handler(err):
return {"msg": str(err)}, code
return error_handler
# function to register all handlers
def register_all_error_handlers(app):
error_codes_to_override = [404, 403, 401, 405, 400, 409, 422]
for code in error_codes_to_override:
app.register_error_handler(code, get_standard_error_handler(code))

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
from flask import request, current_app, abort
from functools import wraps
def json_required(f):
@wraps(f)
def call(*args, **kwargs):
if request.is_json:
return f(*args, **kwargs)
else:
abort(400, "JSON required")
return call

View File

@ -0,0 +1,2 @@
#!/usr/bin/env python3
from .program_view import ProgramView

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
from flask import request, jsonify, current_app, abort, Response
from flask_classful import FlaskView, route
class ProgramView(FlaskView):
def index(self):
pass
def get(self, _id: str):
pass
def post(self):
pass
@route('<_id>/details')
def get_details(self, _id: str):
pass
def delete(self, _id: str):
pass

9
requirements.txt Normal file
View File

@ -0,0 +1,9 @@
pymongo~=3.11.3
pyyaml
blinker
Flask
marshmallow
Flask-Classful
sentry-sdk