Skip to content

Commit

Permalink
feat: remove _ prefix for environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheusafonsouza committed Nov 1, 2023
1 parent 5581a77 commit aef3d41
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
26 changes: 13 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion gestao/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def db_url(self) -> URL:

class Config:
env_file = ".env"
env_prefix = "GESTAO_"
env_prefix = ""
env_file_encoding = "utf-8"


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit aef3d41

Please sign in to comment.