【发布时间】:2018-07-31 03:50:28
【问题描述】:
我正在开发一个大型项目,其中包含 UI、Rails API 和其他一些位于 monorepo 中的基于 Rails/Ruby 的服务。我正在尝试在项目根目录下围绕 Foreman 设置一些 Rake 任务,以在开发模式下启动项目。
repo 的根目录包含一个带有 Foreman 和 Rake 的 Gemfile 以及一个 Procfile:
rails-api: sh -c 'cd ./rails-api && bundle && bundle exec rails server'
rails-api 文件夹只是一个带有自己 Gemfile 的标准 Rails 5 API 应用程序。
从 repo 根目录运行 foreman start 时,输出如下:
11:30:10 factory-api.1 | started with pid 38593
11:30:11 factory-api.1 | Using rake 12.3.0
11:30:11 factory-api.1 | Using bundler 1.16.1
11:30:11 factory-api.1 | Using colorize 0.8.1
11:30:11 factory-api.1 | Using dotenv 2.2.1
11:30:11 factory-api.1 | Using thor 0.19.4
11:30:11 factory-api.1 | Using foreman 0.84.0
11:30:11 factory-api.1 | Bundle complete! 4 Gemfile dependencies, 6 gems now installed.
11:30:11 factory-api.1 | Use `bundle info [gemname]` to see where a bundled gem is installed.
11:30:11 factory-api.1 | bundler: failed to load command: rails (/Users/matthew/.rbenv/versions/2.5.0/bin/rails)
11:30:11 factory-api.1 | Gem::Exception: can't find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
11:30:11 factory-api.1 | /Users/matthew/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:458:in `block in replace_bin_path'
11:30:11 factory-api.1 | /Users/matthew/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/lib/bundler/rubygems_integration.rb:478:in `block in replace_bin_path'
11:30:11 factory-api.1 | /Users/matthew/.rbenv/versions/2.5.0/bin/rails:23:in `<top (required)>'
11:30:11 factory-api.1 | exited with code 1
11:30:11 system | sending SIGTERM to all processes
如您所见,它捆绑了根 Gemfile。从子文件夹手动捆绑就可以了。即使手动执行sh -c 'cd ./rails-api && bundle && bundle exec rails server' 也可以正常工作。
我还尝试在 Procfile 行中添加 pwd 并返回子文件夹,但 bundle 仍在根目录中运行。
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails rake bundler foreman procfile