This repository has been archived on 2026-05-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagerepo/config.py
T

34 lines
1.1 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
SQLALCHEMY_ENGINE_OPTIONS = {
"pool_pre_ping": True
}