mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-03 13:13:27 +08:00
Partially revert the change of split config (a207d97)
It turns out we still have some backend code relies on the flask app, so revert the change to init_config, and make minor change to create config object for frontend and backend with the same function.
This commit is contained in:
@@ -7,6 +7,9 @@ dbdir = path.abspath(path.join(confdir, "..")) if confdir.endswith("conf") else
|
||||
|
||||
|
||||
class BackendConfiguration(object):
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(path.join(dbdir, "module_build_service.db"))
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = True
|
||||
|
||||
# How often should we resort to polling, in seconds
|
||||
# Set to zero to disable polling
|
||||
POLLING_INTERVAL = 600
|
||||
|
||||
@@ -7,6 +7,10 @@ dbdir = path.abspath(path.join(confdir, "..")) if confdir.endswith("conf") else
|
||||
|
||||
|
||||
class WebConfiguration(object):
|
||||
SECRET_KEY = "74d9e9f9cd40e66fc6c4c2e9987dce48df3ce98542529fd0"
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(path.join(dbdir, "module_build_service.db"))
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = True
|
||||
|
||||
# Where we should run when running "manage.py run" directly.
|
||||
HOST = "0.0.0.0"
|
||||
PORT = 5000
|
||||
|
||||
@@ -36,7 +36,7 @@ from module_build_service.logger import init_logging, ModuleBuildLogs, level_fla
|
||||
from module_build_service.errors import (
|
||||
ValidationError, Unauthorized, UnprocessableEntity, Conflict, NotFound,
|
||||
Forbidden, json_error)
|
||||
from module_build_service.config import init_web_config, init_backend_config
|
||||
from module_build_service.config import init_config
|
||||
from module_build_service.proxy import ReverseProxy
|
||||
|
||||
try:
|
||||
@@ -51,9 +51,9 @@ app.wsgi_app = ReverseProxy(app.wsgi_app)
|
||||
backend_commands = ("fedmsg-hub", "celery", "build_module_locally")
|
||||
if any([os.path.basename(arg).startswith(backend_commands) for arg in sys.argv]):
|
||||
# running as backend
|
||||
conf = init_backend_config()
|
||||
conf = init_config(app, backend=True)
|
||||
else:
|
||||
conf = init_web_config(app)
|
||||
conf = init_config(app)
|
||||
|
||||
celery_app = Celery("module-build-service")
|
||||
# Convert config names specific for Celery like this:
|
||||
|
||||
@@ -474,8 +474,7 @@ class KojiModuleBuilder(GenericBuilder):
|
||||
def get_session(config, login=True):
|
||||
"""Create and return a koji.ClientSession object
|
||||
|
||||
:param config: the config object returned from :meth:`init_web_config` or
|
||||
:meth:`init_backend_config`.
|
||||
:param config: the config object returned from :meth:`init_config`.
|
||||
:type config: :class:`Config`
|
||||
:param bool login: whether to log into the session. To login if True
|
||||
is passed, otherwise not to log into session.
|
||||
|
||||
@@ -24,11 +24,19 @@ SUPPORTED_RESOLVERS = {
|
||||
}
|
||||
|
||||
|
||||
def init_web_config(app):
|
||||
def init_config(app, backend=False):
|
||||
""" Configure MBS and the Flask app
|
||||
By default, this create a config object with WebConfig, if backend is specified,
|
||||
create a config object with BackendConfig.
|
||||
"""
|
||||
config_module = None
|
||||
config_file = "/etc/module-build-service/web_config.py"
|
||||
if backend:
|
||||
config_module_name = "backend_config"
|
||||
config_file = "/etc/module-build-service/backend_config.py"
|
||||
else:
|
||||
config_module_name = "web_config"
|
||||
config_file = "/etc/module-build-service/web_config.py"
|
||||
|
||||
config_section = "DevConfiguration"
|
||||
|
||||
# automagically detect production environment:
|
||||
@@ -66,13 +74,14 @@ def init_web_config(app):
|
||||
if "MBS_CONFIG_SECTION" in app.request.environ:
|
||||
config_section = app.request.environ["MBS_CONFIG_SECTION"]
|
||||
|
||||
test_env = False
|
||||
dev_env = False
|
||||
|
||||
true_options = ("1", "on", "true", "y", "yes")
|
||||
# TestConfiguration shall only be used for running tests, otherwise...
|
||||
if any(["py.test" in arg or "pytest" in arg for arg in sys.argv]):
|
||||
test_env = True
|
||||
config_section = "TestConfiguration"
|
||||
from conf import web_config
|
||||
|
||||
config_module = web_config
|
||||
# ...MODULE_BUILD_SERVICE_DEVELOPER_ENV has always the last word
|
||||
# and overrides anything previously set before!
|
||||
# Again, check Flask app (preferably) or fallback to os.environ.
|
||||
@@ -80,15 +89,16 @@ def init_web_config(app):
|
||||
# -> /conf/config.py.
|
||||
elif flask_app_env and "MODULE_BUILD_SERVICE_DEVELOPER_ENV" in app.request.environ:
|
||||
if app.request.environ["MODULE_BUILD_SERVICE_DEVELOPER_ENV"].lower() in true_options:
|
||||
dev_env = True
|
||||
config_section = "DevConfiguration"
|
||||
from conf import web_config
|
||||
|
||||
config_module = web_config
|
||||
elif os.environ.get("MODULE_BUILD_SERVICE_DEVELOPER_ENV", "").lower() in true_options:
|
||||
dev_env = True
|
||||
config_section = "DevConfiguration"
|
||||
from conf import web_config
|
||||
|
||||
config_module = web_config
|
||||
if test_env or dev_env:
|
||||
import importlib
|
||||
config_module = importlib.import_module("conf.%s" % config_module_name)
|
||||
|
||||
# try loading configuration from file
|
||||
if not config_module:
|
||||
try:
|
||||
@@ -98,63 +108,14 @@ def init_web_config(app):
|
||||
|
||||
# finally configure MBS and the Flask app
|
||||
config_section_obj = getattr(config_module, config_section)
|
||||
conf = WebConfig(config_section_obj)
|
||||
if backend:
|
||||
conf = BackendConfig(config_section_obj)
|
||||
else:
|
||||
conf = WebConfig(config_section_obj)
|
||||
app.config.from_object(config_section_obj)
|
||||
return conf
|
||||
|
||||
|
||||
def init_backend_config():
|
||||
""" Configure MBS and backend workers
|
||||
"""
|
||||
config_module = None
|
||||
config_file = "/etc/module-build-service/backend_config.py"
|
||||
config_section = "DevConfiguration"
|
||||
|
||||
try:
|
||||
with open(config_file):
|
||||
config_section = "ProdConfiguration"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Load LocalBuildConfiguration section in case we are building modules
|
||||
# locally.
|
||||
if "build_module_locally" in sys.argv:
|
||||
if "--offline" in sys.argv:
|
||||
config_section = "OfflineLocalBuildConfiguration"
|
||||
else:
|
||||
config_section = "LocalBuildConfiguration"
|
||||
|
||||
# try getting config_file from os.environ
|
||||
if "MBS_CONFIG_FILE" in os.environ:
|
||||
config_file = os.environ["MBS_CONFIG_FILE"]
|
||||
# try getting config_section from os.environ
|
||||
if "MBS_CONFIG_SECTION" in os.environ:
|
||||
config_section = os.environ["MBS_CONFIG_SECTION"]
|
||||
|
||||
true_options = ("1", "on", "true", "y", "yes")
|
||||
# TestConfiguration shall only be used for running tests, otherwise...
|
||||
if any(["py.test" in arg or "pytest" in arg for arg in sys.argv]):
|
||||
config_section = "TestConfiguration"
|
||||
from conf import backend_config
|
||||
|
||||
config_module = backend_config
|
||||
elif os.environ.get("MODULE_BUILD_SERVICE_DEVELOPER_ENV", "").lower() in true_options:
|
||||
config_section = "DevConfiguration"
|
||||
from conf import backend_config
|
||||
|
||||
config_module = backend_config
|
||||
# try loading configuration from file
|
||||
if not config_module:
|
||||
try:
|
||||
config_module = imp.load_source("mbs_runtime_config", config_file)
|
||||
except Exception:
|
||||
raise SystemError("Configuration file {} was not found.".format(config_file))
|
||||
|
||||
config_section_obj = getattr(config_module, config_section)
|
||||
conf = BackendConfig(config_section_obj)
|
||||
return conf
|
||||
|
||||
|
||||
class Path:
|
||||
"""
|
||||
Config type for paths. Expands the users home directory.
|
||||
|
||||
@@ -663,8 +663,8 @@ class ModuleBuild(MBSBase):
|
||||
bus.
|
||||
|
||||
:param db_session: SQLAlchemy session object.
|
||||
:param conf: MBS config object returned from function :func:`init_web_config` or
|
||||
:func:`init_backend_config`, which contains loaded configs.
|
||||
:param conf: MBS config object returned from function :func:`init_config`,
|
||||
which contains loaded configs.
|
||||
:type conf: :class:`Config`
|
||||
:param int state: the state value to transition to. Refer to ``BUILD_STATES``.
|
||||
:param str state_reason: optional reason of why to transform to ``state``.
|
||||
|
||||
@@ -14,7 +14,7 @@ import koji
|
||||
import module_build_service
|
||||
from module_build_service import db
|
||||
from module_build_service.utils import get_rpm_release, import_mmd, mmd_to_str
|
||||
from module_build_service.config import init_web_config
|
||||
from module_build_service.config import init_config
|
||||
from module_build_service.models import (
|
||||
ModuleBuild, ModuleArch, ComponentBuild, VirtualStream,
|
||||
BUILD_STATES,
|
||||
@@ -25,7 +25,7 @@ from module_build_service.db_session import db_session
|
||||
|
||||
base_dir = os.path.dirname(__file__)
|
||||
app = module_build_service.app
|
||||
conf = init_web_config(app)
|
||||
conf = init_config(app)
|
||||
|
||||
|
||||
def staged_data_filename(filename):
|
||||
|
||||
Reference in New Issue
Block a user