-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
96 lines (77 loc) · 2.41 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import traceback
from flask import Flask, request
from flask_cors import CORS
from flask_socketio import SocketIO
import config
from common.logger import Logger
from common.response import Response
from model.db import clean_db_session
from service.build_namespace import build_namespace
from service.deploy_namespace import deploy_namespace
from service.scheduler import run_schedule
from view.build import build_bp
from view.db_inst import db_inst_bp
from view.deploy import deploy_bp
from view.docker import docker_bp
from view.harbor import harbor_bp
from view.k8s import k8s_bp
from view.project import project_bp
from view.template import template_bp
from view.user import user_bp
app = Flask(__name__)
log = Logger(__name__)
app.config.from_object(config)
CORS(app, supports_credentials=True)
socketio = SocketIO(
app,
# engineio_logger=log.logger if env_util.is_dev() else False,
engineio_logger=False,
logger=False,
cors_allowed_origins='*',
)
app.register_blueprint(user_bp, url_prefix='/user')
app.register_blueprint(project_bp, url_prefix='/project')
app.register_blueprint(build_bp, url_prefix='/build')
app.register_blueprint(template_bp, url_prefix='/template')
app.register_blueprint(db_inst_bp, url_prefix='/db_inst')
app.register_blueprint(k8s_bp, url_prefix='/k8s')
app.register_blueprint(docker_bp, url_prefix='/docker')
app.register_blueprint(deploy_bp, url_prefix='/deploy')
app.register_blueprint(harbor_bp, url_prefix='/harbor')
@app.before_request
def before_request():
log.info(request)
@app.after_request
def after_request(response):
if response.json:
log.info(response)
return response
@app.teardown_request
def teardown_request(error):
clean_db_session()
if error is not None:
log.error(error)
@app.errorhandler(Exception)
def error_handler(exception: Exception):
if exception:
log.error(traceback.format_exc())
return Response.failed(msg=f'{exception}')
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/favicon.ico')
def favicon():
return app.send_static_file('favicon.png')
socketio.on_namespace(build_namespace)
socketio.on_namespace(deploy_namespace)
run_schedule()
if __name__ == '__main__':
socketio.init_app(app, async_mode='gevent')
socketio.run(
app,
use_reloader=config.FLASK_USE_RELOAD,
host='0.0.0.0',
port=config.PORT,
debug=True,
log_output=False
)