diff --git a/cms/envs/bok_choy.py b/cms/envs/bok_choy.py index 9e7a11e58e..30be2bb448 100644 --- a/cms/envs/bok_choy.py +++ b/cms/envs/bok_choy.py @@ -33,6 +33,7 @@ os.environ['CONFIG_ROOT'] = path(__file__).abspath().dirname() os.environ['STUDIO_CFG'] = str.format("{config_root}/{service_variant}.yml", config_root=os.environ['CONFIG_ROOT'], service_variant=os.environ['SERVICE_VARIANT']) +os.environ['REVISION_CFG'] = "{config_root}/revisions.yml".format(config_root=os.environ['CONFIG_ROOT']) from .production import * # pylint: disable=wildcard-import, unused-wildcard-import, wrong-import-position diff --git a/cms/envs/production.py b/cms/envs/production.py index afa19de423..dd7c51c2f8 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -45,6 +45,18 @@ with codecs.open(CONFIG_FILE, encoding='utf-8') as f: AUTH_TOKENS = __config__ +# A file path to a YAML file from which to load all the code revisions currently deployed +REVISION_CONFIG_FILE = get_env_setting('REVISION_CFG') + +try: + with codecs.open(REVISION_CONFIG_FILE, encoding='utf-8') as f: + REVISION_CONFIG = yaml.safe_load(f) +except Exception: # pylint: disable=broad-except + REVISION_CONFIG = {} + +# Do NOT calculate this dynamically at startup with git because it's *slow*. +EDX_PLATFORM_REVISION = REVISION_CONFIG.get('EDX_PLATFORM_REVISION', EDX_PLATFORM_REVISION) + # SERVICE_VARIANT specifies name of the variant used, which decides what JSON # configuration files are read during startup. SERVICE_VARIANT = os.environ.get('SERVICE_VARIANT', None) @@ -110,9 +122,6 @@ CELERY_QUEUES = { CELERY_ROUTES = "{}celery.Router".format(QUEUE_VARIANT) -# Do NOT calculate this dynamically at startup with git because it's *slow*. -EDX_PLATFORM_REVISION = ENV_TOKENS.get('EDX_PLATFORM_REVISION', EDX_PLATFORM_REVISION) - # STATIC_URL_BASE specifies the base url to use for static files STATIC_URL_BASE = ENV_TOKENS.get('STATIC_URL_BASE', None) if STATIC_URL_BASE: @@ -197,6 +206,9 @@ if 'loc_cache' not in CACHES: 'LOCATION': 'edx_location_mem_cache', } +if 'staticfiles' in CACHES: + CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION + SESSION_COOKIE_DOMAIN = ENV_TOKENS.get('SESSION_COOKIE_DOMAIN') SESSION_COOKIE_HTTPONLY = ENV_TOKENS.get('SESSION_COOKIE_HTTPONLY', True) SESSION_ENGINE = ENV_TOKENS.get('SESSION_ENGINE', SESSION_ENGINE) diff --git a/lms/envs/bok_choy.py b/lms/envs/bok_choy.py index cf7bd8a7c1..6e2adf72d0 100644 --- a/lms/envs/bok_choy.py +++ b/lms/envs/bok_choy.py @@ -36,6 +36,7 @@ os.environ['SERVICE_VARIANT'] = 'bok_choy_docker' if 'BOK_CHOY_HOSTNAME' in os.e os.environ['CONFIG_ROOT'] = CONFIG_ROOT os.environ['LMS_CFG'] = str.format("{config_root}/{service_variant}.yml", config_root=os.environ['CONFIG_ROOT'], service_variant=os.environ['SERVICE_VARIANT']) +os.environ['REVISION_CFG'] = "{config_root}/revisions.yml".format(config_root=os.environ['CONFIG_ROOT']) from .production import * # pylint: disable=wildcard-import, unused-wildcard-import, wrong-import-position diff --git a/lms/envs/production.py b/lms/envs/production.py index efb8efeb1e..4e0198c896 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -56,6 +56,18 @@ with codecs.open(CONFIG_FILE, encoding='utf-8') as f: ENV_TOKENS = __config__ AUTH_TOKENS = __config__ +# A file path to a YAML file from which to load all the code revisions currently deployed +REVISION_CONFIG_FILE = get_env_setting('REVISION_CFG') + +try: + with codecs.open(REVISION_CONFIG_FILE, encoding='utf-8') as f: + REVISION_CONFIG = yaml.safe_load(f) +except Exception: # pylint: disable=broad-except + REVISION_CONFIG = {} + +# Do NOT calculate this dynamically at startup with git because it's *slow*. +EDX_PLATFORM_REVISION = REVISION_CONFIG.get('EDX_PLATFORM_REVISION', EDX_PLATFORM_REVISION) + # SERVICE_VARIANT specifies name of the variant used, which decides what JSON # configuration files are read during startup. SERVICE_VARIANT = os.environ.get('SERVICE_VARIANT', None) @@ -230,6 +242,9 @@ if 'loc_cache' not in CACHES: 'LOCATION': 'edx_location_mem_cache', } +if 'staticfiles' in CACHES: + CACHES['staticfiles']['KEY_PREFIX'] = EDX_PLATFORM_REVISION + # Email overrides DEFAULT_FROM_EMAIL = ENV_TOKENS.get('DEFAULT_FROM_EMAIL', DEFAULT_FROM_EMAIL) DEFAULT_FEEDBACK_EMAIL = ENV_TOKENS.get('DEFAULT_FEEDBACK_EMAIL', DEFAULT_FEEDBACK_EMAIL) @@ -1057,9 +1072,6 @@ PARENTAL_CONSENT_AGE_LIMIT = ENV_TOKENS.get( PARENTAL_CONSENT_AGE_LIMIT ) -# Do NOT calculate this dynamically at startup with git because it's *slow*. -EDX_PLATFORM_REVISION = ENV_TOKENS.get('EDX_PLATFORM_REVISION', EDX_PLATFORM_REVISION) - ########################## Extra middleware classes ####################### # Allow extra middleware classes to be added to the app through configuration. diff --git a/tox.ini b/tox.ini index 5be73e5f57..9b0752d9b9 100644 --- a/tox.ini +++ b/tox.ini @@ -37,6 +37,7 @@ passenv = EDX_PLATFORM_SETTINGS JOB_NAME LMS_CFG + REVISION_CFG MOZ_HEADLESS NODE_PATH NODE_VIRTUAL_ENV