Some generic fixes

This commit is contained in:
Pünkösd Marcell 2021-08-04 16:42:28 +02:00
parent 8ed165a348
commit edbd17f79d
2 changed files with 36 additions and 20 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
import os
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
@ -13,34 +12,23 @@ from utils import register_all_error_handlers, storage
# import views
from views import SVMView, CNNView, RootView
# Setup sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN:
from config import Config
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration()],
send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'),
environment=os.environ.get('RELEASEMODE', 'dev')
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE
)
# create flask app
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# configure flask app
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI', "sqlite://") # Default to memory db
app.config['MINIO_ENDPOINT'] = os.environ['MINIO_ENDPOINT']
app.config['MINIO_ACCESS_KEY'] = os.environ['MINIO_ACCESS_KEY']
app.config['MINIO_SECRET_KEY'] = os.environ['MINIO_SECRET_KEY']
app.config['MINIO_SVM_BUCKET_NAME'] = os.environ.get('MINIO_SVM_BUCKET_NAME', 'svm')
app.config['MINIO_CNN_BUCKET_NAME'] = os.environ.get('MINIO_CNN_BUCKET_NAME', 'cnn')
app.config['MINIO_SECURE'] = os.environ.get('MINIO_SECURE', False)
app.config['MINIO_REGION'] = os.environ.get('MINIO_REGION', None)
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
# disable this for better performance
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# load config
app.config.from_object(Config)
# initialize stuff
db.init_app(app)
@ -62,3 +50,9 @@ for view in [SVMView, CNNView, RootView]:
# start debuggig if needed
if __name__ == "__main__":
app.run(debug=True)
else:
import logging
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)

22
model_service/config.py Normal file
View File

@ -0,0 +1,22 @@
import os
class Config:
# sentry stuff
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
# configure flask app
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI', "sqlite://") # Default to memory db
MINIO_ENDPOINT = os.environ['MINIO_ENDPOINT']
MINIO_ACCESS_KEY = os.environ['MINIO_ACCESS_KEY']
MINIO_SECRET_KEY = os.environ['MINIO_SECRET_KEY']
MINIO_SVM_BUCKET_NAME = os.environ.get('MINIO_SVM_BUCKET_NAME', 'svm')
MINIO_CNN_BUCKET_NAME = os.environ.get('MINIO_CNN_BUCKET_NAME', 'cnn')
MINIO_SECURE = os.environ.get('MINIO_SECURE', False)
MINIO_REGION = os.environ.get('MINIO_REGION', None)
# important stuff
SECRET_KEY = os.environ.get('SECRET_KEY', os.urandom(12))
# disable this for better performance
SQLALCHEMY_TRACK_MODIFICATIONS = False