Skip to content

Commit ac9f005

Browse files
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
1 parent be4586c commit ac9f005

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
}
3131
},
3232
"containerEnv": {
33-
"DEVSTACK_WORKSPACE": "/workspaces/edx-repos"
33+
"DEVSTACK_WORKSPACE": "/workspaces/edx-repos",
34+
"LEARNING_MICROFRONTEND_PORT": "2010"
3435
},
3536
"updateContentCommand": ".devcontainer/updateContentCommand.sh",
3637
"postCreateCommand": ".devcontainer/postCreateCommand.sh",
3738
"postStartCommand": ".devcontainer/postStartCommand.sh",
3839
"forwardPorts": [
39-
1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
40+
1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2010,
4041
2001, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202,
4142
9301, 9600, 18000, 18010, 18040, 18110, 18120, 18130, 18150, 18160,
4243
18170, 18270, 18280, 18381, 18400, 18450, 18734, 18760, 18787, 19001,
@@ -60,7 +61,7 @@
6061
"18130": { "label": "ecommerce" },
6162
"18150": { "label": "credentials" },
6263
"18120": { "label": "edx_notes_api" },
63-
"2000": { "label": "frontend-app-learning" },
64+
"2010": { "label": "frontend-app-learning" },
6465
"1998": { "label": "frontend-app-payment" },
6566
"18400": { "label": "frontend-app-publisher" },
6667
"1994": { "label": "frontend-app-gradebook" },

.devcontainer/updateContentCommand.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,27 @@ for repo_dir in ${repo_dirs[@]}; do
7979

8080
popd
8181
done
82+
83+
84+
echo "Updating .env.development files for MFE apps..."
85+
86+
# Define shared values
87+
PORT=${LEARNING_MICROFRONTEND_PORT:-2010}
88+
BASE_URL="http://localhost:$PORT"
89+
90+
# Loop through frontend-app-* repos
91+
find "$DEVSTACK_WORKSPACE" -type d -name "frontend-app-*" | while read -r repo; do
92+
ENV_FILE="$repo/.env.development"
93+
94+
95+
if [ -f "$ENV_FILE" ]; then
96+
echo "Updating $ENV_FILE..."
97+
if [[ "$repo" == *"frontend-app-learning" ]]; then
98+
sed -i.bak -E "s|^PORT=.*|PORT=$PORT|" "$ENV_FILE"
99+
sed -i.bak -E "s|^BASE_URL=.*|BASE_URL='$BASE_URL'|" "$ENV_FILE"
100+
else
101+
sed -i.bak -E "s|^LEARNING_BASE_URL=.*|LEARNING_BASE_URL='$BASE_URL'|" "$ENV_FILE"
102+
fi
103+
rm -f "$ENV_FILE.bak"
104+
fi
105+
done

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ services:
11261126
aliases:
11271127
- edx.devstack.frontend-app-learning
11281128
ports:
1129-
- "2000:2000"
1129+
- "${LEARNING_MICROFRONTEND_PORT:-2010}:${LEARNING_MICROFRONTEND_PORT:-2010}"
11301130
depends_on:
11311131
- lms
11321132

py_configuration_files/course_discovery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# noinspection PyUnresolvedReferences
2+
import os
23
from course_discovery.settings._debug_toolbar import * # isort:skip
34

45
from course_discovery.settings.production import *
@@ -18,7 +19,7 @@
1819
'http://localhost:1991', # frontend-app-admin-portal
1920
'http://localhost:18400', # frontend-app-publisher
2021
'http://localhost:18450', # frontend-app-support-tools
21-
'http://localhost:2000', # frontend-app-learning
22+
'http://localhost:' + os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010'), # frontend-app-learning
2223
)
2324

2425
ELASTICSEARCH_DSL['default']['hosts'] = 'edx.devstack.elasticsearch710:9200'

