From ac9f005947fe4d34105c966f9e81023e88db080a Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Mon, 4 Aug 2025 11:04:39 +0000 Subject: [PATCH 1/2] fix: Dynamic port for LEARNING MFE in form of ENV variable fixing the dynamic port for leaning mfe as for overiding the 2000 port to 2010 for all the mfe repos --- .devcontainer/devcontainer.json | 7 +++--- .devcontainer/updateContentCommand.sh | 24 ++++++++++++++++++++ docker-compose.yml | 2 +- py_configuration_files/course_discovery.py | 3 ++- py_configuration_files/ecommerce.py | 3 ++- py_configuration_files/enterprise_subsidy.py | 6 ++++- py_configuration_files/lms.py | 10 +++++--- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 46ae76b1..86762e8e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -30,13 +30,14 @@ } }, "containerEnv": { - "DEVSTACK_WORKSPACE": "/workspaces/edx-repos" + "DEVSTACK_WORKSPACE": "/workspaces/edx-repos", + "LEARNING_MICROFRONTEND_PORT": "2010" }, "updateContentCommand": ".devcontainer/updateContentCommand.sh", "postCreateCommand": ".devcontainer/postCreateCommand.sh", "postStartCommand": ".devcontainer/postStartCommand.sh", "forwardPorts": [ - 1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, + 1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2010, 2001, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202, 9301, 9600, 18000, 18010, 18040, 18110, 18120, 18130, 18150, 18160, 18170, 18270, 18280, 18381, 18400, 18450, 18734, 18760, 18787, 19001, @@ -60,7 +61,7 @@ "18130": { "label": "ecommerce" }, "18150": { "label": "credentials" }, "18120": { "label": "edx_notes_api" }, - "2000": { "label": "frontend-app-learning" }, + "2010": { "label": "frontend-app-learning" }, "1998": { "label": "frontend-app-payment" }, "18400": { "label": "frontend-app-publisher" }, "1994": { "label": "frontend-app-gradebook" }, diff --git a/.devcontainer/updateContentCommand.sh b/.devcontainer/updateContentCommand.sh index 1f05e30d..5c30f230 100755 --- a/.devcontainer/updateContentCommand.sh +++ b/.devcontainer/updateContentCommand.sh @@ -79,3 +79,27 @@ for repo_dir in ${repo_dirs[@]}; do popd done + + +echo "Updating .env.development files for MFE apps..." + +# Define shared values +PORT=${LEARNING_MICROFRONTEND_PORT:-2010} +BASE_URL="http://localhost:$PORT" + +# Loop through frontend-app-* repos +find "$DEVSTACK_WORKSPACE" -type d -name "frontend-app-*" | while read -r repo; do + ENV_FILE="$repo/.env.development" + + + if [ -f "$ENV_FILE" ]; then + echo "Updating $ENV_FILE..." + if [[ "$repo" == *"frontend-app-learning" ]]; then + sed -i.bak -E "s|^PORT=.*|PORT=$PORT|" "$ENV_FILE" + sed -i.bak -E "s|^BASE_URL=.*|BASE_URL='$BASE_URL'|" "$ENV_FILE" + else + sed -i.bak -E "s|^LEARNING_BASE_URL=.*|LEARNING_BASE_URL='$BASE_URL'|" "$ENV_FILE" + fi + rm -f "$ENV_FILE.bak" + fi +done diff --git a/docker-compose.yml b/docker-compose.yml index 664ca50f..87c5e836 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1126,7 +1126,7 @@ services: aliases: - edx.devstack.frontend-app-learning ports: - - "2000:2000" + - "${LEARNING_MICROFRONTEND_PORT:-2010}:${LEARNING_MICROFRONTEND_PORT:-2010}" depends_on: - lms diff --git a/py_configuration_files/course_discovery.py b/py_configuration_files/course_discovery.py index 9fa60390..2387fe84 100644 --- a/py_configuration_files/course_discovery.py +++ b/py_configuration_files/course_discovery.py @@ -1,4 +1,5 @@ # noinspection PyUnresolvedReferences +import os from course_discovery.settings._debug_toolbar import * # isort:skip from course_discovery.settings.production import * @@ -18,7 +19,7 @@ 'http://localhost:1991', # frontend-app-admin-portal 'http://localhost:18400', # frontend-app-publisher 'http://localhost:18450', # frontend-app-support-tools - 'http://localhost:2000', # frontend-app-learning + 'http://localhost:' + os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010'), # frontend-app-learning ) ELASTICSEARCH_DSL['default']['hosts'] = 'edx.devstack.elasticsearch710:9200' diff --git a/py_configuration_files/ecommerce.py b/py_configuration_files/ecommerce.py index 5ce82962..d2331a49 100644 --- a/py_configuration_files/ecommerce.py +++ b/py_configuration_files/ecommerce.py @@ -1,6 +1,7 @@ """Devstack settings""" +import os from corsheaders.defaults import default_headers as corsheaders_default_headers from ecommerce.settings.production import * @@ -55,8 +56,8 @@ 'http://localhost:1996', 'http://localhost:1997', # Account MFE 'http://localhost:1998', - 'http://localhost:2000', # Learning MFE 'http://localhost:8734', # Enterprise Learner Portal MFE + 'http://localhost:' + os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010'), # Learning MFE ) CORS_ALLOW_HEADERS = corsheaders_default_headers + ( 'use-jwt-cookie', diff --git a/py_configuration_files/enterprise_subsidy.py b/py_configuration_files/enterprise_subsidy.py index f168d085..6ee543e2 100644 --- a/py_configuration_files/enterprise_subsidy.py +++ b/py_configuration_files/enterprise_subsidy.py @@ -1,3 +1,4 @@ +import os from enterprise_subsidy.settings.local import * CORS_ORIGIN_WHITELIST = ( @@ -54,6 +55,9 @@ 'BACKEND_SERVICE_EDX_OAUTH2_SECRET', 'enterprise-subsidy-backend-service-secret' ) +# This port is configured centrally in devcontainer.json +LEARNING_MICROFRONTEND_PORT = os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010') + JWT_AUTH.update({ 'JWT_SECRET_KEY': 'lms-secret', 'JWT_ISSUER': 'http://localhost:18000/oauth2', @@ -75,7 +79,7 @@ LMS_URL = 'http://edx.devstack.lms:18000' ENTERPRISE_CATALOG_URL = 'http://edx.devstack.enterprise-catalog:18160' ENTERPRISE_SUBSIDY_URL = 'http://localhost:18280' -FRONTEND_APP_LEARNING_URL = 'http://localhost:2000' +FRONTEND_APP_LEARNING_URL = 'http://localhost:' + LEARNING_MICROFRONTEND_PORT # Kafka Settings # "Standard" Kafka settings as defined in https://github.com/openedx/event-bus-kafka/tree/main diff --git a/py_configuration_files/lms.py b/py_configuration_files/lms.py index 23054cb2..68c43836 100644 --- a/py_configuration_files/lms.py +++ b/py_configuration_files/lms.py @@ -269,6 +269,10 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing ENTERPRISE_LEARNER_PORTAL_NETLOC = 'localhost:8734' ENTERPRISE_LEARNER_PORTAL_BASE_URL = 'http://' + ENTERPRISE_LEARNER_PORTAL_NETLOC +########################## LEARNING MICROFRONTEND ############################## +LEARNING_MICROFRONTEND_PORT = os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010') +LEARNING_MICROFRONTEND_NETLOC = 'localhost:' + LEARNING_MICROFRONTEND_PORT + ########################## ENTERPRISE ADMIN PORTAL ############################## ENTERPRISE_ADMIN_PORTAL_NETLOC = 'localhost:1991' ENTERPRISE_ADMIN_PORTAL_BASE_URL = 'http://' + ENTERPRISE_ADMIN_PORTAL_NETLOC @@ -308,7 +312,6 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing 'localhost:1997', # frontend-app-account 'localhost:1976', # frontend-app-program-console 'localhost:1994', # frontend-app-gradebook - 'localhost:2000', # frontend-app-learning 'localhost:2001', # frontend-app-course-authoring 'localhost:18400', # frontend-app-publisher 'localhost:1993', # frontend-app-ora-grading @@ -316,6 +319,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing ENTERPRISE_LEARNER_PORTAL_NETLOC, # frontend-app-learner-portal-enterprise ENTERPRISE_ADMIN_PORTAL_NETLOC, # frontend-app-admin-portal ENTERPRISE_CHECKOUT_NETLOC, # frontend-app-enterprise-checkout + LEARNING_MICROFRONTEND_NETLOC, # frontend-app-learning ]) ###################### JWTs ###################### @@ -386,7 +390,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service' ############## Settings for Microfrontends ######################### -LEARNING_MICROFRONTEND_URL = 'http://localhost:2000' +LEARNING_MICROFRONTEND_URL = 'http://localhost:' + LEARNING_MICROFRONTEND_PORT ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997' PROFILE_MICROFRONTEND_URL = 'http://localhost:1995' COMMUNICATIONS_MICROFRONTEND_URL = 'http://localhost:1984' @@ -546,7 +550,6 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing # MFEs that will call this service in devstack CSRF_TRUSTED_ORIGINS = [ - 'http://localhost:2000', # frontend-app-learning 'http://localhost:2001', # frontend-app-course-authoring 'http://localhost:1997', # frontend-app-account 'http://localhost:1995', # frontend-app-profile @@ -559,6 +562,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing 'http://localhost:18450', # frontend-app-support-tools 'http://localhost:1994', # frontend-app-gradebook 'http://localhost:1996', # frontend-app-learner-dashboard + LEARNING_MICROFRONTEND_URL # frontend-app-learning ] ############################ Codejail ############################ From f266f4d58a251700c7499b088d4e64944e71d4b5 Mon Sep 17 00:00:00 2001 From: ktyagiapphelix2u Date: Mon, 4 Aug 2025 14:52:52 +0000 Subject: [PATCH 2/2] fix: Dynamic port for LEARNING MFE in form of ENV variable --- .devcontainer/devcontainer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 86762e8e..8a0e6b6e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,8 +37,8 @@ "postCreateCommand": ".devcontainer/postCreateCommand.sh", "postStartCommand": ".devcontainer/postStartCommand.sh", "forwardPorts": [ - 1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2010, - 2001, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202, + 1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, + 2010, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202, 9301, 9600, 18000, 18010, 18040, 18110, 18120, 18130, 18150, 18160, 18170, 18270, 18280, 18381, 18400, 18450, 18734, 18760, 18787, 19001, 27017, 44567