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 :)
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.
Download Hunspell source
Extract
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
Extract the Heroku Vulcan build tar from /tmp
Copy the entire lib folder to vendor/hunspell in your project root directory
Tell Heroku where to look for libraries: 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).
dict = Hunspell.new("dictionaries", "en_US")
if dict.check('caribean') == false
suggestions = dict.suggest('caribean')
if (suggestions.size)
correction = suggestions.first # returns 'caribbean'
end
end
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
The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
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.
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
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'
Then add to git:
git add .
git commit -m 'added hunspell'
Then bundle:
bundle
And deploy:
git push heroku
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.
Related
My understanding is that the gemfile in a Rails app only provides references to the actual code of these gems on your local computer. So when you're running your app locally, it's pulling the gem code from your local computer. What happens when you deploy though? The server runs your rails code, but does it also hold all the references in your gem file and automatically download them as well?
Yep. If you deploy on Heroku, you can see bundler doing its work and pulling down the gems.
As per the Bundler docs, you can use bundle show --paths to see exactly where your gems are being loaded from.
Additionally, if you aren't using bundler, you can use the command gem environment to see gem paths on the system.
See this existing answer for more info: How can I find where gem files are installed?
I am working on a Rails 4 application and one of the requirements is to have all of the Gems that normally go into the Gemfile brought in locally to the machine for use. This includes Rails and after looking at many google search results I am not able to find anyone talking about using the Rails gem locally on a Rails project.
My train of thought here is to clone the rails project from Github locally and then using the bundler config path to target that directory for rails, but I am not sure how well will that solution work or even if it will work.
I will appreciate any input here or if anyone has experience with this situation I will appreciate any insight.
The bundle install does that ?
If you want to install any gem to your project go to the project root on cmd
$ gem install gemname
Doing that you locally installed the gem afterwards you want to make sure its loaded to your project so you can run
$ bundle install
And simply like that your gem is installed. Hope that helps
If you have your project on github, then you can clone it using command.
git clone github-repository-url
And then from that project directory, run command
bundle install --path vendor
It will install all your rubygems into vendor directory.
I have a custom gem built as a .gem file that I am trying to reference from my Gemfile. I have placed the .gem file, along with the .gemspec, in the vendor/gems folder. My Gemfile has the following line:
gem 'umlgrader', '1.0.0', :path=>'vendor/gems'
When I run bundle install, it claims to have found the gem but it says it is "using" the gem, rather than "installing" it, even though the gem was not previously installed on my machine. When I try to run my app, I then get a NoMethodError when it tries to call any of the methods in the gem. Why isn't Bundler installing the gem?
I have gotten it to work by unpacking the gem in that directory and then editing the Gemfile as follows:
gem 'umlgrader', '1.0.0', :path=>'vendor/gems/umlgrader-1.0.0'
This solution is less than desirable. I would prefer to be able to install the gem using Bundler since I am trying to deploy the app to Heroku. I have already tried a lot of the solutions I have found online, but I am open to any suggestions.
EDIT:
Some of the other pages I have already gone through and tried:
Bundler: installing a specific .gem file
How to use Bundler with offline .gem file?
How do I specify local .gem files in my Gemfile?
I also noticed a lot of people suggest pointing to a Git repository containing the gem. I would rather not do this if I don't have to.
The Bundler documentation is somewhat cryptic on that topic, but that is the intended behaviour of Bundler. In order to use the path option you must unpack the gem at the desired location.
But that should be no problem for Heroku. After all, you are still using Bundler, even if the gem is already unpacked. It's just a step less in the gem installing process...
Without Docker
You need to clone the repository from github (or other source) to your custom folder. In example below the steps to reproduce how I use custom path to edit gems in a separeted folder:
In this case I use a custom_gems folder inside /bundle: mkdir /bundle/custom_gems.
cd /bundle/custom_gems.
git clone <gem-repository-source>. Is necessary to clone because if you copy from other folder in your computer probably some files are missed.
Set in your Gemfile: gem '<gem-name>', path: '/bundle/custom_gems/<gem-name>'.
Restart you application.
In docker-compose (or Docker)
With docker is little different, in this case I use a /gems folder inside my rails application folder: mkdir <my-app>/gems.
cd <my-app>/gems.
git clone <gem-repository-source>. Is necessary to clone because if you copy from other folder in your computer probably some files are missed.
Set in your Gemfile: gem '<gem-name>', path: '/bundle/custom_gems/<gem-name>'.
If you use docker-compose, you need to bind folders with volumes config, like below:
volumes:
- ./app/gems:/bundle/custom_gems
With this, your local folder (your machine) copy files inside ./app/gems to /bundle/custom_gems in Docker container.
Restart service.
If you NOT use docker-compose, you need add in Dockerfile some like:
ADD ./app/gems /bundle/custom_gems
I need to get Ruby on Rails (3.0.9) installed onto a production server that doesn't have internet access. Ruby itself is already installed, and is the same version as on my development machine. But there are no gems installed at the moment.
Running gem list -d on my development machine, I can see a pile of gems installed at /usr/lib/ruby/gems/1.8/gems
Basically, I am wondering whether it is possible so simply tar up the gems directory on the development machine, copy to production, and unpack it into the corresponding directory. I would simply try it and see if it works, but I'm aware this is a production install, and I'd rather not be left with something that looks like it works, but doesn't quite.
Is there a better option? e.g. copy these files to somewhere else that I set up as a gem repository?
Bundler offers this feature with bundle package.
Note that this doesn't include gems with sources included via :git or :path options.
I've written a few gems that I've released to rubygems using Gemcutter and the source stored on github.
I have issue that I need to create a gem that can't be open source and also not available to the community, but only to members of my team.
I am aware that I can store gems locally and target them in my Gemfile, however I'd like to be able to do
rake version:bump
rake release
or similar. That would bump the version and push it to my gem server and still keep older gems so that people can install older versions of it.
Seems like it should be fairly simple to do. I'm just missing how to do it
This is fairly simple if you have a server you can host your private gems on. Setup a subdomain, something like gems.companyname.com and setup a virtual host to host your domain. You'd point that virtual host to a folder like you would any website and setup the gem server from there.
Example:
mkdir /var/www/gemserver
mkdir /var/www/gemserver/gems
cp private-gem-0.1.0.gem /var/www/gemserver/gems
cd /var/www/gemserver
gem generate_index
/var/www/gemserver would be the root directory. Lastly all you'd need to do is add a new source to your Gemfile
source 'http://rubygems.org'
source 'http://gems.companyname.com'
So anyone that knows about your custom domain can get access to the gems. The only pain is every time you rebuild your gem you need to run the generate_index command again after you upload your gem to the gems folder.