50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Flask application factory."""
|
|
import logging
|
|
|
|
from flask import Flask
|
|
|
|
from . import auth, scheduler, settings
|
|
from .routes import bp as main_bp
|
|
from .filters import register_filters
|
|
|
|
|
|
def create_app():
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
)
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = settings.SECRET_KEY
|
|
|
|
register_filters(app)
|
|
auth.init_app(app) # OIDC (Authentik) — no-op if unconfigured
|
|
app.register_blueprint(main_bp)
|
|
|
|
@app.context_processor
|
|
def _inject_globals():
|
|
# In dev we pull Tailwind from the Play CDN for zero-build styling;
|
|
# in Docker the multi-stage build compiles static/app.css instead.
|
|
from . import store
|
|
try:
|
|
excluded_count = sum(
|
|
1 for s in store.load().get("stacks", []) if not s.get("enabled", True))
|
|
except Exception: # noqa: BLE001
|
|
excluded_count = 0
|
|
return {
|
|
"dev_mode": settings.DEV_MODE,
|
|
"tailwind_cdn": settings.DEV_MODE,
|
|
"oidc_enabled": settings.oidc_enabled(),
|
|
"excluded_count": excluded_count,
|
|
}
|
|
|
|
scheduler.start() # start the cron scheduler
|
|
|
|
app.logger.info(
|
|
"dockhand-backup started (dev_mode=%s, dockhand=%s, oidc=%s)",
|
|
settings.DEV_MODE,
|
|
"real" if settings.dockhand_configured() else "mock",
|
|
"on" if settings.oidc_enabled() else "off",
|
|
)
|
|
return app
|