Created skeleton
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2020-03-25 00:19:12 +01:00
parent db72904b62
commit 453b686cbe
12 changed files with 111 additions and 21 deletions

10
.gitignore vendored
View File

@ -131,3 +131,13 @@ dmypy.json
#Pycharm #Pycharm
.idea/ .idea/
*.iml *.iml
# Wing project file
*.wpr
# Nano, vi, vim lockfile
*.swp
# log
*.log

View File

@ -1,28 +1,14 @@
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.8-slim FROM python:3.8-slim
# Copy local code to the container image. ADD storage_service requirements.txt /storage_service/
ENV APP_HOME /app WORKDIR /storage_service/
ENV PIP_NO_CACHE_DIR=true
# Set timezone ENV PIP_NO_CACHE_DIR=true
ENV TZ Europe/Budapest ENV TZ Europe/Budapest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR $APP_HOME RUN pip3 install -r requirements.txt
ARG RELEASE_ID EXPOSE 8000
ENV RELEASE_ID ${RELEASE_ID:-""} CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]
#Copy requirements to install
COPY requirements.txt ./
# Install production dependencies.
RUN pip install -r requirements.txt
COPY ./src ./src
EXPOSE 8080
ENTRYPOINT ["gunicorn", "-b", "0.0.0.0:8080", "--workers", "1", "--threads", "8", "app:app"]

1
requirements-dev.txt Normal file
View File

@ -0,0 +1 @@
pytest

View File

@ -1,2 +1,8 @@
sentry_sdk requests
blinker
Flask
marshmallow
Flask-Classful
gunicorn gunicorn
sentry_sdk
flask_minio

31
storage_service/app.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import os
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
# import stuff
from utils import register_all_error_handlers
# import views
from views import ObjectView
# create flask app
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
# register error handlers
register_all_error_handlers(app)
# register views
for view in [ObjectView]:
view.register(app, trailing_slash=False)
# start debuggig if needed
if __name__ == "__main__":
app.run(debug=True)

View File

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

View File

@ -0,0 +1 @@
import os

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,21 @@
#!/usr/bin/env python3
def get_standard_error_handler(code: int):
def error_handler(err):
return {"msg": str(err)}, code
return error_handler
def register_all_error_handlers(app):
"""
function to register all handlers
"""
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,19 @@
#!/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 .object_view import ObjectView

View File

@ -0,0 +1,9 @@
#!/usr/bin/env python3
from flask import jsonify
from flask_classful import FlaskView
class ObjectView(FlaskView):
def post(self):
return jsonify({}), 200