From 335e5adaee3cb529954fcb499b580b974f218c94 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Sat, 7 Feb 2026 18:05:02 +0100 Subject: [PATCH 1/6] feat: use pydantic-settings to manage environment --- app/core/config.py | 14 +++++++------- pyproject.toml | 1 + uv.lock | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index be7359d..c0d0138 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,7 +1,11 @@ -import os from typing import List -class Settings: +from pydantic_settings import BaseSettings, SettingsConfigDict + + +class Settings(BaseSettings): + model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8') + # API Configuration app_name: str = "Ecologits API" app_version: str = "1.0.0" @@ -16,10 +20,6 @@ class Settings: api_v1_prefix: str = "/v1" docs_url: str = "/docs" redoc_url: str = "/redoc" - - # Environment-based overrides - def __init__(self): - self.app_name = os.getenv("APP_NAME", self.app_name) - self.app_version = os.getenv("APP_VERSION", self.app_version) + settings = Settings() diff --git a/pyproject.toml b/pyproject.toml index 47c39f0..df74e53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires-python = ">=3.10,<4" dependencies = [ "fastapi[standard]>=0.128.4,<1.0.0", "ecologits>=0.9.2,<1.0.0", + "pydantic-settings>=2.12.0", ] [dependency-groups] diff --git a/uv.lock b/uv.lock index 22c532a..6f58f04 100644 --- a/uv.lock +++ b/uv.lock @@ -95,6 +95,7 @@ source = { virtual = "." } dependencies = [ { name = "ecologits" }, { name = "fastapi", extra = ["standard"] }, + { name = "pydantic-settings" }, ] [package.dev-dependencies] @@ -107,6 +108,7 @@ dev = [ requires-dist = [ { name = "ecologits", specifier = ">=0.9.2,<1.0.0" }, { name = "fastapi", extras = ["standard"], specifier = ">=0.128.4,<1.0.0" }, + { name = "pydantic-settings", specifier = ">=2.12.0" }, ] [package.metadata.requires-dev] From b4c8e03c538bdee4e6b5c401ad5c5b148df48b6e Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Sat, 7 Feb 2026 18:31:44 +0100 Subject: [PATCH 2/6] ci: add clever cloud deploy workflow --- .github/workflows/deploy.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0fff74f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,26 @@ +name: Deploy to Clever Cloud + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Deploy to Clever Cloud + uses: CleverCloud/clever-cloud-review-app@v2.0.2 + env: + CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }} + CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }} + APP_NAME: el_api_prod + with: + type: 'python' From 19898a329362f2af88d42c7ff093b9c5d455c47d Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Wed, 11 Feb 2026 18:32:08 +0100 Subject: [PATCH 3/6] ci: use clever cloud cli instead of github action --- .github/workflows/deploy.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0fff74f..b465bee 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,12 +15,20 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v4 - - - name: Deploy to Clever Cloud - uses: CleverCloud/clever-cloud-review-app@v2.0.2 - env: - CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }} - CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }} - APP_NAME: el_api_prod with: - type: 'python' + fetch-depth: 0 + + - name: Install Clever Tools CLI + run: | + CC_VERSION=latest + curl -s -O https://clever-tools.clever-cloud.com/releases/${CC_VERSION}/clever-tools-${CC_VERSION}_linux.tar.gz + tar -xvf clever-tools-${CC_VERSION}_linux.tar.gz + PATH=${PATH}:$(pwd)/clever-tools-${CC_VERSION}_linux + + - name: Login to Clever Cloud + run: ./clever-tools-latest_linux/clever login --token ${{ secrets.CLEVER_TOKEN }} --secret ${{ secrets.CLEVER_SECRET }} + + - name: Deploy API to Clever Cloud + run: | + ./clever-tools-latest_linux/clever link $CLEVER_APP_ID + ./clever-tools-latest_linux/clever deploy -f From 90d3af650ca617b4c12b8b3e3ac17eb37feca902 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Wed, 11 Feb 2026 18:35:23 +0100 Subject: [PATCH 4/6] ci: add clever app id as a secret --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b465bee..132c8fb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -30,5 +30,5 @@ jobs: - name: Deploy API to Clever Cloud run: | - ./clever-tools-latest_linux/clever link $CLEVER_APP_ID + ./clever-tools-latest_linux/clever link ${{ secrets.CLEVER_APP_ID }} ./clever-tools-latest_linux/clever deploy -f From e693cfd1032e19d16d8f72428a2a35f3e62327ce Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Wed, 11 Feb 2026 20:41:13 +0100 Subject: [PATCH 5/6] ci: deploy to prod only on main branch --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 132c8fb..cb6582b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,6 @@ name: Deploy to Clever Cloud on: - pull_request: push: branches: - main From 817843171ec5e9bea8f9f0bf463246885d33b184 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Wed, 11 Feb 2026 20:43:56 +0100 Subject: [PATCH 6/6] ci: gate deployment on test success --- .github/workflows/deploy.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cb6582b..a592a03 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,10 @@ name: Deploy to Clever Cloud on: - push: + workflow_run: + workflows: ["pytest"] + types: + - completed branches: - main @@ -11,6 +14,7 @@ permissions: jobs: deploy: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Check out repository uses: actions/checkout@v4