Skip to content

Commit c4b585e

Browse files
dynamic port for LEARNING MFE in form of ENV variable
1 parent be4586c commit c4b585e

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
}
3131
},
3232
"containerEnv": {
33-
"DEVSTACK_WORKSPACE": "/workspaces/edx-repos"
33+
"DEVSTACK_WORKSPACE": "/workspaces/edx-repos",
34+
"LEARNING_MICROFRONTEND_PORT": "2010",
35+
"LEARNING_MICROFRONTEND_URL": "http://localhost:2010",
36+
"LEARNING_MICROFRONTEND_NETLOC": "localhost:2010"
3437
},
3538
"updateContentCommand": ".devcontainer/updateContentCommand.sh",
3639
"postCreateCommand": ".devcontainer/postCreateCommand.sh",
3740
"postStartCommand": ".devcontainer/postStartCommand.sh",
3841
"forwardPorts": [
39-
1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
42+
1976, 1984, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2010,
4043
2001, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202,
4144
9301, 9600, 18000, 18010, 18040, 18110, 18120, 18130, 18150, 18160,
4245
18170, 18270, 18280, 18381, 18400, 18450, 18734, 18760, 18787, 19001,
@@ -60,7 +63,7 @@
6063
"18130": { "label": "ecommerce" },
6164
"18150": { "label": "credentials" },
6265
"18120": { "label": "edx_notes_api" },
63-
"2000": { "label": "frontend-app-learning" },
66+
"2010": { "label": "frontend-app-learning" },
6467
"1998": { "label": "frontend-app-payment" },
6568
"18400": { "label": "frontend-app-publisher" },
6669
"1994": { "label": "frontend-app-gradebook" },

.devcontainer/updateContentCommand.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,30 @@ 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:-2000}
88+
BASE_URL=${LEARNING_MICROFRONTEND_URL:-"http://localhost:$PORT"}
89+
90+
# Path to workspace
91+
92+
93+
# Loop through frontend-app-* repos
94+
find "$DEVSTACK_WORKSPACE" -type d -name "frontend-app-*" | while read -r repo; do
95+
ENV_FILE="$repo/.env.development"
96+
97+
98+
if [ -f "$ENV_FILE" ]; then
99+
echo "Updating $ENV_FILE..."
100+
if [[ "$repo" == *"frontend-app-learning" ]]; then
101+
sed -i.bak -E "s|^PORT=.*|PORT=$PORT|" "$ENV_FILE"
102+
sed -i.bak -E "s|^BASE_URL=.*|BASE_URL='$BASE_URL'|" "$ENV_FILE"
103+
else
104+
sed -i.bak -E "s|^LEARNING_BASE_URL=.*|LEARNING_BASE_URL='$BASE_URL'|" "$ENV_FILE"
105+
fi
106+
rm -f "$ENV_FILE.bak"
107+
fi
108+
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}:${LEARNING_MICROFRONTEND_PORT}"
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+
os.environ.get('LEARNING_MICROFRONTEND_URL', 'http://localhost: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+
os.environ.get('LEARNING_MICROFRONTEND_URL', 'http://localhost:2010'), # Learning MFE
6061
)
6162
CORS_ALLOW_HEADERS = corsheaders_default_headers + (
6263
'use-jwt-cookie',

py_configuration_files/enterprise_subsidy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
LMS_URL = 'http://edx.devstack.lms:18000'
7676
ENTERPRISE_CATALOG_URL = 'http://edx.devstack.enterprise-catalog:18160'
7777
ENTERPRISE_SUBSIDY_URL = 'http://localhost:18280'
78-
FRONTEND_APP_LEARNING_URL = 'http://localhost:2000'
78+
FRONTEND_APP_LEARNING_URL = os.environ.get('LEARNING_MICROFRONTEND_URL', 'http://localhost:2010')
7979

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

py_configuration_files/lms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
308308
'localhost:1997', # frontend-app-account
309309
'localhost:1976', # frontend-app-program-console
310310
'localhost:1994', # frontend-app-gradebook
311-
'localhost:2000', # frontend-app-learning
312311
'localhost:2001', # frontend-app-course-authoring
313312
'localhost:18400', # frontend-app-publisher
314313
'localhost:1993', # frontend-app-ora-grading
315314
'localhost:1996', # frontend-app-learner-dashboard
315+
LEARNING_MICROFRONTEND_NETLOC, # frontend-app-learning
316316
ENTERPRISE_LEARNER_PORTAL_NETLOC, # frontend-app-learner-portal-enterprise
317317
ENTERPRISE_ADMIN_PORTAL_NETLOC, # frontend-app-admin-portal
318318
ENTERPRISE_CHECKOUT_NETLOC, # frontend-app-enterprise-checkout
@@ -386,7 +386,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
386386
EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service'
387387

388388
############## Settings for Microfrontends #########################
389-
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000'
389+
LEARNING_MICROFRONTEND_URL = os.environ.get('LEARNING_MICROFRONTEND_URL', 'http://localhost:2010')
390390
ACCOUNT_MICROFRONTEND_URL = 'http://localhost:1997'
391391
PROFILE_MICROFRONTEND_URL = 'http://localhost:1995'
392392
COMMUNICATIONS_MICROFRONTEND_URL = 'http://localhost:1984'
@@ -546,7 +546,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
546546

547547
# MFEs that will call this service in devstack
548548
CSRF_TRUSTED_ORIGINS = [
549-
'http://localhost:2000', # frontend-app-learning
549+
LEARNING_MICROFRONTEND_URL, # frontend-app-learning
550550
'http://localhost:2001', # frontend-app-course-authoring
551551
'http://localhost:1997', # frontend-app-account
552552
'http://localhost:1995', # frontend-app-profile

0 commit comments

Comments
 (0)