如何将Monorepo部署到Heroku?

时间:2018-12-21 14:37:33

标签: ruby heroku monorepo

我们正在评估向Monorepo的迁移,同时将我们的应用程序托管在Heroku上。我们的源代码树如下所示:

.
├── Gemfile
├── Gemfile.lock
├── backend
│   ├── logger
│   │   ├── Gemfile
│   │   ├── Gemfile.lock
│   │   └── Procfile
│   └── legacy
│   │   ├── Gemfile
│   │   ├── Gemfile.lock
│   │   └── Procfile
└── shared
    ├── gems
    │   └── protos
    └── protos

我们找到了多个与monorepos相关的buildpack,即heroku-buildpack-monorepoheroku-buildpack-multi-procfile

在第一种情况下,buildpack用包含应用程序的子目录覆盖部署的根目录。例如,APP_BASE设置为backend/logger。可以,但是我们计划在不同的应用程序之间使用共享的gem,并且覆盖树排除了这种情况:backend/logger将覆盖.,从而删除对shared/gems的访问。

在第二种情况下,启动应用程序之前,需要Procfiles cd到所需目录。我们的Procfile看起来像:

worker: cd backend/logger && bundle exec bin/logger

这是我们首选的前进方式。

问题在于,默认的heroku / ruby​​ buildpack在构建之前不知道cd到应用程序的目录。我在部署时看到的错误消息是:

remote: Compressing source files... done. remote: Building source: remote: remote: -----> Multi-procfile app detected remote: Copied backend/logger/Procfile as Procfile successfully remote: -----> Ruby app detected remote: -----> Compiling Ruby remote: -----> Using Ruby version: ruby-2.5.3 remote: -----> Installing dependencies using bundler 1.15.2 remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment remote: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.17.2). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. remote: Fetching gem metadata from https://rubygems.org/.............. remote: Fetching version metadata from https://rubygems.org/. remote: Fetching rake 12.3.2 ... remote: Installing rubocop 0.61.1 remote: Bundle complete! 4 Gemfile dependencies, 14 gems now installed. remote: Gems in the groups development and test were not installed. remote: Bundled gems are installed into ./vendor/bundle. remote: Bundle completed (4.54s) remote: Cleaning up the bundler cache. remote: -----> Detecting rake tasks remote: remote: remote: -----> Discovering process types remote: Procfile declares types -> release, worker remote: Default types for buildpack -> console, rake remote: remote: -----> Compressing... remote: Done: 34.4M remote: -----> Launching... remote: ! Release command declared: this new release will not be available until the command succeeds. remote: Released v8 remote: https://stb-logger-staging.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. remote: Running release command... remote: remote: bundler: command not found: sequel remote: Install missing gem executables with `bundle install`

已安装的gem是在根目录的Gemfile中声明的gem。如果将buildpack安装到release并从那里运行backend/logger,则bundle install任务将成功。

问题是:我们有什么选择?我可能可以创建/扩展一个buildpack,它将复制/移动shared / gems文件夹到在编译和部署阶段仍然可以访问的位置。有一个我不知道的构建包可以支持我们的用例吗?

PS:我调查了https://github.com/Pagedraw/heroku-buildpack-select-subdir,但它在5分钟的测试中未通过。第一次部署没有部署任何东西。

0 个答案:

没有答案