marieai / marie-ai

Integrate AI-powered Document Analysis Pipelines
MIT License
57 stars 3 forks source link

Add support for remote debugging container via debugpy #79

Closed gregbugaj closed 1 year ago

gregbugaj commented 1 year ago

Need capability to debug remote docker containers

gregbugaj commented 1 year ago

VSCode Remote Debug

Using VSCode Remote Debugging with Marie is easy.

Starting the server

To start the server with DEBUG enabled, run the following command:

MARIE_DEBUG=1 marie server --start --uses /mnt/data/marie-ai/config/service/marie.yml 

This will start the server with DEBUG enabled and will wait for the debugger to attach. By default, the debugger will wait for the client to attach on port 5678 and will bind to 0.0.0.0

Advanced configuration:

If not specified, the following defaults will be used:

MARIE_DEBUG=1
MARIE_DEBUG_PORT=5678
MARIE_DEBUG_WAIT_FOR_CLIENT=1
MARIE_DEBUG_HOST=0.0.0.0

Usage:

MARIE_DEBUG=1;MARIE_DEBUG_PORT=5678;MARIE_DEBUG_WAIT_FOR_CLIENT=1;MARIE_DEBUG_HOST=0.0.0.0 \
marie server --start --uses /mnt/data/marie-ai/config/service/marie.yml 

Attaching the debugger

To attach the debugger, you need to create or modify launch.json file in your .vscode folder.

Under the Run/Debug icon and then > menu Run, select Add configuration or Run> Open Configurations. Paste this in or add the keys, confirm your port matches the Marie session. https://code.visualstudio.com/docs/python/debugging

{
    // 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": [
      // Attaches to injected debugpy hosted on port 5678.
      // https://code.visualstudio.com/docs/containers/docker-compose
      {
        "name": "Python: Remote Attach Marie (docker)",
        "type": "python",
        "request": "attach",
        "connect": {
          "host": "0.0.0.0",
          "port": 5678
        },
        "pathMappings": [
          {
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "."
          }
        ]
      },
      // Attaches to injected debugpy hosted on port 5678.
      // https://code.visualstudio.com/docs/containers/docker-compose
      {
        "name": "Python: Remote Attach Marie (localhost)",
        "type": "python",
        "request": "attach",
        "connect": {
          "host": "0.0.0.0",
          "port": 5678
        },
        // "pathMappings": [
        //   {
        //     "localRoot": "${workspaceFolder}",
        //     "remoteRoot": "./marie"
        //   }
        // ]
      }
    ]
  }

Debugging

At this point, you should be able to start the server and attach the debugger. You can now set breakpoints and debug the server.