mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 12:29:42 +00:00
♻️ Simplify optional environment configuration (#2417)
## AI Disclaimer Using Codex with gpt-5.6-sol. Reviewed manually.
This commit is contained in:
committed by
GitHub
parent
bda0325818
commit
dd15054da0
@@ -10,17 +10,12 @@ ENVIRONMENT=local
|
||||
|
||||
PROJECT_NAME="Full Stack FastAPI Project"
|
||||
|
||||
# Backend
|
||||
# Additional allowed CORS origins, separated by commas
|
||||
BACKEND_CORS_ORIGINS=
|
||||
SECRET_KEY=changethis
|
||||
FIRST_SUPERUSER=admin@example.com
|
||||
FIRST_SUPERUSER_PASSWORD=changethis
|
||||
|
||||
# Emails
|
||||
SMTP_HOST=localhost
|
||||
SMTP_USER=
|
||||
SMTP_PASSWORD=
|
||||
EMAILS_FROM_EMAIL=info@example.com
|
||||
SMTP_TLS=False
|
||||
SMTP_PORT=1025
|
||||
@@ -30,5 +25,3 @@ POSTGRES_SERVER=localhost
|
||||
POSTGRES_DB=app
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=changethis
|
||||
|
||||
SENTRY_DSN=
|
||||
|
||||
@@ -17,7 +17,6 @@ jobs:
|
||||
- self-hosted
|
||||
- production
|
||||
env:
|
||||
ENVIRONMENT: production
|
||||
DOMAIN: ${{ secrets.DOMAIN }}
|
||||
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
||||
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
||||
|
||||
@@ -17,7 +17,6 @@ jobs:
|
||||
- self-hosted
|
||||
- staging
|
||||
env:
|
||||
ENVIRONMENT: staging
|
||||
DOMAIN: ${{ secrets.DOMAIN }}
|
||||
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
||||
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Settings(BaseSettings):
|
||||
# 60 minutes * 24 hours * 8 days = 8 days
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
||||
FRONTEND_HOST: str = "http://localhost:5173"
|
||||
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
|
||||
ENVIRONMENT: Literal["local"] | None = None
|
||||
|
||||
BACKEND_CORS_ORIGINS: Annotated[
|
||||
list[AnyUrl] | str, BeforeValidator(parse_cors)
|
||||
|
||||
@@ -68,10 +68,15 @@ services:
|
||||
volumes:
|
||||
- ./backend/htmlcov:/app/backend/htmlcov
|
||||
environment:
|
||||
ENVIRONMENT: "local"
|
||||
SMTP_HOST: "mailcatcher"
|
||||
SMTP_PORT: "1025"
|
||||
SMTP_TLS: "false"
|
||||
|
||||
prestart:
|
||||
environment:
|
||||
ENVIRONMENT: "local"
|
||||
|
||||
mailcatcher:
|
||||
image: schickling/mailcatcher
|
||||
ports:
|
||||
|
||||
+4
-5
@@ -57,21 +57,20 @@ services:
|
||||
condition: service_completed_successfully
|
||||
# The YAML anchor lets the prestart service reuse this environment mapping.
|
||||
environment: &backend-environment
|
||||
ENVIRONMENT: ${ENVIRONMENT}
|
||||
PROJECT_NAME: ${PROJECT_NAME?Variable not set}
|
||||
BACKEND_CORS_ORIGINS: ${BACKEND_CORS_ORIGINS}
|
||||
BACKEND_CORS_ORIGINS: ${BACKEND_CORS_ORIGINS:-}
|
||||
SECRET_KEY: ${SECRET_KEY?Variable not set}
|
||||
FIRST_SUPERUSER: ${FIRST_SUPERUSER?Variable not set}
|
||||
FIRST_SUPERUSER_PASSWORD: ${FIRST_SUPERUSER_PASSWORD?Variable not set}
|
||||
SMTP_HOST: ${SMTP_HOST}
|
||||
SMTP_USER: ${SMTP_USER}
|
||||
SMTP_PASSWORD: ${SMTP_PASSWORD}
|
||||
SMTP_USER: ${SMTP_USER:-}
|
||||
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
|
||||
EMAILS_FROM_EMAIL: ${EMAILS_FROM_EMAIL}
|
||||
POSTGRES_SERVER: db
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER?Variable not set}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD?Variable not set}
|
||||
SENTRY_DSN: ${SENTRY_DSN}
|
||||
SENTRY_DSN: ${SENTRY_DSN:-}
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"]
|
||||
|
||||
@@ -46,12 +46,6 @@ Copy the content and use that as password / secret key. And run that again to ge
|
||||
|
||||
### Required Environment Variables
|
||||
|
||||
Set the `ENVIRONMENT`, by default `local` (for development), but when deploying to a server you would put something like `staging` or `production`:
|
||||
|
||||
```bash
|
||||
export ENVIRONMENT=production
|
||||
```
|
||||
|
||||
Set the `DOMAIN`, by default `localhost` (for development), but when deploying you would use your own domain, for example:
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user