我正在尝试在rails应用程序上运行vscode调试器。rails应用程序在docker容器中运行,它使用puma config运行:
docker-compose命令:bundle exec puma -C config/puma.rb -b 'tcp://0.0.0.0:3000'
puma.rb配置
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
if ENV['RACK_ENV'] == 'development'
worker_timeout 3600 # 1 hour to prevent debugger timeouts
end
before_fork do
Barnes.start # Initializes runtime metrics
end
vscode配置
{
"type": "rdbg",
"name": "Attach with rdbg",
"request": "attach",
"debugPort": "localhost:12345",
}
我尝试了许多变化rdbg,调试等。
但还不能让它工作
1条答案
按热度按时间cedebl8k1#
你需要确保这些事情:
1.配置Docker以使用调试器启动服务。在应用根目录下创建
scripts/entrypoint.sh
脚本:i.如果
bundle
不工作,请使用二进制的完整路径,例如/usr/local/bundle/bin/bundle
阅读此处以了解rdebug-ide中的所有可用选项:rdebug-ide githubii.确保
ruby-debug-ide
和debase
gems安装在容器内和机器上。1.在你的docker compose中:
1.在项目根目录中创建一个
.vscode/launch.json
:i.如果你使用的是Intellij,那么在
dispatcherPort
param中放入任意随机整数值。ii.确保在VScode中安装了
Ruby
和VS Code ruby debugger
扩展iii.如果您使用
rbenv
,请相应修改上述扩展选项。(Ctrl+Shift+P > Open user settings json)
这应该够了我在集群模式下使用puma时遇到了一些问题,所以我修改了
puma.rb
,使其只在单一模式下运行,方法是注解掉该文件中与workers
相关的设置。现在你应该都准备好了。把你的容器拿上来:
compose up -d
>然后转到VS-code并启动名为Attach to container
的调试器