deploying a gem using capistrano

This is something I wrote to push gems to an internal gem server. It is a simple Capistrano recipe. Here is the Capfile. You can easily move the GemDeployer module into a separate file if you want to reuse it.

module GemDeployer
  def deploy(gem_path_glob)
    gem = Dir[gem_path_glob].first
 
    unless gem
      raise "failed to find gem using #{gem_path_glob}"
    end
 
    # the gem must be read in binary mode, its a
    # windows thing
    File.open(gem, 'rb')  do |f|
      put f.read, 
          "/var/www/html/gems/gems/#{File.basename(gem)}"
    end   
 
    run 'gem generate_index -d /var/www/html/gems'
    # use this for rubygems < 0.9.4
    # run 'index_gem_repository.rb -d /var/www/html/gems'
  end
end
Capistrano.plugin :gem_deployer, GemDeployer
 
role :app, '[SET HOSTNAME HERE]'
 
namespace :deploy do
  task :default do
    gem_deployer.deploy File.dirname(__FILE__) +
                        "/pkg/name-of-your-gem-*.*.*.gem"
  end
end

Post a Comment

Your email is never published nor shared. Required fields are marked *