activist
activist copied to clipboard
Check and load in env variables for backend/db only builds
Terms
- [X] I have searched open and closed feature requests
- [X] I agree to follow activist's Code of Conduct
Description
An issue that a contributor faced recently was that for builds that are not the full Docker build, but rather only the backend and database separately, that the environment variables within .env.dev were not loaded in. Ideally we would check what the build situation is, and then in settings.py for the backend we would pass an argument to dotenv.load_dotenv()
to load them in. Specifically, the line should be changed to:
dotenv.load_dotenv(override=True, dotenv_path=Path(__file__).resolve().parent.parent.parent / ".env.dev")
This again should be triggered via an if clause that determines the Docker state and whether it would be necessary :)
Contribution
Happy to look into this or support as needed!
@andrewtavis I think best practice in the django world is to split the settings file into:
- base.py (shared settings amongs all enviroments)
- local.py (this would include the line above)
- development.py (development specific settings)
- production.py
Then include the line above inside the local.py settings file. Determine the appropriate settings file based on an environment variable (e.g., mode="Production"). If the mode is neither set to Production
nor Development
, default to the Local
settings.
@to-sta @andrewtavis can i work on this issue?
Sure, @bharath637462. Please name the env. variable DJANGO_ENV
.
@to-sta @andrewtavis i have changed .env.dev to .env now docker compose working. can i give a pull request?
Ping @anthonyshibitov for an issue that you could pick up :)