diff --git a/.backend_env.example b/.backend_env.example index a4ceaa2ec..b50e83a71 100644 --- a/.backend_env.example +++ b/.backend_env.example @@ -18,4 +18,4 @@ MODEL_PATH=./local_models/ggml-gpt4all-j-v1.3-groovy.bin RESEND_API_KEY= RESEND_EMAIL_ADDRESS=onboarding@resend.dev -CRAWL_DEPTH=1 \ No newline at end of file +CRAWL_DEPTH=1 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..c950225e1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach", + "type": "python", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}/backend", + "remoteRoot": "." + } + ], + "justMyCode": true + } + ] +} diff --git a/backend/.vscode/launch.json b/backend/.vscode/launch.json new file mode 100644 index 000000000..daab14f5a --- /dev/null +++ b/backend/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach", + "type": "python", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "." + } + ], + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index a20912d5d..1f2c7e18c 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,6 +1,9 @@ # Using a slim version for a smaller base image FROM python:3.11-slim-bullseye +ARG DEV_MODE +ENV DEV_MODE=$DEV_MODE + # Install GEOS library, Rust, and other dependencies, then clean up RUN apt-get update && apt-get install -y \ libgeos-dev \ @@ -28,6 +31,8 @@ RUN pip install --upgrade pip # Increase timeout to wait for the new installation RUN pip install --no-cache-dir -r requirements.txt --timeout 200 +RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi + # Copy the rest of the application COPY . . diff --git a/backend/main.py b/backend/main.py index 410a0f55b..2727fb1ae 100644 --- a/backend/main.py +++ b/backend/main.py @@ -29,6 +29,12 @@ from routes.user_routes import user_router logger = get_logger(__name__) +if (os.getenv("DEV_MODE") == "true"): + import debugpy + logger.debug("👨‍💻 Running in dev mode") + debugpy.listen(("0.0.0.0", 5678)) + + sentry_dsn = os.getenv("SENTRY_DSN") if sentry_dsn: sentry_sdk.init( diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 544e013c2..7e5e5a170 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" services: frontend: @@ -22,6 +22,8 @@ services: build: context: backend dockerfile: Dockerfile + args: + - DEV_MODE=true container_name: backend-core restart: always volumes: @@ -31,14 +33,15 @@ services: - worker ports: - 5050:5050 - + - 5678:5678 # debug port + redis: image: redis:latest container_name: redis restart: always ports: - 6379:6379 - + worker: env_file: - ./backend/.env @@ -52,8 +55,7 @@ services: - redis volumes: - ./backend/:/code/ - - + flower: env_file: - ./backend/.env diff --git a/docs/docs/Reference/Tests.md b/docs/docs/Reference/Tests.md index 27632c9dd..1734d1a0f 100644 --- a/docs/docs/Reference/Tests.md +++ b/docs/docs/Reference/Tests.md @@ -15,9 +15,18 @@ title: Testing Strategies - Chat related functions How: + - Pytest -# Frontend +### 🐛 Debugging the backend + +The backend is running in a docker container. To debug the backend, you can attach a debugger to the container. The debugger server runs on port `5678`. The backend is started in dev mode with `make dev`. + +#### Debug with VSCode + +The configuration for this is already set up in the `launch.json` file in the `.vscode` folder. After you started the project in dev mode with `make dev` you can run a debugging session using the `Python: Remote attach` configuration. + +## Frontend - Functional tests - Good rendering of components @@ -26,5 +35,6 @@ How: - User can interact with the component How: + - Vitest - RTL (React Testing Library)