vscode-rdbg icon indicating copy to clipboard operation
vscode-rdbg copied to clipboard

Help with using rdbg within a docker-compose service

Open bmtrann opened this issue 1 year ago • 6 comments

I have a Rails app that is run in Docker Compose with following structure:

my-rails-app:
  build: .
  image: my-image
  ports:
    - 3000:3000
    - 1234:1234
  command: ["rdbg", "-n", "--open", "--port", "1234", "-c", "--", "rails", "server", "-b", "0.0.0.0"]
  stdin_open: true
  tty: true

I tried following the docs and construct my launch.json like the following:

{
    // 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": [
        {
            "type": "rdbg",
            "name": "Debug Rails with rdbg",
            "rdbgPath": "docker-compose exec my-rails-app rdbg",
            "request": "launch",
            "script": "rails s",
            "command": "docker-compose exec my-rails-app rdbg -c",
        },
        {
            "type": "rdbg",
            "name": "Attach with rdbg",
            "request": "attach",
            "rdbgPath": "docker-compose exec my-rails-app rdbg",
            "debugPort": "localhost:1234"
        }
    ]
}

I have also put gem "debug", ">= 1.0.0" in my Gemfile. When pressing F5 to debug, with both launch and attach mode, VSCode kept saying that it couldnt find the process..

Couldn't start debug session. The debuggee process exited with code 1 with launch connect ECONNREFUSED 127.0.0.1:1234 with attach

Any help is appreciated, sorry if there's anything unclear since this is my 1st time writing a Github issue!

bmtrann avatar Mar 23 '23 12:03 bmtrann

your rdbgPath looks to contain an executable script, and not a path - I would be shocked if that worked. Are you hoisting your workspace into the container - but running vscode "locally"? Or are you using a devcontainer with vscode inside devcontainer?

firien avatar Mar 23 '23 13:03 firien

if you are running vscode locally - and hoisting your workspace into the container then you shouldn't need rdbgPath - just the debugPort

/workspace below is whatever path you have loaded as WORKDIR in Dockerfile (I assume you are mapping your rails project as a volume via docker compose)

"type": "rdbg",
"name": "Attach with rdbg",
"request": "attach",
"debugPort": "1234",
"localfsMap": "/workspace:${workspaceFolder}"

firien avatar Mar 23 '23 14:03 firien

thanks @firien for the quick response. I tried using VSCode inside the dev container and the attach debugging mode worked per your instructions! Just wondering what would I put in the rdbgPath if I want to switch to launch mode? I saw someone put in bundle exec rdbg and said it worked here, which made me kinda confused too.

bmtrann avatar Mar 23 '23 16:03 bmtrann

Are you really running in a dev container? Do you have a Remote Host label like Dev Container in the status bar like that? image

firien avatar Mar 23 '23 16:03 firien

umm yeah

Capture

eaera is the name of my Rails app, unless it's not what you meant then apologies :)

bmtrann avatar Mar 23 '23 17:03 bmtrann

ah ok so you are in the container, then you shouldn't need the debugPort option. You should be able to talk directly to a socket. Something as simple as config below should find the socket.

{
     "type": "rdbg",
     "name": "rails",
     "request": "attach"
}

although you would probably have to remove the port option from startup

command: ["rdbg", "-n", "--open", ~"--port", "1234"~, "-c", "--", "rails", "server", "-b", "0.0.0.0"]


As for launching, it seems your server is booted up with the container, so you kind of have to attach to it.


You can experiment with rails/console launches (you may need to make a few adjustments, I am using an rdbg bin stub in config below)

{
    "type": "rdbg",
    "name": "Launch Rails Console",
    "request": "launch",
    "command": "bin/rails",
    "args": ["--", "--noautocomplete"],
    "script": "console",
    "useBundler": false, // using a bin/stub at rdbgPath
    "useTerminal": true,
    "rdbgPath": "bin/rdbg", // no docker compose stuff
}

firien avatar Mar 23 '23 17:03 firien