将 Hunspell 与 Heroku 结合使用
我正在构建一个使用 Hunspell 和 hunspell-ffi gem 的 Rails 应用程序,以便 Ruby 可以与其交互。我正在将应用程序部署到 heroku,但不幸的是,它需要在服务器上安装 Hunspell 才能使 gem 工作。
我有什么办法可以在 Heroku 上安装 Hunspell 吗?或者我是否必须迁移到 EC2?
提前致谢 :)
I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.
Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要构建所需的 Hunspell 库并将其直接包含在您的 Heroku 项目中。
Heroku 在 64 位 Ubuntu 上运行,因此必须在该系统下编译二进制文件。最好的方法是简单地使用 Heroku 的 Vulcan 构建服务器 在 Heroku 实例上进行编译。
编译 Heroku
gem install vulcan
vulcan create vulcan-compile-me
最后一个参数是您自己的应用程序名称。vulcan build -v -s 。 /hunspell-1.3.2
告诉 Vulcan 构建它并自动将成品下载到 /tmp/hunspell..构建服务器需要 cloudant 插件,该插件会自动安装但您必须确保拥有经过验证(添加信用卡)的 Heroku 帐户。如果您在第六步中遇到错误无构建输出,请执行
heroku addons:add cloudant --app vulcan-compile-me
添加到您的项目
heroku config:add LD_LIBRARY_PATH=供应商/hunspell/lib
。安装词典
从 Open Office 下载一些词典并将它们添加到您的项目中。一个好的位置是根级别名为dictionaries的文件夹。然后在 Ruby 中初始化 Hunspell 时会引用该路径。
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
使用
安装你最喜欢的 Hunspell gem,我使用 hunspell-ffi。有一个 Hunspell 的较新 gem 但我更喜欢以前的 FFI gem。使用词典文件夹路径和语言(语言与词典文件名匹配)初始化 Hunspell 对象。
供应更复杂的项目
您还可以将库供应到您的项目中,方法是将第一步中由 Vulcan 服务器构建的 tar 放入公共可访问服务器(例如 Google Storage),然后更改 Heroku 构建包以在每个实例上下载 tar启动。
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
http://commondatastorage.googleapis.com/developer.you.com /hunspell-heroku-1.3.tgz
heroku 配置:添加 LD_LIBRARY_PATH=lib
You need to build the required Hunspell library and include it in your Heroku project directly.
Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.
Compiling for Heroku
gem install vulcan
vulcan create vulcan-compile-me
last argument is your own app name.vulcan build -v -s ./hunspell-1.3.2
Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do
heroku addons:add cloudant --app vulcan-compile-me
Adding to Your Project
heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib
.Install Dictionaries
Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
Using
Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).
Vendoring for More Complex Projects
You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
heroku config:add LD_LIBRARY_PATH=lib
除非我弄错了或者发生了一些变化(我找不到任何证据),否则您无法在 Heroku 上安装外部本机库。如果尚未安装该库(我认为 ImageMagick 可能是这种情况,也许还有其他库),您将无法使用 gem。
Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.
查看此网址: http://gems-summary.heroku.com/2011-07-19
Heroku 对 gem 社区的支持之多令人惊讶。因此,您所需要做的就是将 gem 添加到您的捆绑包中,因为 Hunspell 位于 rubygems 上,捆绑安装,然后部署。
Gemfile
然后添加到 git:
然后捆绑:
并部署:
Checkout this url: http://gems-summary.heroku.com/2011-07-19
It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.
Gemfile
Then add to git:
Then bundle:
And deploy:
使用 Bundler,您应该能够安装任何 gem。根据 http://devcenter.heroku.com /articles/how-do-i-install-gems-for-my-app,“几乎所有 gem - 即使是具有本机依赖项的 gem - 都可以使用 Bundler 安装。如果存在无法安装的特定 gem在 Heroku 上,请提交支持票。”
AFAIK,当您的应用程序启动时,Gemfile 中的 gem 会即时安装到您的应用程序启动的服务器上。
Aspen 堆栈已预安装 gem,但您仍然应该能够添加未预安装的 gem。
竹子堆栈没有预先安装的gem,因此必须显式声明所有gem依赖项。我相信青瓷堆栈也是如此。
With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."
AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.
The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.
The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.