How to deploy an RubyGem-based Server - ruby

We have built a custom socket server in ruby and packaged it as a gem. Since this is an internal project we can not simply publish it to RubyForge or GitHub. I tried to setup our own gem server but gem would not authenticate over https. Our other deployment is all for standard rails applications that use capistrano and svn for deployment.
Our current setup which is to use a rails-like deployment with capistrano. which does the following:
Check out the code from svn
Build the gem
Install the gem
Restart the server
This just seems awkward, and makes the gem packaging seem like extra work -- but outside of the deployment issue it fits really nicely as a gem.
Is there a cleaner approach?

Start
gem server #That will serve all your local installed gems.
gem install YourLocalPkg1.X.X.gem
#on YourHost
use
gem sources --add localhost:8808
gem install YourGem
on client machine
develop something
rake gem
gem install YourLocalPkg2.X.X.gem #on YourHost
use
gem update YourGem #on client machine
Maybe you have a need to use https but I don't see why in your post.
On Some Machine
* Check out the code from svn #the railspart not in the gem
* gem update YourGem # or install if not exist....
* Restart the server

You can install gems from the local filesystem.
gem install /path/to/some.gem
Shouldn't be too hard for you to script scp with that, or use an NFS mount, etc.

gem install --local path_to_gem/filename.gem will help. Or you can get a trusted certificate on your web server.
You might be able to install from the server with gem install -P NoSecurity or -P LowSecurity, but I haven't tried that.
http://www.rubygems.org/read/chapter/21

Related

Chef Client skip bundle install on air gapped server

I am trying to install chef recipes on air-gapped server
I bundled gems listed in all recipes and prepared vendor/cache archive. Copying it into the server and running /opt/chef/embedded/bin/bunlde install --local successfully installed 233 gems but when i run chef-client -j boot.json it finds all gems and doesn't download but still run bundle install step and tries to access rubygems.org and fails
Running chef-client in debug mode doesn't reveal any gem name, its trying to download so i don't know what's missing.
Is there anyway i can skip this step or know which gem is missing ?
Part of the run after loading the cookbooks is to install the gems required in the cookbook metadata.rb.
The client prepare a Gemfile and launch a bundle install to check if the necessary gems are installed and up to date, that's the behavior of bundler and why it tries to connect to rubygems.org.
As said in the comments, vendoring all the gems on each server is far from being efficient, you'd better have an internal gem repository and point your cient to it.
That's nearly what you did, get all gems from your recipes, install them on an internal machine and run gem server.
That can be tedious, and there's other approaches allowing to mirror rubygem internally more easily described here

Where does Bundler install gems pulled from Github?

I want to put a debugger in a file for testing, but can't find where Bundler installs gems pulled from Github on my local machine.
I've looked at this thread http://bundler.io/v1.5/git.html which shows how to setup a local file repo to pull from, but I would rather avoid this as my situation is a one off debugging scenario.
I use rbenv for my ruby and gem management. When I pull in a gem from a git repo, it places the files for the gem here:
/usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bundler/gems/gem-name-SHA/
On my machine bundler installed the gem in:
~/.rvm/gems/ruby-2.3.3/bundler/gems/gem-from-github
gem which [GEM] doesn't work on its own, but bundle exec gem which [GEM] does.

Portable ruby weapp on sinatra

I have a webapp running on sinatra with several gems installed.
I would like to zip it and move to another machine, but since that machine doesnt have internet connection I would like to pack all the gems (sinatra, mongoid etc) with it?
If the two machines are similar and you’re using the same Ruby implementation (and version) you could use Bundler. Create a Gemfile, add the gems your app needs to it, then run
$ bundle install
to install those gems to the local machine.
You can then run
$ bundle package
which will copy all the gems used to the vendor/cache directory in your app. After zipping up and transferring the app to the other machine run
$ bundle install --local
to install all the gems from the vendor/cache directory on the other machine.
See the docs for bundle package.

Using Bundler in deployment

Pretty fundamental question but I'm trying to understand how best to use Bundler in a deployment situation.
I'm working on a Sinatra application that has about 20 dependent gems. During development, I'm using RVM with a custom gemset for the application, and I run bundle install to update the gemset in accordance with the gemfile.
When it comes to deployment (manually for now, so I can understand how it all works before using a tool like capistrano), I need to do bundle install --development right? This downloads the gems and places them in vendor/bundle.
My question is what else do I need to do? I'm using Unicorn on the server - do I just bundle exec unicorn ... and everything just works? (i.e. bundler finds the vendor directory and uses the gems from there?)
Should unicorn be a vendored gem in the application or a separate 'system' gem on the server that all applications share?
You need --deployment key, not --development: http://gembundler.com/man/bundle-install.1.html#DEPLOYMENT-MODE
On first run bundler creates config in .bundle directory. You can check it by running bundle config or just cat .bundle/config in project's directory. So bundle exec unicorn is enough since bundler knows where gems are installed. On development machine you can also install gems to arbitrary directory using --path key. For more details see manpage for bundle install (link above or bundle help install).

Local gem install vs running setup.rb

What is the difference between a ruby library installed from a tarball versus through a gem install?
My machine can't connect to rubygems.org because of a university proxy, so all my installations happen locally. I have some gems that I've installed using a gem local install, and others where I've downloaded a tarball and run setup.rb or some such. In my newbie-ish state when messing around with Ruby I wasn't too phased about this inconsistency, but it bothers me now.
I assume rubygems is the preferred method, but I'd like to understand the exact pitfalls so that I can know what to watch out for when I try clean out my machine.
The most important difference is that Ruby extensions installed without the gem mechanism cannot be easily uninstalled or updated (except they provide their own mechanism for that). Automatic installation of dependencies is also largely simplified with gems.
If you are behind a proxy, you can tell gem to use that proxy as well, e.g.
gem install foo --http-proxy http://192.168.0.1:81
or define the environment variable HTTP_PROXY like
export HTTP_PROXY=http://192.168.0.1:81
Look into your browser/network settings to find the proxy address.

Resources