Loading environment files


When we run tutor config save, tutor generates the file:

  • env/apps/openedx/config/cms.env.json
  • env/apps/openedx/config/lms.env.json

These files are binded to the respective container directories:

  • openedx/edx-platform/cms/envs/tutor
  • openedx/edx-platform/lms/envs/tutor

My question is, how these settings are loaded in the django settings?
In the source code, we can read the values, like:

from django.conf import settings

I want to know how these files are loaded? If possible in which file and function.

I believe you are asking for the templates that create the JSON environment files.

You can take a look at the tutor repository at this location for those templates: tutor/tutor/templates/apps/openedx/config at master · overhangio/tutor · GitHub

If you are looking for how edx-platform uses those variables, you will have to search for the variable inside the edx-platform repo here: GitHub - openedx/edx-platform: The Open edX LMS & Studio, powering education sites around the world!
Here is an example with the first variable SITE_NAME: Search · SITE_NAME · GitHub

Thank you @uetuluk for the answer!

But what I want to know is how edx-platform reads the *.env.json files end load the values in Django settings.
I was not able to find in edx-platform source a function that reads these files.

I don’t know exactly how they are converted in Tutor’s source code, but I am under the impression they end up in the production.py files under $TUTOR_ROOT/env/apps/openedx/settings/lms/production.py and $TUTOR_ROOT/env/apps/openedx/settings/cms/production.py

Is that what you were looking for?

I found how it works.

The cms/envs/tutor/production.py imports cms/envs/production.py who imports cms/envs/common.py.

In cms/envs/production.py we have this part of the code that reads the config env file:

# A file path to a YAML file from which to load all the configuration for the edx platform
CONFIG_FILE = get_env_setting('STUDIO_CFG')

with codecs.open(CONFIG_FILE, encoding='utf-8') as f:
    __config__ = yaml.safe_load(f)

    # ENV_TOKENS and AUTH_TOKENS are included for reverse compatability.
    # Removing them may break plugins that rely on them.
    ENV_TOKENS = __config__
    AUTH_TOKENS = __config__