Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
install gems if you have a gems.yml in the root of yoru app
  • Loading branch information
Ezra Zygmuntowicz committed Apr 28, 2009
1 parent a10e89e commit b00e2d2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/chef-deploy.rb
Expand Up @@ -158,7 +158,9 @@ def load_current_resource
:copy_exclude => @new_resource.copy_exclude,
:revision => (@new_resource.revision || ''),
:git_enable_submodules => @new_resource.enable_submodules,
:git_shallow_clone => @new_resource.shallow_clone
:git_shallow_clone => @new_resource.shallow_clone,
:node => @node,
:new_resource => @new_resource
end

def action_deploy
Expand Down
42 changes: 41 additions & 1 deletion lib/chef-deploy/cached_deploy.rb
@@ -1,5 +1,5 @@
# stolen wholesale from capistrano, thanks Jamis!

require 'yaml'
class ChefDeployFailure < StandardError
end

Expand All @@ -16,6 +16,7 @@ def deploy
run(update_repository_cache)
Chef::Log.info "copying the cached version to #{configuration[:release_path]}"
run(copy_repository_cache)
install_gems
callback(:before_migrate)
migrate
callback(:before_symlink)
Expand All @@ -33,6 +34,45 @@ def restart
end
end

def install_gems
if File.exist?("#{latest_release}/gems.yml")
gems = YAML.load(IO.read("#{latest_release}/gems.yml"))
resources = []
gems.each do |g|
next if has_gem?(g[:name], g[:version])
r = Chef::Resource::GemPackage.new(g[:name], nil, @configuration[:node])
r.version = g[:version]
r.source = "http://gems.github.com"
resources << r
end
resources.each do |r|
r.run_action(:install)
end
end
end

def has_gem?(name, version=nil)
if !$GEM_LIST_DEPLOY
gems = {}
`gem list --local`.each_line do |line|
gems[$1.to_sym] = $2.split(/, /) if line =~ /^(.*) \(([^\)]*)\)$/
end
$GEM_LIST_DEPLOY = gems
end
if $GEM_LIST_DEPLOY[name.to_sym]
if version
if $GEM_LIST_DEPLOY[name.to_sym].include?(version)
Chef::Log.info("Gem: #{name}:#{version} already installed, skipping")
return true
end
else
Chef::Log.info("Gem: #{name} already installed, skipping")
return true
end
end
false
end

# before_symlink
# before_restart
def callback(what)
Expand Down

0 comments on commit b00e2d2

Please sign in to comment.