storage-service/storage_service/app.py
Torma Kristóf 475e0e7242
All checks were successful
continuous-integration/drone/push Build is passing
update helathcheck
2020-12-06 11:14:40 +01:00

61 lines
1.7 KiB
Python

#!/usr/bin/env python3
import os
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
from healthcheck import HealthCheck
# import stuff
from utils import register_all_error_handlers, storage, health_database_status
# import views
from views import ObjectView
# Setup sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[FlaskIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'),
environment=os.environ.get('RELEASEMODE', 'dev'),
_experiments={"auto_enabling_integrations": True}
)
# create flask app
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# init stuff
storage.init_app(app)
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
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_BUCKET_NAME'] = os.environ['MINIO_BUCKET_NAME']
app.config['MINIO_SECURE'] = os.environ.get('MINIO_SECURE', False)
app.config['MINIO_REGION'] = os.environ.get('MINIO_REGION', None)
health = HealthCheck()
# register error handlers
register_all_error_handlers(app)
# register views
for view in [ObjectView]:
view.register(app, trailing_slash=False)
health.add_check(health_database_status)
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
# start debugging if needed
if __name__ == "__main__":
app.run(debug=True)