Table of Contents
- Configuration Loading
- Check if running under pytest
- Load config/app_config.yaml unless in test environment
- Configuration Categories
- Best Practices
- Examples
Configuration Loading
This directory contains documentation for Blueberry IDP's configuration loading mechanisms and priority systems.
Overview
The configuration loading system implements a priority-based approach where settings can be sourced from multiple locations with clear precedence rules.
Configuration Priority
The system follows this priority order (highest to lowest):
- Environment Variables - Direct OS environment variables
- config/app_config.yaml - Repository configuration file
- Default Values - Hard-coded fallback values
Loading Process
Settings Class Initialization
The Settings
class in blueberry/config.py
handles all configuration loading:
class Settings:
def __init__(self, *, debug: bool | None = None, in_cluster: bool | None = None):
# Check if running under pytest
running_under_pytest = os.getenv("PYTEST_CURRENT_TEST") is not None
# Load config/app_config.yaml unless in test environment
if not running_under_pytest:
config_path = Path(__file__).parent.parent / "config/app_config.yaml"
if config_path.exists():
with open(config_path) as f:
file_config = yaml.safe_load(f) or {}
else:
file_config = {}
else:
file_config = {}
Helper Functions
The system uses helper functions to implement the priority logic:
get_config(env_var, file_key, default)
- String valuesget_bool_config(env_var, file_key, default)
- Boolean valuesget_int_config(env_var, file_key, default)
- Integer values
Test Environment Handling
The system automatically detects test environments and skips file configuration to ensure consistent test behavior with default values.
Configuration Categories
API Configuration
API_TITLE
- Application titleAPI_VERSION
- Application versionDEBUG
- Debug mode flag
Server Configuration
HOST
- Server bind addressPORT
- Server portRELOAD
- Auto-reload flag
GCP Configuration
GCP_PROJECT_ID
- Google Cloud project IDREGION
- Default GCP regionGCS_BUCKET
- Storage bucket name
Integration Configuration
GITLAB_URL
- GitLab instance URLREDIS_HOST
- Redis server hostFIREBASE_PROJECT
- Firebase project ID
Environment Configuration
ENVIRONMENT_PREFIX
- Environment naming prefixENVIRONMENT_TTL_HOURS
- Default environment TTLEPHEMERAL_DOMAIN
- Base domain for environments
Best Practices
Environment Variables
- Use uppercase names with underscores
- Provide sensible defaults
- Document all environment variables
Configuration Files
- Use
config/app_config.yaml
for development overrides - Don't commit sensitive values to version control
- Use consistent naming with environment variables
Default Values
- Provide safe defaults for all configuration
- Use values that work in development environments
- Document the purpose of each setting
Examples
Environment Variable Override
export DEBUG=true
export PORT=8080
export GCP_PROJECT_ID=my-project
Configuration File Override
# config/app_config.yaml
debug: true
port: 8080
gcp_project_id: my-project
Programmatic Access
from blueberry.config import get_settings
settings = get_settings()
print(f"Debug mode: {settings.debug}")
print(f"Project ID: {settings.project_id}")
Troubleshooting
Configuration Not Loading
- Check file path:
config/app_config.yaml
should be in repository root - Verify YAML syntax is valid
- Ensure environment variables use correct names
Test Environment Issues
- Tests use default values only
- File configuration is ignored in tests
- Use explicit parameters for test-specific settings
Priority Confusion
- Environment variables always win
- File config overrides defaults
- Use
get_settings()
to inspect final values
Related Files
blueberry/config.py
- Main configuration classconfig/app_config.yaml
- Development configuration filecharts/blueberry/templates/configmap.yml
- Kubernetes ConfigMap templatecharts/blueberry/values.yaml
- Helm default values
Document ID: reference/configuration/loading/README