activist icon indicating copy to clipboard operation
activist copied to clipboard

Check and load in env variables for backend/db only builds

Open andrewtavis opened this issue 11 months ago • 5 comments

Terms

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 avatar Mar 07 '24 13:03 andrewtavis

@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 avatar Mar 07 '24 18:03 to-sta

@to-sta @andrewtavis can i work on this issue?

bharath637462 avatar Mar 17 '24 13:03 bharath637462

Sure, @bharath637462. Please name the env. variable DJANGO_ENV.

to-sta avatar Mar 17 '24 15:03 to-sta

@to-sta @andrewtavis i have changed .env.dev to .env now docker compose working. can i give a pull request?

bharath637462 avatar Mar 18 '24 17:03 bharath637462

Ping @anthonyshibitov for an issue that you could pick up :)

andrewtavis avatar Jul 27 '24 15:07 andrewtavis