35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import os
|
|
|
|
class Config:
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'you-will-never-guess')
|
|
DB_TYPE = os.environ.get('DB_TYPE', 'sqlite').lower() # 'sqlite' or 'postgresql'
|
|
|
|
if DB_TYPE == 'postgresql':
|
|
DB_USER = os.environ.get('DB_USER', 'imagerepo')
|
|
DB_PASS = os.environ.get('DB_PASS', 'postgres')
|
|
DB_HOST = os.environ.get('DB_HOST', 'postgres')
|
|
DB_PORT = os.environ.get('DB_PORT', '5432')
|
|
DB_NAME = os.environ.get('DB_NAME', 'imagerepo')
|
|
|
|
SQLALCHEMY_DATABASE_URI = (
|
|
f'postgresql://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}'
|
|
)
|
|
|
|
elif DB_TYPE == 'sqlite':
|
|
DB_DIR = '/db'
|
|
os.makedirs(DB_DIR, exist_ok=True) # only works if /db is writable
|
|
DB_NAME = os.environ.get('DB_NAME', 'app.db')
|
|
SQLALCHEMY_DATABASE_URI = f'sqlite:///{os.path.join(DB_DIR, DB_NAME)}'
|
|
|
|
|
|
|
|
else:
|
|
raise ValueError(f"Unsupported DB_TYPE '{DB_TYPE}'. Use 'sqlite' or 'postgresql'.")
|
|
|
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
# Celery configuration
|
|
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://redis:6379/0')
|
|
CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'redis://redis:6379/0')
|
|
CELERY_WORKER_CONCURRENCY = int(os.environ.get('CELERY_WORKER_CONCURRENCY', '2'))
|