All configurations are placed in the config directory at the root of the project.
- Load key-value pairs from environment variables to override configurations.
- Load environment-specific configurations from
config_xxx.pyin theconfigdirectory, wherexxxrepresents the specific environment. - Load configurations from
config.pyin theconfigdirectory. - Load the default configurations provided by the framework.
- Start the service using the default configuration:
pfs
- Start the service using the
testenvironment configuration, which inherits from the default configuration:
pfs test
- Start the service using the
dailyenvironment configuration, inheriting from the default configuration, and set the number of workers to 4:
workers=4 pfs daily
- Start the service using both
localanddailyconfigurations, wherelocal(on the left) has higher priority, while also inheriting from the default configuration:
pfs local daily
Please note, debug is a reserved keyword in the framework and cannot be used as an environment name. For example, config_debug.py will not take effect.
- When the container starts, it defaults to using the
prodenvironment configuration (i.e., prioritizes configurations fromconfig_prod.py):
docker run your-image
- Start the container using a specified environment (e.g.,
local), with support forlocal,daily, andprodenvironments by default:
docker run your-image local
Configuration items are injected into Flask’s config. The recommended way to access them is as follows:
from ab import app
app.config['YOUR_CONFIG_KEY']
# or
app.config.YOUR_CONFIG_KEY- Framework plugin configurations
- Flask configuration items (all uppercase)
- Gunicorn configuration items (all lowercase)
- User-defined configurations
The config inherits settings from Flask and Gunicorn, with additional custom configurations from ab. Therefore, all configurations can be written in the same config.py file.
Supported configuration items:
- APP_NAME: The algorithm name used for registration in Spring Cloud. Ensure each algorithm has a unique name.
since v2.4.2: The separator should be
-instead of_. Must be changed when deploying to a server. Required field. - PORT: The port number can no longer be modified. Inside Docker, Nginx uses a fixed port 80 to access Gunicorn on port 8000.
- HOST: Specifies which IP to bind to. Typically use
localhostfor local testing, and0.0.0.0for server deployment. Default is 'localhost'. Reference: What is the difference between 0.0.0.0, 127.0.0.1, and localhost? - DEBUG: Whether to enable Flask and Gunicorn debug mode, default is
False. SettingDEBUG=Trueallows the execution of arbitrary code. Avoid using the combination ofHOST=0.0.0.0andDEBUG=Truewhen deploying to a server. - LOG_LEVEL: The global default logging level, which relies on Python’s logging module.
See logging levels for level details.
If unspecified, the default level is
INFO.