Skip to content

Commit c2e2ec4

Browse files
feat: enable for lms debug mode
enable for lms debug mode
1 parent 9997c08 commit c2e2ec4

5 files changed

Lines changed: 146 additions & 4 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
},
88
"customizations": {
99
"vscode": {
10+
//Optional list of VS Code extensions to install in the container.
11+
// See https://aka.ms/vscode-dev-containers/extensions.
12+
//
13+
"extensions": [
14+
"ms-python.python",
15+
"ms-python.debugpy"
16+
],
1017
"settings": {
1118
"terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } },
1219
"terminal.integrated.profiles.osx": { "zsh": { "path": "/bin/zsh" } },
@@ -47,7 +54,7 @@
4754
2010, 3406, 5335, 7474, 8000, 8081, 8734, 8735, 9021, 9201, 9202,
4855
9301, 9600, 18000, 18010, 18040, 18110, 18120, 18130, 18150, 18160,
4956
18170, 18270, 18280, 18381, 18400, 18450, 18734, 18760, 18787, 19001,
50-
27017, 44567
57+
27017, 44567, 44568
5158
],
5259
"portsAttributes": {
5360
"3406": { "label": "mysql80" },
@@ -96,6 +103,7 @@
96103
"18270": { "label": "enterprise-access" },
97104
"18280": { "label": "enterprise-subsidy" },
98105
"8000": { "label": "paragon-pattern-library" },
99-
"18760": { "label": "ai-translations" }
106+
"18760": { "label": "ai-translations" },
107+
"44568": { "label": "LMS debugging" }
100108
}
101109
}

LMS_DEBUG_MODE_README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# LMS Debug Mode Setup
2+
3+
This document describes how to run the LMS service in normal or debug mode using the Devstack Makefile.
4+
5+
## Quick Start
6+
7+
### Normal Mode (Default)
8+
To run the LMS service in normal mode without debugpy:
9+
```bash
10+
make dev.up.lms
11+
```
12+
13+
### Debug Mode with debugpy
14+
To run the LMS service in debug mode with debugpy enabled:
15+
```bash
16+
make dev.debug.lms
17+
```
18+
19+
## How It Works
20+
21+
### Implementation Details
22+
23+
1. **LMS Runner Script** (`lms-run.sh`)
24+
- A bash script that determines whether to run in normal or debug mode
25+
- Checks the `DEVSTACK_DEBUG` environment variable
26+
- If set to `debug`: Installs and runs with debugpy on port 44568
27+
- If set to `normal` (default): Runs without debugpy
28+
29+
2. **Docker Compose Configuration**
30+
- The LMS service command now calls `lms-run.sh` instead of hardcoding debugpy
31+
- The `DEVSTACK_DEBUG` environment variable is passed to the container
32+
- Port 44568 remains exposed in docker-compose.yml for debugpy
33+
34+
3. **Makefile Targets**
35+
- `dev.up.%`: Standard targets for normal mode (unchanged)
36+
- `dev.debug.%`: New targets that set `DEVSTACK_DEBUG=debug` before starting services
37+
- Examples:
38+
- `make dev.up.lms` - Start LMS normally
39+
- `make dev.debug.lms` - Start LMS with debugpy
40+
- `make dev.debug.lms+discovery` - Start LMS with debugpy and discovery in normal mode
41+
42+
## VS Code Debugging
43+
44+
With the LMS running in debug mode, you can attach VS Code debugger:
45+
46+
1. Ensure `make dev.debug.lms` is running
47+
2. In VS Code, go to the Debug view (Ctrl+Shift+D)
48+
3. Select "LMS Debugpy" configuration
49+
4. Click the play button to attach the debugger
50+
51+
The debugger will wait for client attachment when configured with `--wait-for-client` flag.
52+
53+
## Switching Between Modes
54+
55+
To switch from one mode to another:
56+
57+
```bash
58+
# Kill existing LMS container
59+
docker-compose kill lms
60+
61+
# Start in the desired mode
62+
make dev.up.lms # Normal
63+
# or
64+
make dev.debug.lms # Debug with debugpy
65+
```
66+
67+
## Troubleshooting
68+
69+
- **Debugpy port already in use**: Ensure no other process is using port 44568
70+
- **Script permission issues**: The `lms-run.sh` script will be executed inside the container, so host permissions don't matter
71+
- **Environment variable not passed**: Verify using `docker-compose exec lms env | grep DEVSTACK_DEBUG`
72+
73+
## Technical Notes
74+
75+
- The `DEVSTACK_DEBUG` environment variable only affects LMS service
76+
- Other services (cms, lms-worker, etc.) are not affected by this flag
77+
- For services other than LMS, standard `dev.up` and `dev.debug` targets still apply the environment variable, but it won't affect their behavior unless they also implement similar logic

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
dev.shell.registrar dev.shell.cms \
5555
dev.shell.cms_watcher dev.shell.xqueue dev.shell.xqueue_consumer \
5656
dev.static dev.static.lms dev.static.cms dev.stats dev.status \
57-
dev.stop dev.up dev.up.attach dev.up.shell \
57+
dev.stop dev.up dev.up.attach dev.up.shell \
58+
dev.stop dev.debug dev.debug.without-deps \
59+
dev.up dev.up.attach dev.up.shell \
5860
dev.up.without-deps dev.up.without-deps.shell dev.up.with-programs \
5961
dev.up.with-watchers dev.validate docs \
6062
help requirements impl-dev.clone.https impl-dev.clone.ssh impl-dev.provision \
@@ -279,6 +281,24 @@ ifeq ($(ALWAYS_CACHE_PROGRAMS),true)
279281
endif
280282

281283

284+
########################################################################################
285+
# Developer interface: Debug mode (with debugpy).
286+
########################################################################################
287+
288+
dev.debug: _expects-service-list.dev.debug ## Bring up services in debug mode (with debugpy).
289+
290+
dev.debug.%: dev.check-memory ## Bring up services in debug mode and their dependencies.
291+
DEVSTACK_DEBUG=debug docker compose up -d $$(echo $* | tr + " ")
292+
ifeq ($(ALWAYS_CACHE_PROGRAMS),true)
293+
make dev.cache-programs
294+
endif
295+
296+
dev.debug.without-deps: _expects-service-list.dev.debug.without-deps ## Bring up services in debug mode by themselves.
297+
298+
dev.debug.without-deps.%: dev.check-memory ## Bring up services in debug mode by themselves.
299+
DEVSTACK_DEBUG=debug docker compose up -d --no-deps $$(echo $* | tr + " ")
300+
301+
282302
dev.ps: ## View list of created services and their statuses.
283303
docker compose ps
284304

docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ services:
421421

422422
lms:
423423
# Switch to `--settings devstack_with_worker` if you want to use lms-worker
424-
command: bash -c 'source /edx/app/edxapp/edxapp_env && (pip install -r /edx/private_requirements.txt; while true; do python /edx/app/edxapp/edx-platform/manage.py lms runserver 0.0.0.0:18000 --settings devstack; sleep 2; done)'
424+
# Use DEVSTACK_DEBUG env var to enable debugpy. See `make dev.debug.lms` and `make dev.up.lms`.
425+
command: bash -c '/edx/devstack/lms-run.sh ${DEVSTACK_DEBUG:-normal}'
425426
container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.lms"
426427
hostname: lms.devstack.edx
427428
depends_on:
@@ -446,6 +447,7 @@ services:
446447
CMS_CFG: "/edx/etc/studio.yml"
447448
PATH: "/edx/app/edxapp/venvs/edxapp/bin:/edx/app/edxapp/nodeenv/bin:/edx/app/edxapp/edx-platform/node_modules/.bin:/edx/app/edxapp/edx-platform/bin:${PATH}"
448449
SERVICE_VARIANT: lms
450+
DEVSTACK_DEBUG: ${DEVSTACK_DEBUG:-normal}
449451
image: edxops/lms-dev:latest
450452
networks:
451453
default:
@@ -455,10 +457,12 @@ services:
455457
ports:
456458
- "18000:18000"
457459
- "19876:19876" # JS test debugging
460+
- "44568:44568" # debugpy
458461
# - "18003:18003"
459462
# - "18031:18031"
460463
volumes:
461464
- edxapp_lms_assets:/edx/var/edxapp/staticfiles/
465+
- ${PWD}/lms-run.sh:/edx/devstack/lms-run.sh
462466

463467
lms-worker:
464468
command: bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && celery --app=lms.celery:APP worker -l debug -c 2'

lms-run.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# LMS runner script to support both normal and debug modes
3+
# Usage: lms-run.sh [debug|normal]
4+
# Expected to be run inside the LMS container
5+
6+
set -e
7+
8+
source /edx/app/edxapp/edxapp_env
9+
10+
DEBUG_MODE="${1:-${DEVSTACK_DEBUG:-normal}}"
11+
12+
# Install pip requirements
13+
pip install -r /edx/private_requirements.txt
14+
15+
if [ "$DEBUG_MODE" = "debug" ]; then
16+
# Install debugpy for debug mode
17+
pip install debugpy
18+
19+
# Run with debugpy
20+
while true; do
21+
python -m debugpy --listen 0.0.0.0:44568 --wait-for-client \
22+
/edx/app/edxapp/edx-platform/manage.py lms runserver 0.0.0.0:18000 \
23+
--settings devstack --noreload
24+
sleep 2
25+
done
26+
else
27+
# Run in normal mode
28+
while true; do
29+
python /edx/app/edxapp/edx-platform/manage.py lms runserver 0.0.0.0:18000 \
30+
--settings devstack --noreload
31+
sleep 2
32+
done
33+
fi

0 commit comments

Comments
 (0)