jackowayed-gemist 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +77 -0
  2. data/lib/gemist.rb +120 -0
  3. metadata +63 -0
@@ -0,0 +1,77 @@
1
+ == Description
2
+
3
+ Capistrano recipes to make it easier to specify gems that need to be installed.
4
+
5
+
6
+ == Requirements
7
+
8
+ * Capistrano 2
9
+
10
+ == Install
11
+
12
+ $ gem install eric-gemist -s http://gems.github.com/
13
+
14
+
15
+ == Configuration
16
+
17
+ Load the gem in your capistrano <tt>config/deploy.rb</tt>:
18
+
19
+ gem 'eric-gemist'
20
+ require 'gemist'
21
+
22
+
23
+ Then configure the gems that should be installed for each role:
24
+
25
+ gemist.role :app, %w(hpricot stomp mongrel mongrel_cluster xmpp4r)
26
+ gemist.role :stompserver, 'stompserver'
27
+ gemist.role :app, 'eric-god', :version => '>= 0.7.7', :source => 'http://gems.github.com/'
28
+
29
+
30
+ == Usage
31
+
32
+ To update the rubygems on your systems, you can run:
33
+
34
+ $ cap gems:update_system
35
+
36
+ To install all the required gems, just run:
37
+
38
+ $ cap gems:install
39
+
40
+ If you are like me and have set :use_sudo to false, you can make sure sudo
41
+ is used to install the gems by running:
42
+
43
+ $ cap gems:install -s run_method=sudo
44
+
45
+
46
+ == Thanks
47
+
48
+ Special thanks to:
49
+
50
+ * Jesse Newland for his inspiration to write this in the form of the san_juan
51
+ capistrano recipe: http://github.com/jnewland/san_juan
52
+
53
+
54
+ == License
55
+
56
+ (The MIT License)
57
+
58
+ Copyright (c) 2008 Eric Lindvall
59
+
60
+ Permission is hereby granted, free of charge, to any person obtaining
61
+ a copy of this software and associated documentation files (the
62
+ "Software"), to deal in the Software without restriction, including
63
+ without limitation the rights to use, copy, modify, merge, publish,
64
+ distribute, sublicense, and/or sell copies of the Software, and to
65
+ permit persons to whom the Software is furnished to do so, subject to
66
+ the following conditions:
67
+
68
+ The above copyright notice and this permission notice shall be
69
+ included in all copies or substantial portions of the Software.
70
+
71
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
72
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
73
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
74
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
75
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
76
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
77
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ module Gemist
2
+ @@gems = Hash.new { |h,role| h[role] = {} }
3
+
4
+ # Usage:
5
+ # role(:app, %w(hpricot mongrel))
6
+ # or
7
+ # role(:app, 'god', :version => '>= 0.7.7')
8
+ def role(role, *gems)
9
+ options = { :version => '>= 0' }
10
+
11
+ if gems.last.is_a?(Hash)
12
+ options.merge!(gems.pop)
13
+ end
14
+
15
+ gems.flatten.each do |gem|
16
+ @@gems[role][gem] = options
17
+ end
18
+
19
+ namespace :gems do
20
+ unless @_gemist_tasks_defined
21
+ desc "Install all required gems"
22
+ task :install do
23
+ @@gems.keys.each do |role|
24
+ send(role).send(:install)
25
+ end
26
+ end
27
+ @_gemist_tasks_defined = true
28
+ end
29
+
30
+ namespace role do
31
+ desc "Install required gems"
32
+ task :install, :roles => role do
33
+ @@gems[role].each do |gem,version|
34
+ gemist.install_gem(gem, version)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def install_system
42
+ url = "http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz"
43
+ filename = 'rubygems-1.2.0.tgz'
44
+ expanded_directory = 'rubygems-1.2.0'
45
+
46
+ run "mkdir -p #{shared_path}/opt/src #{shared_path}/opt/dist #{shared_path}/opt/bin"
47
+ run "curl -L -q -o #{shared_path}/opt/dist/#{filename} #{url}"
48
+ run "rm -rf #{shared_path}/opt/src/#{expanded_directory}"
49
+ run "tar zxvf #{shared_path}/opt/dist/#{filename} -C #{shared_path}/opt/src"
50
+ run "cd #{shared_path}/opt/src/#{expanded_directory} && sudo ruby setup.rb"
51
+ end
52
+
53
+ # Upgrade the *gem* system to the latest version. Runs via *sudo*
54
+ def update_system
55
+ gem_install = fetch('gemist_gem_install') { "gem install --no-rdoc --no-ri" }
56
+ gem_update = fetch('gemist_gem_update') { gem_install.sub('install', 'update') }
57
+
58
+ send(run_method, "#{gem_update} --system")
59
+ end
60
+
61
+ # Auto selects a gem from a list and installs it.
62
+ #
63
+ # *gem* has no mechanism on the command line of disambiguating builds for
64
+ # different platforms, and instead asks the user. This method has the necessary
65
+ # conversation to select the +version+ relevant to +platform+ (or the one nearest
66
+ # the top of the list if you don't specify +version+).
67
+ def install_gem(package, options = {})
68
+ version = options.delete(:version) || '>= 0.0.0'
69
+ platform = options.delete(:platform) || 'ruby'
70
+ source = options.delete(:source)
71
+ install_args = options.delete(:args)
72
+
73
+ gem_install = fetch('gemist_gem_install') { "gem install --no-rdoc --no-ri" }
74
+
75
+ source_arg = "--source #{source}" if source
76
+ version_arg = "--version '#{version}'"
77
+ install_cmd = "#{gem_install} #{source_arg} #{version_arg} #{package}"
78
+ if install_args
79
+ install_cmd << " -- #{install_args}"
80
+ end
81
+
82
+ selections={}
83
+ gem_installed = %(ruby -rubygems -e 'exit(Gem.source_index.find_name(%(#{package}), %(#{version})).size > 0)')
84
+ cmd = %(/bin/sh -c "#{gem_installed} || #{install_cmd}")
85
+ send run_method, cmd, :shell => false, :pty => true do |channel, stream, data|
86
+ data.each_line do |line|
87
+ case line
88
+ when /\s(\d+).*\(#{platform}\)/
89
+ unless selections[channel[:host]]
90
+ selections[channel[:host]]=$1.dup+"\n"
91
+ logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
92
+ end
93
+ when /\s\d+\./
94
+ # Discard other selections from data stream
95
+ when /^>/
96
+ channel.send_data selections[channel[:host]]
97
+ logger.debug line, "#{stream} :: #{channel[:host]}"
98
+ else
99
+ logger.info line, "#{stream} :: #{channel[:host]}"
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ Capistrano.plugin :gemist, Gemist
107
+
108
+ Capistrano::Configuration.instance(:must_exist).load do
109
+ namespace :gems do
110
+ desc "Install rubygems"
111
+ task :install_system do
112
+ gemist.install_system
113
+ end
114
+
115
+ desc "Update rubygems"
116
+ task :update_system do
117
+ gemist.update_system
118
+ end
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackowayed-gemist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Eric Lindvall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-25 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capistrano
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capistrano recipes for gem installation
26
+ email: eric@5stops.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - lib/gemist.rb
35
+ - README.rdoc
36
+ has_rdoc: false
37
+ homepage: http://github.com/eric/gemist/
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Capistrano recipes for gem installation
62
+ test_files: []
63
+