11import logging
2- import uvicorn
2+ import os
33
4+ import uvicorn
45from fastapi import FastAPI
56from fastapi .middleware .cors import CORSMiddleware
67
7- from spaceone .core import config
8+ from spaceone .core import config , utils
89from spaceone .core .logger import set_logger
910from spaceone .core .opentelemetry import set_tracer , set_metric
1011from spaceone .core .extension .server_info import ServerInfoManager
@@ -130,7 +131,39 @@ def _init_fast_api():
130131 )
131132
132133
134+ def set_server_config_from_env ():
135+ package = os .environ .get ('SPACEONE_PACKAGE' )
136+ host = os .environ ['SPACEONE_HOST' ]
137+ module_path = tuple (os .environ .get ('SPACEONE_MODULE_PATH' ).split (', ' ))
138+ port = os .environ .get ('SPACEON_PORT' )
139+ config_file = os .environ .get ('SPACEONE_CONFIG_FILE' )
140+
141+ # 1. Set a python path
142+ utils .set_python_path (package , module_path )
143+
144+ # 2. Initialize config from command argument
145+ config .init_conf (
146+ package = package ,
147+ port = port
148+ )
149+
150+ # 3. Get service config from global_conf.py
151+ config .set_service_config ()
152+
153+ # 4. Merge file conf
154+ if config_file :
155+ config .set_file_conf (config_file )
156+
157+
133158def fast_api_app ():
159+ set_server_config_from_env ()
160+
161+ # Enable logging configuration\
162+ set_logger ()
163+
164+ # Set OTel Tracer and Metric|
165+ set_tracer ()
166+
134167 app = _init_fast_api ()
135168 app = _add_middlewares (app )
136169 app = _include_routers (app )
@@ -140,12 +173,6 @@ def fast_api_app():
140173def serve ():
141174 conf = config .get_global ()
142175
143- # Enable logging configuration\
144- set_logger ()
145-
146- # Set OTel Tracer and Metric|
147- set_tracer ()
148-
149176 uvicorn_options = conf .get ('UVICORN_OPTIONS' , {})
150177
151178 _LOGGER .info (f'Start REST Server ({ config .get_service ()} ): '
0 commit comments