From 17acdba04a9202bbd61128ebd47b917ff89fa04a Mon Sep 17 00:00:00 2001 From: 0x1026 <69076992+0x1026@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:09:18 +0100 Subject: [PATCH] fix(api): update image version handling and remove SENTRY_RELEASE property --- api/src/config.py | 10 ++-------- api/src/main.py | 4 ++-- api/tests/test_config.py | 14 +++++--------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/api/src/config.py b/api/src/config.py index 19cefc8..2f29b8e 100644 --- a/api/src/config.py +++ b/api/src/config.py @@ -32,8 +32,8 @@ class Settings(BaseSettings): def check_image_version(cls, v): if v == "": return None - if v.startswith("v"): - return v[1:] + if v and not v.startswith("v"): + return f"v{v}" return v @model_validator(mode="before") @@ -75,11 +75,5 @@ def SQLALCHEMY_DATABASE_URI(self) -> MariaDBDsn: path=self.MARIADB_DB, ) - @computed_field - @property - def SENTRY_RELEASE(self) -> str | None: - if self.APP_ENV == "production": - return f"{self.APP_PACKAGE}@{self.IMAGE_VERSION}" - settings = Settings() diff --git a/api/src/main.py b/api/src/main.py index d548ce6..a922b81 100644 --- a/api/src/main.py +++ b/api/src/main.py @@ -12,7 +12,7 @@ sentry_sdk.init( dsn=settings.SENTRY_DSN, environment=settings.APP_ENV, - release=settings.SENTRY_RELEASE, + release=settings.IMAGE_VERSION, enable_tracing=True, # Set traces_sample_rate to 1.0 to capture 100% # of transactions for tracing. @@ -48,4 +48,4 @@ def hello(): @app.get("/health") def health_check(): - return {"status": "healthy", "version": settings.SENTRY_RELEASE or "dev"} + return {"status": "healthy", "version": settings.IMAGE_VERSION or "dev"} diff --git a/api/tests/test_config.py b/api/tests/test_config.py index 276bf5a..9ad0944 100644 --- a/api/tests/test_config.py +++ b/api/tests/test_config.py @@ -22,7 +22,6 @@ def test_settings_defaults(): str(settings.SQLALCHEMY_DATABASE_URI) == "mysql+pymysql://user:password@localhost:3306/test_db" ) - assert settings.SENTRY_RELEASE is None def test_settings_with_custom_settings(): @@ -30,7 +29,7 @@ def test_settings_with_custom_settings(): APP_NAME="api", APP_PACKAGE="api2", APP_ENV="production", - IMAGE_VERSION="1.0.0", + IMAGE_VERSION="v1.0.0", MARIADB_SERVER="127.0.0.1", MARIADB_PORT=3307, MARIADB_USER="user2", @@ -41,7 +40,7 @@ def test_settings_with_custom_settings(): assert custom.APP_NAME == "api" assert custom.APP_PACKAGE == "api2" assert custom.APP_ENV == "production" - assert custom.IMAGE_VERSION == "1.0.0" + assert custom.IMAGE_VERSION == "v1.0.0" assert custom.MARIADB_SERVER == "127.0.0.1" assert custom.MARIADB_PORT == 3307 assert custom.MARIADB_USER == "user2" @@ -52,16 +51,13 @@ def test_settings_with_custom_settings(): str(custom.SQLALCHEMY_DATABASE_URI) == "mysql+pymysql://user2:password2@127.0.0.1:3307/test_db2" ) - assert custom.SENTRY_RELEASE == "api2@1.0.0" -def test_v_prefixed_image_version(): +def test_image_version_without_v_prefix(): custom = Settings( - APP_ENV="production", - IMAGE_VERSION="v1.0.0", + IMAGE_VERSION="1.0.0", ) - assert custom.IMAGE_VERSION == "1.0.0" - assert custom.SENTRY_RELEASE == "api@1.0.0" + assert custom.IMAGE_VERSION == "v1.0.0" def test_settings_missing_password():