py_configuration_files/ecommerce.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Devstack settings"""
22

33

4+
import os
45
from corsheaders.defaults import default_headers as corsheaders_default_headers
56

67
from ecommerce.settings.production import *
@@ -55,8 +56,8 @@
5556
'http://localhost:1996',
5657
'http://localhost:1997', # Account MFE
5758
'http://localhost:1998',
58-
'http://localhost:2000', # Learning MFE
5959
'http://localhost:8734', # Enterprise Learner Portal MFE
60+
'http://localhost:' + os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010'), # Learning MFE
6061
)
6162
CORS_ALLOW_HEADERS = corsheaders_default_headers + (
6263
'use-jwt-cookie',

py_configuration_files/enterprise_subsidy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from enterprise_subsidy.settings.local import *
23

34
CORS_ORIGIN_WHITELIST = (
@@ -54,6 +55,9 @@
5455
'BACKEND_SERVICE_EDX_OAUTH2_SECRET', 'enterprise-subsidy-backend-service-secret'
5556
)
5657

58+
# This port is configured centrally in devcontainer.json
59+
LEARNING_MICROFRONTEND_PORT = os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010')
60+
5761
JWT_AUTH.update({
5862
'JWT_SECRET_KEY': 'lms-secret',
5963
'JWT_ISSUER': 'http://localhost:18000/oauth2',
@@ -75,7 +79,7 @@
7579
LMS_URL = 'http://edx.devstack.lms:18000'
7680
ENTERPRISE_CATALOG_URL = 'http://edx.devstack.enterprise-catalog:18160'
7781
ENTERPRISE_SUBSIDY_URL = 'http://localhost:18280'
78-
FRONTEND_APP_LEARNING_URL = 'http://localhost:2000'
82+
FRONTEND_APP_LEARNING_URL = 'http://localhost:' + LEARNING_MICROFRONTEND_PORT
7983

8084
# Kafka Settings
8185
# "Standard" Kafka settings as defined in https://github.com/openedx/event-bus-kafka/tree/main

py_configuration_files/lms.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
269269
ENTERPRISE_LEARNER_PORTAL_NETLOC = 'localhost:8734'
270270
ENTERPRISE_LEARNER_PORTAL_BASE_URL = 'http://' + ENTERPRISE_LEARNER_PORTAL_NETLOC
271271

272+
########################## LEARNING MICROFRONTEND ##############################
273+
LEARNING_MICROFRONTEND_PORT = os.environ.get('LEARNING_MICROFRONTEND_PORT', '2010')
274+
LEARNING_MICROFRONTEND_NETLOC = 'localhost:' + LEARNING_MICROFRONTEND_PORT
275+
272276
########################## ENTERPRISE ADMIN PORTAL ##############################
273277
ENTERPRISE_ADMIN_PORTAL_NETLOC = 'localhost:1991'
274278
ENTERPRISE_ADMIN_PORTAL_BASE_URL = 'http://' + ENTERPRISE_ADMIN_PORTAL_NETLOC
@@ -308,14 +312,14 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
308312
'localhost:1997', # frontend-app-account
309313
'localhost:1976', # frontend-app-program-console
310314
'localhost:1994', # frontend-app-gradebook
311-
'localhost:2000', # frontend-app-learning
312315
'localhost:2001', # frontend-app-course-authoring
313316
'localhost:18400', # frontend-app-publisher
314317
'localhost:1993', # frontend-app-ora-grading
315318
'localhost:1996', # frontend-app-learner-dashboard
316319
ENTERPRISE_LEARNER_PORTAL_NETLOC, # frontend-app-learner-portal-enterprise
317320
ENTERPRISE_ADMIN_PORTAL_NETLOC, # frontend-app-admin-portal
318321
ENTERPRISE_CHECKOUT_NETLOC, # frontend-app-enterprise-checkout
322+
LEARNING_MICROFRONTEND_NETLOC, # frontend-app-learning
319323
])
320324

321325
###################### JWTs ######################
@@ -386,7 +390,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
386390
EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service'
387391

388392
############## Settings for Microfrontends #########################
389-
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000'
393+
LEARNING_MICROFRONTEND_URL = 'http://localhost:' + LEARNING_MICROFRONTEND_PORT
390394
ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997'
391395
PROFILE_MICROFRONTEND_URL = 'http://localhost:1995'
392396
COMMUNICATIONS_MICROFRONTEND_URL = 'http://localhost:1984'
@@ -546,7 +550,6 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
546550

547551
# MFEs that will call this service in devstack
548552
CSRF_TRUSTED_ORIGINS = [
549-
'http://localhost:2000', # frontend-app-learning
550553
'http://localhost:2001', # frontend-app-course-authoring
551554
'http://localhost:1997', # frontend-app-account
552555
'http://localhost:1995', # frontend-app-profile
@@ -559,6 +562,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
559562
'http://localhost:18450', # frontend-app-support-tools
560563
'http://localhost:1994', # frontend-app-gradebook
561564
'http://localhost:1996', # frontend-app-learner-dashboard
565+
LEARNING_MICROFRONTEND_URL # frontend-app-learning
562566
]
563567

564568
############################ Codejail ############################

0 commit comments

Comments
 (0)