我正在尝试使用Visual Studio Code对Docker容器中的Ruby(on Rails)代码进行远程调试。
我没有在机器上安装Ruby,仅在Docker中安装了
。过程如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot},
"remoteHost": "10.0.75.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "/var/work/app",
"showDebuggerOutput": true,
}
]
}
,然后“快速调试器(ruby-debug-ide 0.7.0.beta7,降级0.2.3.beta3,支持文件过滤)在0.0.0.0:1234上侦听” 但是,VSCode表示我暂停调试时正在执行的行。之后,我可以跨步,变量,WATCH和CALL STACK正常工作。
似乎只有BREAKPOINTS不起作用。
这是我的文件(摘要):
launch.json:
services:
app:
build: "./app"
depends_on:
- db
ports:
- "3000:3000"
- "1234:1234"
- "26162:26162"
volumes:
- "./app:/var/work"
stdin_open: true
tty: true
docker-compose.yml:
gem 'ruby-debug-ide', '0.7.0.beta7'
gem 'debase', '~> 0.2.3.beta3'
宝石文件:
gem 'ruby-debug-ide', '0.6.0'
gem 'debase', '~> 0.2.2'
我也尝试过
{{1}}
答案 0 :(得分:0)
您可能需要在launch.json
中添加捆绑和RdebugIde的路径。像这样:
{
"name": "Debug Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"useBundler": true,
"pathToBundler": "/path/to/rubygem/wrappers/bundle",
"pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server",
"-p",
"3000"
]
}
并调试一种规格:
{
"name": "Debug RSpec - open spec file",
"type": "launch",
"request": "attach",
"cwd": "${workspaceRoot}",
"useBundler": true,
"pathToBundler": "/path/to/rubygem/wrappers/bundle",
"pathToRDebugIDE": "/path/to/rubygem/gems/ruby-debug-ide-x.x.x/bin/rdebug-ide",
"debuggerPort": "1235",
"program": "/path/to/rubygem/bin/rspec",
"args": [
"${file}"
]
}
更多信息,请参考:https://github.com/Microsoft/vscode-recipes/tree/master/debugging-Ruby-on-Rails#bonus。
这对我有用。
答案 1 :(得分:0)
我的问题已经解决。
我修改了launch.json并成功了。似乎出问题的是“ cmd”的目录规范。
“ cmd”必须设置为Windows格式。
供参考,目录结构如下:
product_root
├── .vscode
│ └── launch.json
├── product
│ ├── rails_root
│ │ ├── app
│ │ ├── Gemfile
│ │ ├── etc.
│ └── Dockerfile
└── docker-compose.yml
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}\\product\\rails_root",
"remoteHost": "localhost",
"remotePort": "1234",
"remoteWorkspaceRoot": "/var/work/rails_root"
}
]
}
docker-compose.yml
services:
app:
build: "./product"
depends_on:
- db
ports:
- "3000:3000"
- "1234:1234"
- "26162:26162"
volumes:
- "./product:/var/work"
stdin_open: true
tty: true