Skip to content

Commit dd15054

Browse files
authored
♻️ Simplify optional environment configuration (#2417)
## AI Disclaimer Using Codex with gpt-5.6-sol. Reviewed manually.
1 parent bda0325 commit dd15054

7 files changed

Lines changed: 10 additions & 21 deletions

File tree

‎.env‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ ENVIRONMENT=local
1010

1111
PROJECT_NAME="Full Stack FastAPI Project"
1212

13-
# Backend
14-
# Additional allowed CORS origins, separated by commas
15-
BACKEND_CORS_ORIGINS=
1613
SECRET_KEY=changethis
1714
FIRST_SUPERUSER=admin@example.com
1815
FIRST_SUPERUSER_PASSWORD=changethis
1916

2017
# Emails
2118
SMTP_HOST=localhost
22-
SMTP_USER=
23-
SMTP_PASSWORD=
2419
EMAILS_FROM_EMAIL=info@example.com
2520
SMTP_TLS=False
2621
SMTP_PORT=1025
@@ -30,5 +25,3 @@ POSTGRES_SERVER=localhost
3025
POSTGRES_DB=app
3126
POSTGRES_USER=postgres
3227
POSTGRES_PASSWORD=changethis
33-
34-
SENTRY_DSN=

‎.github/workflows/deploy-production.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
- self-hosted
1818
- production
1919
env:
20-
ENVIRONMENT: production
2120
DOMAIN: ${{ secrets.DOMAIN }}
2221
SECRET_KEY: ${{ secrets.SECRET_KEY }}
2322
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}

‎.github/workflows/deploy-staging.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
- self-hosted
1818
- staging
1919
env:
20-
ENVIRONMENT: staging
2120
DOMAIN: ${{ secrets.DOMAIN }}
2221
SECRET_KEY: ${{ secrets.SECRET_KEY }}
2322
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}

‎backend/app/core/config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Settings(BaseSettings):
3434
# 60 minutes * 24 hours * 8 days = 8 days
3535
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
3636
FRONTEND_HOST: str = "http://localhost:5173"
37-
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
37+
ENVIRONMENT: Literal["local"] | None = None
3838

3939
BACKEND_CORS_ORIGINS: Annotated[
4040
list[AnyUrl] | str, BeforeValidator(parse_cors)

‎compose.override.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ services:
6868
volumes:
6969
- ./backend/htmlcov:/app/backend/htmlcov
7070
environment:
71+
ENVIRONMENT: "local"
7172
SMTP_HOST: "mailcatcher"
7273
SMTP_PORT: "1025"
7374
SMTP_TLS: "false"
7475

76+
prestart:
77+
environment:
78+
ENVIRONMENT: "local"
79+
7580
mailcatcher:
7681
image: schickling/mailcatcher
7782
ports:

‎compose.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,20 @@ services:
5757
condition: service_completed_successfully
5858
# The YAML anchor lets the prestart service reuse this environment mapping.
5959
environment: &backend-environment
60-
ENVIRONMENT: ${ENVIRONMENT}
6160
PROJECT_NAME: ${PROJECT_NAME?Variable not set}
62-
BACKEND_CORS_ORIGINS: ${BACKEND_CORS_ORIGINS}
61+
BACKEND_CORS_ORIGINS: ${BACKEND_CORS_ORIGINS:-}
6362
SECRET_KEY: ${SECRET_KEY?Variable not set}
6463
FIRST_SUPERUSER: ${FIRST_SUPERUSER?Variable not set}
6564
FIRST_SUPERUSER_PASSWORD: ${FIRST_SUPERUSER_PASSWORD?Variable not set}
6665
SMTP_HOST: ${SMTP_HOST}
67-
SMTP_USER: ${SMTP_USER}
68-
SMTP_PASSWORD: ${SMTP_PASSWORD}
66+
SMTP_USER: ${SMTP_USER:-}
67+
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
6968
EMAILS_FROM_EMAIL: ${EMAILS_FROM_EMAIL}
7069
POSTGRES_SERVER: db
7170
POSTGRES_DB: ${POSTGRES_DB}
7271
POSTGRES_USER: ${POSTGRES_USER?Variable not set}
7372
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD?Variable not set}
74-
SENTRY_DSN: ${SENTRY_DSN}
73+
SENTRY_DSN: ${SENTRY_DSN:-}
7574

7675
healthcheck:
7776
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"]

‎deployment.md‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Copy the content and use that as password / secret key. And run that again to ge
4646

4747
### Required Environment Variables
4848

49-
Set the `ENVIRONMENT`, by default `local` (for development), but when deploying to a server you would put something like `staging` or `production`:
50-
51-
```bash
52-
export ENVIRONMENT=production
53-
```
54-
5549
Set the `DOMAIN`, by default `localhost` (for development), but when deploying you would use your own domain, for example:
5650

5751
```bash

0 commit comments

Comments
 (0)