4
0
Fork 0

Initial commit
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Pünkösd Marcell 2020-04-15 00:33:06 +02:00
parent 758630f925
commit fd83e268ef
10 changed files with 115 additions and 27 deletions

View File

@ -1,28 +1,9 @@
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.8-slim
FROM python:3
# Copy local code to the container image.
ENV APP_HOME /app
ENV PIP_NO_CACHE_DIR=true
ADD classification_service requirements.txt /classification_service/
WORKDIR /classification_service/
# Set timezone
ENV TZ Europe/Budapest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN pip3 install -r requirements.txt && pip3 install gunicorn
WORKDIR $APP_HOME
ARG RELEASE_ID
ENV RELEASE_ID ${RELEASE_ID:-""}
#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"]
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]

View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import os
from flask import Flask
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
# import stuff
from utils import register_all_error_handlers
# import views
from views import ClassifyView
# Setup sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[FlaskIntegration()],
send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'),
environment=os.environ.get('RELEASEMODE', 'dev')
)
# create flask app
app = Flask(__name__)
# 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 [ClassifyView]:
view.register(app, trailing_slash=False)
# start debugging if needed
if __name__ == "__main__":
app.run(debug=True)

View File

@ -0,0 +1,2 @@
#!/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,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 .classify_view import ClassifyView

View File

@ -0,0 +1,11 @@
#!/usr/bin/env python3
from flask import request, jsonify
from flask_classful import FlaskView
from utils import json_required
class ClassifyView(FlaskView):
@json_required
def post(self):
return jsonify(request.json)

View File

@ -1,2 +1,14 @@
sentry_sdk
gunicorn
requests
blinker
Flask
marshmallow
Flask-Classful
sentry-sdk
pyAudioanalysis
numpy
eyed3
pydub
scipy
matplotlib
sklearn