Heroku 上的 JRuby 和 Sinatra
我正在克隆这个仓库:
https://github.com/freeformz/sinatra-jruby- heroku.git
尝试在 Heroku 的 Cedar 堆栈上使用 JRuby/Sinatra。我按照随附的说明进行操作,并且通过“工头启动”,一切都在本地运行良好。然后我 git Push 到 Heroku,它最初加载得很好,但是当我尝试访问该站点时,我在日志中收到错误:
jruby: No such file or directory -- trinidad (LoadError)
所以看来 jruby 找不到“/app/.gems/bin/trinidad”文件。我最初认为它不存在,因为 .gems/ 位于 .gitignore 文件中,但我很确定 Heroku 在 git Push 上创建了该服务器端。
$APPDIR/.gems 已添加到 PATH 中,因此 Heroku 应该能够看到 trinidad 脚本。我还尝试更改 Procfile 以使用以下路径:
web: script/jruby -S bin/trinidad -p $PORT
但没有骰子。有没有人成功地将 JRuby 部署到 Heroku cedar?
谢谢
I'm cloning this repo:
https://github.com/freeformz/sinatra-jruby-heroku.git
to try and use JRuby/Sinatra on Heroku's Cedar stack. I follow the included instructions and everything runs great locally with a 'foreman start'. I then git push to Heroku and it initially loads up fine but when I try to access the site I get an error in the logs:
jruby: No such file or directory -- trinidad (LoadError)
So it seems jruby can't find the "/app/.gems/bin/trinidad" file. I initially thought it wasn't there because .gems/ is in the .gitignore file, but I'm pretty sure Heroku creates that server side on a git push.
$APPDIR/.gems is added to the PATH so Heroku should be able to see the trinidad script. I've also tried to change the Procfile around to play with the path like:
web: script/jruby -S bin/trinidad -p $PORT
But no dice. Has anyone had any success deploying anything JRuby to Heroku cedar?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 Bundler 1.2 开始,您现在可以在
中指定 Ruby 实现和版本 >宝石文件
。这样做的好处是 Heroku 会理解这些设置并为您的环境准备 Heroku 应用程序。以这个
Gemfile
为例:这个很酷的是,Celadon Cedar 默认使用 Ruby 1.9.2。但是,当您在
Gemfile
中指定ruby "1.9.3"
时,它实际上会为您的 Heroku 环境编译 Ruby 1.9.3。现在,如果您想向您的 Heroku 环境添加不同的 Ruby 实现,您可以这样做:
现在,它将在部署时为您的 Heroku 应用程序安装并使用 Ruby 1.9 模式下的 JRuby 1.7.0.preview1。它甚至还会在 Heroku 环境变量中定义正确的 JVM 选项。
最重要的是,它附带了官方 Heroku buildpack,因此无需切换到第 3 方构建包以使 JRuby/JVM 在 Heroku 上运行。虽然我还没有让它工作,但这个也应该与 Rubinius 一起使用,但我相信它目前已被窃听。要么是这样,要么我做错了。
在我看来,这是一个很棒且可扩展的功能。只需定义您在 Gemfile 中使用的 Ruby 实现/版本/模式以及其他依赖项,Heroku 将确保环境准备就绪。
现在,完成所有这些后,Heroku 应该在 APP_ROOT/bin 中创建 binstub(通过 Bundler),因此您可以做的就是这样:
只是不要使用bundle exec 因为 JRuby 对此不太满意。始终使用 Bundler 提供的 binstub,它们始终位于 Heroku 上的
APP_ROOT/bin
中。As of Bundler 1.2 you are now able to specify the Ruby implementation and version in your
Gemfile
. The nice thing about this is that Heroku will understand these settings and prepare the your Heroku application for your environment.Take this
Gemfile
for example:What's cool about this is that by default Celadon Cedar uses Ruby 1.9.2. However, when you specify
ruby "1.9.3"
in theGemfile
it'll actually compile Ruby 1.9.3 for your Heroku environment.Now, if you want to add a different Ruby implementation to your Heroku environment, you can do so like this:
Now it'll install and use JRuby 1.7.0.preview1 in Ruby 1.9 mode for your Heroku application upon deployment. It'll also even define the proper JVM options in the Heroku environment variables.
Best of all is that this comes with the official Heroku buildpack, so there is no need to switch to a 3rd party buildpack to get the JRuby/JVM going on Heroku. Although I haven't gotten it to work yet, this should also work with Rubinius, but I believe it's currently bugged. Either that, or I'm doing it wrong.
This is in my opinion an awesome and scalable feature. Just define the Ruby implementation/version/mode you're using in your Gemfile along with your other dependencies and Heroku will ensure the environment is prepared.
Now, with all this in place, Heroku should create binstubs (through Bundler) in
APP_ROOT/bin
so what you can do is for example this:Just don't use
bundle exec
since JRuby doesn't play nice with that. Always use the binstubs provided by Bundler which are always located inAPP_ROOT/bin
on Heroku.我相信有关在此博客条目中包含 gem 的详细信息可能对您有所帮助:
http://chris.chowie.net/2011/08/28/Sinatra-with-JRuby-on-Heroku/
I believe the details about including gems on this blog entry might be helpful to you:
http://chris.chowie.net/2011/08/28/Sinatra-with-JRuby-on-Heroku/
我怀疑您的宝石不在
/app/.gems
中,而是在/app/vendor/bundle
中您可以通过运行以下命令找出答案:
无论哪种方式,您都应该可能将 GEM_HOME/bin 添加到路径中,而不是您所说的 GEM_HOME 。
我在这里有一篇关于在 Heroku 上运行 Jruby 和 Trinidad 的博客文章:
http://deployingjruby.blogspot.com/2012/03 /deploying-with-trinidad-on-heroku.html
这里有一个示例应用程序:
https://github.com/jkutner/jruby-trinidad-heroku
其他一些您可能会发现材料有点过时了。
I suspect that your gems are not in
/app/.gems
but rather in/app/vendor/bundle
You can find out by running this command:
Either way, you should probably add the GEM_HOME/bin to the path, and not the GEM_HOME as you state.
I've got a blog post on running Jruby and Trinidad on Heroku here:
http://deployingjruby.blogspot.com/2012/03/deploying-with-trinidad-on-heroku.html
And an example app here:
https://github.com/jkutner/jruby-trinidad-heroku
Some of the other material you may find is a little out of date.