From 7257647b9be93dbb6bb138269cef8172cc008579 Mon Sep 17 00:00:00 2001 From: Danyal-Faheem Date: Mon, 23 Jun 2025 15:22:00 +0500 Subject: [PATCH] Revert "depr!: remove preview site configurations (#1238)" This reverts commit c780e0a6e54c6c87f612c4aa71c551ea81412a1b. We revert this commit as the upstream change was merged in the master branch and is not to be backported to teak. Therefore, the current builds running on top of teak are failing. --- docs/configuration.rst | 1 + docs/tutorials/proxy.rst | 2 +- tutor/commands/jobs_utils.py | 2 ++ tutor/config.py | 16 ++++++++++++++++ tutor/templates/apps/caddy/Caddyfile | 2 +- tutor/templates/apps/openedx/config/cms.env.yml | 1 + tutor/templates/apps/openedx/config/lms.env.yml | 1 + .../apps/openedx/settings/cms/development.py | 2 ++ .../apps/openedx/settings/lms/production.py | 1 + tutor/templates/config/defaults.yml | 1 + 10 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 5810dffd83..b61b3df926 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -292,6 +292,7 @@ When ``ENABLE_HTTPS`` is ``true``, the whole Open edX platform will be reconfigu The following DNS records must exist and point to your server:: LMS_HOST (e.g: myopenedx.com) + PREVIEW_LMS_HOST (e.g: preview.myopenedx.com) CMS_HOST (e.g: studio.myopenedx.com) Thus, **this feature will (probably) not work in development** because the DNS records will (probably) not point to your development machine. diff --git a/docs/tutorials/proxy.rst b/docs/tutorials/proxy.rst index a4581299b5..94e961f0f7 100644 --- a/docs/tutorials/proxy.rst +++ b/docs/tutorials/proxy.rst @@ -20,7 +20,7 @@ With these changes, Tutor will no longer listen to ports 80 and 443 on the host. It is then your responsibility to configure the web proxy on the host. There are too many use cases and proxy vendors, so Tutor does not provide configuration files that will work for everyone. You should configure your web proxy to: -- Capture traffic for the following hostnames: LMS_HOST, CMS_HOST, as well as any additional host exposed by your plugins (MFE_HOST, CREDENTIALS_HOST, etc.). See each plugin documentation for more information. +- Capture traffic for the following hostnames: LMS_HOST, PREVIEW_LMS_HOST, CMS_HOST, as well as any additional host exposed by your plugins (MFE_HOST, CREDENTIALS_HOST, etc.). See each plugin documentation for more information. - If SSL/TLS is enabled: - Perform SSL/TLS termination using your own certificates. - Forward http traffic to https. diff --git a/tutor/commands/jobs_utils.py b/tutor/commands/jobs_utils.py index c385912ddc..efbd0b2b68 100644 --- a/tutor/commands/jobs_utils.py +++ b/tutor/commands/jobs_utils.py @@ -177,6 +177,8 @@ def assign_theme(name, domain): "{{ LMS_HOST }}:8000", "{{ CMS_HOST }}", "{{ CMS_HOST }}:8001", + "{{ PREVIEW_LMS_HOST }}", + "{{ PREVIEW_LMS_HOST }}:8000", ] for domain_name in domain_names: python_command += f"assign_theme('{theme_name}', '{domain_name}')\n" diff --git a/tutor/config.py b/tutor/config.py index af88ad719b..03a7f85f97 100644 --- a/tutor/config.py +++ b/tutor/config.py @@ -342,3 +342,19 @@ def _update_enabled_plugins_on_unload(_plugin: str, _root: str, config: Config) Note that this action must be performed after the plugin has been unloaded, hence the low priority. """ save_enabled_plugins(config) + + +@hooks.Actions.CONFIG_LOADED.add() +def _check_preview_lms_host(config: Config) -> None: + """ + This will check if the PREVIEW_LMS_HOST is a subdomain of LMS_HOST. + if not, prints a warning to notify the user. + """ + + lms_host = get_typed(config, "LMS_HOST", str, "") + preview_lms_host = get_typed(config, "PREVIEW_LMS_HOST", str, "") + if not preview_lms_host.endswith("." + lms_host): + fmt.echo_alert( + f'Warning: PREVIEW_LMS_HOST="{preview_lms_host}" is not a subdomain of LMS_HOST="{lms_host}". ' + "This configuration is not typically recommended and may lead to unexpected behavior." + ) diff --git a/tutor/templates/apps/caddy/Caddyfile b/tutor/templates/apps/caddy/Caddyfile index ad94a97f48..77eb152ec4 100644 --- a/tutor/templates/apps/caddy/Caddyfile +++ b/tutor/templates/apps/caddy/Caddyfile @@ -41,7 +41,7 @@ {{ patch("caddyfile-proxy")|indent(4) }} } -{{ LMS_HOST }}{$default_site_port} { +{{ LMS_HOST }}{$default_site_port}, {{ PREVIEW_LMS_HOST }}{$default_site_port} { @favicon_matcher { path_regexp ^/favicon.ico$ } diff --git a/tutor/templates/apps/openedx/config/cms.env.yml b/tutor/templates/apps/openedx/config/cms.env.yml index 17ba857d54..8eb7b462d8 100644 --- a/tutor/templates/apps/openedx/config/cms.env.yml +++ b/tutor/templates/apps/openedx/config/cms.env.yml @@ -8,6 +8,7 @@ FEATURES: {{ patch("common-env-features")|indent(2) }} {{ patch("cms-env-features")|indent(2) }} CERTIFICATES_HTML_VIEW: true + PREVIEW_LMS_BASE: "{{ PREVIEW_LMS_HOST }}" ENABLE_CSMH_EXTENDED: false ENABLE_LEARNER_RECORDS: false ENABLE_LIBRARY_INDEX: true diff --git a/tutor/templates/apps/openedx/config/lms.env.yml b/tutor/templates/apps/openedx/config/lms.env.yml index 44fe04d7b9..bc9927f23c 100644 --- a/tutor/templates/apps/openedx/config/lms.env.yml +++ b/tutor/templates/apps/openedx/config/lms.env.yml @@ -8,6 +8,7 @@ FEATURES: {{ patch("common-env-features")|indent(2) }} {{ patch("lms-env-features")|indent(2) }} CERTIFICATES_HTML_VIEW: true + PREVIEW_LMS_BASE: "{{ PREVIEW_LMS_HOST }}" ENABLE_CSMH_EXTENDED: false ENABLE_COMBINED_LOGIN_REGISTRATION: true ENABLE_GRADE_DOWNLOADS: true diff --git a/tutor/templates/apps/openedx/settings/cms/development.py b/tutor/templates/apps/openedx/settings/cms/development.py index ef413a9a21..ee4c3b3b5b 100644 --- a/tutor/templates/apps/openedx/settings/cms/development.py +++ b/tutor/templates/apps/openedx/settings/cms/development.py @@ -16,6 +16,8 @@ SOCIAL_AUTH_EDX_OAUTH2_KEY = "{{ CMS_OAUTH2_KEY_SSO_DEV }}" SOCIAL_AUTH_EDX_OAUTH2_PUBLIC_URL_ROOT = LMS_ROOT_URL +FEATURES["PREVIEW_LMS_BASE"] = "{{ PREVIEW_LMS_HOST }}:8000" + # Setup correct webpack configuration file for development WEBPACK_CONFIG_PATH = "webpack.dev.config.js" diff --git a/tutor/templates/apps/openedx/settings/lms/production.py b/tutor/templates/apps/openedx/settings/lms/production.py index c9e62fe094..6c2793b3bc 100644 --- a/tutor/templates/apps/openedx/settings/lms/production.py +++ b/tutor/templates/apps/openedx/settings/lms/production.py @@ -6,6 +6,7 @@ ALLOWED_HOSTS = [ ENV_TOKENS.get("LMS_BASE"), + FEATURES["PREVIEW_LMS_BASE"], "lms", ] CORS_ORIGIN_WHITELIST.append("{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}") diff --git a/tutor/templates/config/defaults.yml b/tutor/templates/config/defaults.yml index 32e4bbc222..bb916b9e5b 100644 --- a/tutor/templates/config/defaults.yml +++ b/tutor/templates/config/defaults.yml @@ -68,6 +68,7 @@ MYSQL_PORT: 3306 MYSQL_ROOT_USERNAME: "root" NPM_REGISTRY: "https://registry.npmjs.org/" PLATFORM_NAME: "My Open edX" +PREVIEW_LMS_HOST: "preview.{{ LMS_HOST }}" REDIS_HOST: "redis" REDIS_PORT: 6379 REDIS_USERNAME: ""