From aef3d41eaf5fe8d10cc2672e6c731dc3cb959a48 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Date: Tue, 31 Oct 2023 22:29:08 -0300 Subject: [PATCH] feat: remove _ prefix for environment variables --- .github/workflows/tests.yml | 4 ++-- README.md | 10 ++++------ docker-compose.yml | 26 +++++++++++++------------- gestao/settings.py | 2 +- pyproject.toml | 4 ++-- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2ad05ca..98b78c7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,5 +46,5 @@ jobs: - name: Run pytest check run: poetry run pytest -vv --cov="gestao" . env: - GESTAO_HOST: "0.0.0.0" - GESTAO_DB_HOST: localhost + HOST: "0.0.0.0" + DB_HOST: localhost diff --git a/README.md b/README.md index 49b1966..493850a 100644 --- a/README.md +++ b/README.md @@ -57,18 +57,16 @@ This application can be configured with environment variables. You can create `.env` file in the root directory and place all environment variables here. -All environment variables should start with "GESTAO_" prefix. - For example if you see in your "gestao/settings.py" a variable named like -`random_parameter`, you should provide the "GESTAO_RANDOM_PARAMETER" +`random_parameter`, you should provide the "RANDOM_PARAMETER" variable to configure the value. This behaviour can be changed by overriding `env_prefix` property in `gestao.settings.Settings.Config`. An example of .env file: ```bash -GESTAO_RELOAD="True" -GESTAO_PORT="8000" -GESTAO_ENVIRONMENT="dev" +RELOAD="True" +PORT="8000" +ENVIRONMENT="dev" ``` You can read more about BaseSettings class here: https://pydantic-docs.helpmanual.io/usage/settings/ diff --git a/docker-compose.yml b/docker-compose.yml index 0502b27..23fe779 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,14 +16,14 @@ services: depends_on: - db environment: - GESTAO_HOST: 0.0.0.0 - GESTAO_PORT: 8001 - GESTAO_DB_HOST: gestao-db - GESTAO_DB_PORT: 5432 - GESTAO_DB_USER: gestao - GESTAO_DB_PASS: gestao - GESTAO_DB_BASE: gestao - GESTAO_RELOAD: "True" + HOST: 0.0.0.0 + PORT: 8001 + DB_HOST: gestao-db + DB_PORT: 5432 + DB_USER: gestao + DB_PASS: gestao + DB_BASE: gestao + RELOAD: "True" networks: - sindpol_network @@ -54,11 +54,11 @@ services: restart: "no" command: alembic upgrade head environment: - GESTAO_DB_HOST: gestao-db - GESTAO_DB_PORT: 5432 - GESTAO_DB_USER: gestao - GESTAO_DB_PASS: gestao - GESTAO_DB_BASE: gestao + DB_HOST: gestao-db + DB_PORT: 5432 + DB_USER: gestao + DB_PASS: gestao + DB_BASE: gestao depends_on: - db networks: diff --git a/gestao/settings.py b/gestao/settings.py index 9bcaf65..78e9966 100644 --- a/gestao/settings.py +++ b/gestao/settings.py @@ -64,7 +64,7 @@ def db_url(self) -> URL: class Config: env_file = ".env" - env_prefix = "GESTAO_" + env_prefix = "" env_file_encoding = "utf-8" diff --git a/pyproject.toml b/pyproject.toml index e9e6ed8..67019ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,8 +51,8 @@ filterwarnings = [ "ignore:.*unclosed.*:ResourceWarning", ] env = [ - "GESTAO_ENVIRONMENT=pytest", - "GESTAO_DB_BASE=gestao_test", + "ENVIRONMENT=pytest", + "DB_BASE=gestao_test", ] [fastapi-template.options]