Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Container Debugging: File Not Found #29

Closed
Finleth opened this issue Mar 29, 2022 · 8 comments
Closed

Docker Container Debugging: File Not Found #29

Finleth opened this issue Mar 29, 2022 · 8 comments

Comments

@Finleth
Copy link

Finleth commented Mar 29, 2022

I'm running a docker container with Alpine running Ruby 3.1 and Rails 7.0 where the docker-compose.yml uses the following command to start the debug session:

sh -c "rm -f tmp/pids/server.pid && rdbg -O --host=0.0.0.0 --port=1234 -c -- bundle exec rails server -b 0.0.0.0 -p 3000"

When I run docker compose up I get the container up and running with a debugger ready for a connection to attach. In my VS Code launch.js I have the following configuration:

{
  "name": "Attach with rdbg",
  "type": "rdbg",
  "request": "attach",
  "debugPort": "1234",
}

When I start the debugger using the above configuration it launches the debugger and immediately stops on the bin/rails file. I can then continue/step through the process using VS Code's debugger tools but it doesn't actually show the debugger line in VS Code and instead says Unable to open '<file name>'. File not found.. It says that for every file that the debugger stops on.

In my docker-compose.yml I define the volumes for the application like so:

.:/app:cached

I'm not sure what I need to do in order to get the full integration of VS Code's debugger with a rails app running on a docker container.

Let me know what other information would be useful to diagnose my issue and I can add that. Thanks!

@ko1
Copy link
Collaborator

ko1 commented Mar 30, 2022

Thank you for the report. I need to prepare repro env...

@ko1
Copy link
Collaborator

ko1 commented Mar 30, 2022

I could repro this feature without Docker. I'm trying to fix, but it can be later version, I can fix.

@ko1
Copy link
Collaborator

ko1 commented Mar 30, 2022

ruby/debug#600 may solve this issue.

@ko1 ko1 closed this as completed Mar 30, 2022
@Finleth
Copy link
Author

Finleth commented Mar 30, 2022

Awesome! Thank you for this quick turnaround! Based off of that pull request does this mean I would be able to set the sourceReference in my launch.json to tell vscode where the debugger's file system is?

@ko1
Copy link
Collaborator

ko1 commented Mar 31, 2022

You don't need any configurations. Please try to use latest version of extension and debug.gem.

@Finleth
Copy link
Author

Finleth commented Mar 31, 2022

I've updated the extension and gem to the latest versions and am getting some parts of it to work! Using the same configurations as I mentioned at the beginning of this issue I can now add a line with debugger which will cause a break when the code is run. However when this happens vscode opens a readonly of the file with the debugger line (which I assume is being sent from the docker container).
Is there a way to use path mappings to tell vscode to use the local files when displaying the debugging info?

Another thing that I'm seeing is when I add a vscode breakpoint (the red dot) then I see this error in my docker container output:

DEBUGGER: Debugger can attach via TCP/IP (0.0.0.0:1234)
DEBUGGER: wait for debugger connection...
DEBUGGER: Connected.
DEBUGGER: ReaderThreadError: No such file or directory @ rb_check_realpath_internal - /app/c:\Users\jpau\Documents\sites\fees\app\controllers\application_controller.rb
["/usr/local/bundle/gems/debug-1.5.0/lib/debug/session.rb:1600:in `realpath'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/session.rb:1600:in `resolve_path'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/session.rb:1373:in `clear_line_breakpoints'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server_dap.rb:233:in `process'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:72:in `block (3 levels) in activate'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:244:in `setup_interrupt'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:70:in `block (2 levels) in activate'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:419:in `block (2 levels) in accept'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:810:in `block (2 levels) in accept_loop'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:807:in `each'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:807:in `block in accept_loop'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:805:in `loop'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:805:in `accept_loop'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:417:in `block in accept'",
 "/usr/local/lib/ruby/3.1.0/socket.rb:782:in `tcp_server_sockets'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:393:in `accept'",
 "/usr/local/bundle/gems/debug-1.5.0/lib/debug/server.rb:49:in `block in activate'"]
DEBUGGER: Disconnected.

The file on my local would be just:

c:\Users\jpau\Documents\sites\fees\app\controllers\application_controller.rb

And on the container would be:

/app/app/controllers/application_controller.rb

Is there anything I need to do so the built in vscode break points reference the correct the path mappings?

@firien
Copy link
Contributor

firien commented Apr 18, 2022

#32 (comment)

I patched together a working demo of this extension in a remote vscode environment - with it debugging a dockerized rails app.

The issue I have now is that I want multiple mappings. The main rails directory is my working directory that I mapped to a docker volume. I can debug with breakpoints fine with my hack job mentioned in #32. But I also have a ruby gems docker volume that is handled by docker that I am more or less oblivious of. I would want the debugger to have a second read only mapping, something like:

{
  "remoteRoots": [
    {
      "remoteRoot": "/path/to/app",
      "localfs": true
    }, {
      "remoteRoot": "/path/to/gems",
      "localfs": false
    }
  ]
}

I believe the localfs* is an internal(ish) vscode configuration, so I think that option applying to different directories might be a pipe dream. But at the very least maybe multiple remote mappings could be supported? If my internal ruby gem files opened in edit mode - that wouldn't be the worst thing.


*correction, localfs is passed on to the ruby debugger

@firien
Copy link
Contributor

firien commented Apr 18, 2022

https://github.com/firien/vscode-rdbg/tree/multi-remote-root

well I just did it, branch above will map multiple directories. The ruby gems files load as editable - but 🤷‍♂️.

{
  "type": "rdbg",
  "name": "Attach with rdbg",
  "request": "attach",
  "debugPort": "12345",
  "localfs": true,
  "sourceMappings": [
    {
      "remoteRoot": "/rails_app" //this is dockerized rails app
      // with localRoot missing - it defaults to workspaceFolder
    },
    {
      "remoteRoot": "/usr/local/bundle", //ruby gems in docker
      "localRoot": "/home/user/.local/share/docker/volumes/app_gems/_data" //local mapping of ruby gem docker volume
    },
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants