【问题标题】:How to use Foreman with subfolders and nested Gemfiles如何将 Foreman 与子文件夹和嵌套的 Gemfile 一起使用
【发布时间】: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 &amp;&amp; bundle &amp;&amp; bundle exec rails server' 也可以正常工作。

我还尝试在 Procfile 行中添加 pwd 并返回子文件夹,但 bundle 仍在根目录中运行。

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails rake bundler foreman procfile


    【解决方案1】:

    所以我发现了问题,这是由于我认为不是超级重要但在原始问题中遗漏的部分。

    Foreman 正在从 repo 根目录中的 Rake 任务的捆绑包中启动:

    exec('bundle exec foreman start -p Procfile.dev')
    

    以这种方式调用它确实会使用捆绑包中的 Foreman,但 Bundler 会接管一切。我将此行更改为:

    Bundler.clean_system('foreman start -p Procfile.dev')
    

    一切似乎都运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2012-07-18
      • 2020-06-27
      • 2019-03-17
      • 2018-04-16
      相关资源
      最近更新 更多