使用 Bundler 和 JRuby 的 Rails 部署策略
我有一个 jruby Rails 应用程序,并且刚刚开始使用捆绑器进行 gem 依赖项管理。我有兴趣听取人们对部署策略的意见。文档说 bundle package
将在本地打包您的 gem,因此您不必在服务器上获取它们(我相信 warbler 默认情况下会这样做),但我个人认为(对我们来说)这这不是正确的方法,因为我们部署的代码(在我们的例子中是 WAR 文件)变得更大。
我的偏好是模仿我们的 MVN 设置,在代码复制到服务器后直接在服务器上获取所有依赖项。以下是我的想法,欢迎大家批评指正:
Step1:构建war文件,复制到服务器
Step2:在服务器上解压war,使用mvn获取java依赖 Step3:使用Bundler获取Gem deps(这些应该放在哪里??)
* 步骤3是我有点不清楚的步骤。我运行bundle install
时是否考虑到特定目标?
第四步:重启Tomcat
我的理由是,我希望在部署时将依赖项与代码分开。我还想将所有 gem 依赖项放在应用程序本身中,以便包含它们,而不是将它们安装在应用程序用户的主目录中(同样,我相信这是 Bundler 的默认设置)
I have a jruby rails app and I've just started using bundler for gem dependency management. I'm interested in hearing peoples' opinions on deployment strategies. The docs say that bundle package
will package your gems locally so you don't have to fetch them on the server (and I believe warbler does this by default), but I personally think (for us) this is not the way to go as our deployed code (in our case a WAR file) becomes much larger.
My preference would be to mimic our MVN setup which fetches all dependencies directly on the server AFTER the code has been copied there. Here's what I'm thinking, all comments are appreciated:
Step1: Build war file, copy to server
Step2: Unpack war on server, fetch java dependencies with mvn
Step3: use Bundler to fetch Gem deps (Where should these be placed??)
* Step 3 is the step I'm a bit unclear on. Do I runbundle install
with a particular target in mind??
Step4: Restart Tomcat
Again my reasoning here is that I'd like to keep the dependencies separate from the code at deploy time. I'd also like to place all gem dependencies in the app itself so they are contained, rather than installing them in the app user's home directory (as, again, I believe is the default for Bundler)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要查看 Warbler 的默认结构,它就会将 gem 复制到 Rails.root/gems 中,所以我决定遵循该约定。
*注意:我没有看到任何地方将此路径定义为 Rails 的加载路径,但它显然有效。这是我的最终解决方案:
另请注意,
bundle install gems
看起来像一个特定的命令,即。 “安装这些gems”,但gems实际上指的是Rails.root中的gems目录。该目录是由捆绑程序创建的,因此在部署时不需要存在。希望这可以帮助其他正在寻找类似解决方案的人!
Just looking at the default structure from Warbler it copies gems into
Rails.root/gems
, so I just decided to follow that convention.*Note: I don't see anywhere that defines this path as a load path for Rails, but it obviously works. Here's my final solution:
Also note that
bundle install gems
looks like a specific command ie. "Install these gems" but thegems
is actually referring to the directory gems in Rails.root. This directory is created by bundler so doesn't need to exist on deploy.Hope that helps anyone else looking for a similar solution!