Page 239 of Agile Web Development with Rails instructs us to add the vendor/cache directory to git.
Is this actually recommended practice? I was under the impression that this directory was platform-specific. Will it cause problems to commit a cache dir under OSX and then deploy to prod under Linux?
This is where your app's gems are stored if you package them locally. So if you deploy from the SCM source and you want to use the exact gem packages that you are using locally, you'll need these files, which is why I suspect the book suggests this.
As far as the gem files go, it won't cause a problem if you develop on a Mac and deploy to a Linux server.
Short answer - yes.
Long answer - it's very handy to keep your gem dependencies with your application. Not just a Gemfile and Gemfile.lock but also the gems themselves.
There are numerous advantages - such as having all your gems available without having to connect to a gem server.
Related
I am trying to deploy APM solution provided by scout app. Scout apm documentation says I need to install a gem in all the applications I am running on the server. I have multiple applications running on single server. All my ruby applications are located at /var/www. Is there a way I can deploy that apm gem in one place and then it can be used for all the services. so that I don't need to add it in each application Gemfile and its config file in config folder. I know I can achieve it using a shell script however problem with that approach is all the apps have their own git repo which would be administrative overhead for me.
No, you have to add gems that you want to use in an application to the Gemfile. Because if you do not add that gem to an application's Gemfile then the application will simply not load that gem.
Another option might be to install the gem globally ion the server and require that gem in each application manually. But that still means you have to add a require 'gem_name' to all applications and this is error-prone because you lose the magic provided by bundler.
tl;dr: No, you have to add the gem to each application's Gemfile.
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 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'm trying to deploy my local app to dreamhost using Capistrano. While running the cap deploy:cold for the first time, I'm getting an error for missing gems. The dreamhost wiki also recommends that users should maintain their own gem repository in the folder $HOME/.gems .
Going back to the main question :
Where are the .gem files stored locally? I can find the individual gem folders in /Library/Ruby/Gems/1.8/gems/ (on my mac). But I cannot find the respective .gem files.
Would copying these .gem files to the server at the location $HOME/.gems/gems solve the problem of missing gems?
Is there a better way to avoid this?
All you need to do is put your gems in a folder and point your app to that; however, this is obsolete. Bundler what what you should use. Below is an article on how it works with DH:
http://wiki.dreamhost.com/Bundler#Get_Your_App_Using_Bundler
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.