From 3cd23700cbc925908c88f46119dcaac7e0edea0d Mon Sep 17 00:00:00 2001 From: Markbeep Date: Sun, 16 Mar 2025 18:52:52 +0100 Subject: [PATCH] add version to settings pages --- .github/workflows/build.yaml | 5 +++++ Dockerfile | 2 ++ app/internal/auth/oidc_config.py | 2 +- app/internal/env_settings.py | 1 + app/routers/settings.py | 32 +++++++++++++++++++++---------- docker-compose.yml | 5 ++++- templates/settings_page/base.html | 8 +++++++- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 28f1dc0..4ad99c7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -70,8 +70,11 @@ jobs: MINOR=$(echo $VERSION | cut -d. -f2) PATCH=$(echo $VERSION | cut -d. -f3) echo "::set-output name=tags::${{ secrets.DOCKER_HUB_USERNAME }}/audiobookrequest:$VERSION,${{ secrets.DOCKER_HUB_USERNAME }}/audiobookrequest:$MAJOR.$MINOR,${{ secrets.DOCKER_HUB_USERNAME }}/audiobookrequest:$MAJOR,${{ secrets.DOCKER_HUB_USERNAME }}/audiobookrequest:latest" + echo "::set-output name=version::$VERSION" else echo "::set-output name=tags::${{ secrets.DOCKER_HUB_USERNAME }}/audiobookrequest:nightly" + github_sha_hash=${{ github.sha }} + echo "::set-output name=version::${github_sha_hash:0:7}" fi - name: Build and push @@ -80,3 +83,5 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.vars.outputs.tags }} + build-args: | + VERSION=${{ steps.vars.outputs.version }} diff --git a/Dockerfile b/Dockerfile index 26c8e6f..fbfc7b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,8 @@ COPY app/ app/ RUN /bin/tailwindcss -i styles/globals.css -o static/globals.css -m ENV ABR_APP__PORT=8000 +ARG VERSION +ENV ABR_APP__VERSION=$VERSION CMD alembic upgrade heads && fastapi run --port $ABR_APP__PORT diff --git a/app/internal/auth/oidc_config.py b/app/internal/auth/oidc_config.py index 74c4e11..6508285 100644 --- a/app/internal/auth/oidc_config.py +++ b/app/internal/auth/oidc_config.py @@ -63,7 +63,7 @@ class oidcConfig(StringConfigCache[oidcConfigKey]): return "Failed to fetch OIDC configuration" data = await response.json() - config_scope = (self.get(session, "oidc_scope") or "").split(" ") + config_scope = self.get(session, "oidc_scope", "").split(" ") provider_scope = data.get("scopes_supported") if not provider_scope or not all( scope in provider_scope for scope in config_scope diff --git a/app/internal/env_settings.py b/app/internal/env_settings.py index 70d6d4e..09d12d8 100644 --- a/app/internal/env_settings.py +++ b/app/internal/env_settings.py @@ -13,6 +13,7 @@ class ApplicationSettings(BaseModel): openapi_enabled: bool = False config_dir: str = "/config" port: int = 8000 + version: str = "local" class Settings(BaseSettings): diff --git a/app/routers/settings.py b/app/routers/settings.py index 323763f..d63ef45 100644 --- a/app/routers/settings.py +++ b/app/routers/settings.py @@ -6,7 +6,6 @@ from aiohttp import ClientResponseError, ClientSession from fastapi import APIRouter, Depends, Form, HTTPException, Request, Response from sqlmodel import Session, select -from app.internal.auth.config import LoginTypeEnum, auth_config from app.internal.auth.authentication import ( DetailedUser, create_user, @@ -14,7 +13,9 @@ from app.internal.auth.authentication import ( is_correct_password, raise_for_invalid_password, ) +from app.internal.auth.config import LoginTypeEnum, auth_config from app.internal.auth.oidc_config import oidc_config +from app.internal.env_settings import Settings from app.internal.models import EventEnum, GroupEnum, Notification, User from app.internal.notifications import send_notification from app.internal.prowlarr.indexer_categories import indexer_categories @@ -35,7 +36,10 @@ def read_account( user: Annotated[DetailedUser, Depends(get_authenticated_user())], ): return template_response( - "settings_page/account.html", request, user, {"page": "account"} + "settings_page/account.html", + request, + user, + {"page": "account", "version": Settings().app.version}, ) @@ -84,7 +88,12 @@ def read_users( "settings_page/users.html", request, admin_user, - {"page": "users", "users": users, "is_oidc": is_oidc}, + { + "page": "users", + "users": users, + "is_oidc": is_oidc, + "version": Settings().app.version, + }, ) @@ -215,6 +224,7 @@ def read_prowlarr( "indexer_categories": indexer_categories, "selected_categories": selected, "prowlarr_misconfigured": True if prowlarr_misconfigured else False, + "version": Settings().app.version, }, ) @@ -304,6 +314,7 @@ def read_download( "name_ratio": name_ratio, "title_ratio": title_ratio, "indexer_flags": flags, + "version": Settings().app.version, }, ) @@ -443,6 +454,7 @@ def read_notifications( "page": "notifications", "notifications": notifications, "event_types": event_types, + "version": Settings().app.version, }, ) @@ -579,13 +591,13 @@ def read_security( "login_type": auth_config.get_login_type(session), "access_token_expiry": auth_config.get_access_token_expiry_minutes(session), "min_password_length": auth_config.get_min_password_length(session), - "oidc_endpoint": oidc_config.get(session, "oidc_endpoint") or "", - "oidc_client_secret": oidc_config.get(session, "oidc_client_secret") or "", - "oidc_client_id": oidc_config.get(session, "oidc_client_id") or "", - "oidc_scope": oidc_config.get(session, "oidc_scope") or "", - "oidc_username_claim": oidc_config.get(session, "oidc_username_claim") - or "", - "oidc_group_claim": oidc_config.get(session, "oidc_group_claim") or "", + "oidc_endpoint": oidc_config.get(session, "oidc_endpoint", ""), + "oidc_client_secret": oidc_config.get(session, "oidc_client_secret", ""), + "oidc_client_id": oidc_config.get(session, "oidc_client_id", ""), + "oidc_scope": oidc_config.get(session, "oidc_scope", ""), + "oidc_username_claim": oidc_config.get(session, "oidc_username_claim", ""), + "oidc_group_claim": oidc_config.get(session, "oidc_group_claim", ""), + "version": Settings().app.version, }, ) diff --git a/docker-compose.yml b/docker-compose.yml index f36c5e0..7e096aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,9 @@ services: web: - build: . + build: + context: . + args: + - VERSION=local volumes: - ./config:/config ports: diff --git a/templates/settings_page/base.html b/templates/settings_page/base.html index 3cd8adf..b5ee1a2 100644 --- a/templates/settings_page/base.html +++ b/templates/settings_page/base.html @@ -1,6 +1,12 @@ {% extends "base.html" %} {% block head %} Settings -{% endblock %} {% block body %} +{% endblock %} {% block body %} {% if version %} +

+ version: {{ version }} +

+{% endif %}