capstrap 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .bundle
21
+ .yardoc
22
+ doc
23
+
24
+ ## PROJECT::SPECIFIC
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm default@capstrap
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capstrap.gemspec
4
+ gemspec
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capstrap (0.0.1)
5
+ capistrano (~> 2.5.19)
6
+ thor (~> 0.14.3)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ capistrano (2.5.19)
12
+ highline
13
+ net-scp (>= 1.0.0)
14
+ net-sftp (>= 2.0.0)
15
+ net-ssh (>= 2.0.14)
16
+ net-ssh-gateway (>= 1.0.0)
17
+ diff-lcs (1.1.2)
18
+ highline (1.6.1)
19
+ net-scp (1.0.4)
20
+ net-ssh (>= 1.99.1)
21
+ net-sftp (2.0.5)
22
+ net-ssh (>= 2.0.9)
23
+ net-ssh (2.0.23)
24
+ net-ssh-gateway (1.0.1)
25
+ net-ssh (>= 1.99.1)
26
+ rspec (2.0.1)
27
+ rspec-core (~> 2.0.1)
28
+ rspec-expectations (~> 2.0.1)
29
+ rspec-mocks (~> 2.0.1)
30
+ rspec-core (2.0.1)
31
+ rspec-expectations (2.0.1)
32
+ diff-lcs (>= 1.1.2)
33
+ rspec-mocks (2.0.1)
34
+ rspec-core (~> 2.0.1)
35
+ rspec-expectations (~> 2.0.1)
36
+ thor (0.14.3)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ capistrano (~> 2.5.19)
43
+ capstrap!
44
+ rspec (~> 2.0.0)
45
+ thor (~> 0.14.3)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Fletcher Nichol
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = capstrap
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Fletcher Nichol. See LICENSE for details.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'capstrap'
6
+
7
+ Capstrap::CLI.start
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capstrap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capstrap"
7
+ s.version = Capstrap::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Fletcher Nichol"]
10
+ s.email = ["fnichol@nichol.ca"]
11
+ s.homepage = "http://rubygems.org/gems/capstrap"
12
+ s.summary = %q{bootstrapping chef solo from capistrano}
13
+ s.description = %q{A command to remotely install git, rvm, ruby, and chef-solo using capistrano.}
14
+
15
+ s.rubyforge_project = "capstrap"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "thor", "~> 0.14.3"
23
+ s.add_dependency "capistrano", "~> 2.5.19"
24
+
25
+ s.add_development_dependency "rspec", " ~>2.0.0"
26
+ end
@@ -0,0 +1,7 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "Requires Capistrano 2"
3
+ end
4
+
5
+ Dir[File.join(File.dirname(__FILE__), %w{capstrap *.rb})].each do |lib|
6
+ load(lib)
7
+ end
@@ -0,0 +1,43 @@
1
+ module Capstrap
2
+ module Apt
3
+
4
+ APT_RVM_PKGS = %w{sed grep tar gzip bzip2 bash curl git-core}
5
+
6
+ APT_MRI_AND_REE_PKGS = %w{build-essential bison openssl libreadline5
7
+ libreadline-dev zlib1g zlib1g-dev libssl-dev vim libsqlite3-0
8
+ libsqlite3-dev sqlite3 libxml2-dev subversion autoconf ssl-cert}
9
+
10
+ def self.load_into(configuration)
11
+ configuration.load do
12
+
13
+ def self.task_name(pkg)
14
+ pkg.gsub(/-/, "_").to_sym
15
+ end
16
+
17
+ namespace :apt do
18
+ namespace :install do
19
+ desc "Installs packages for running RVM"
20
+ task :rvm_depends do
21
+ apt_install APT_RVM_PKGS.join(" ")
22
+ end
23
+
24
+ desc "Installs packages for running MRI/REE."
25
+ task :mri_depends do
26
+ apt_install APT_MRI_AND_REE_PKGS.join(" ")
27
+ end
28
+
29
+ desc "Installs all packages via apt-get."
30
+ task :default do
31
+ rvm_depends
32
+ mri_depends
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ if Capistrano::Configuration.instance
42
+ Capstrap::Apt.load_into(Capistrano::Configuration.instance)
43
+ end
@@ -0,0 +1,27 @@
1
+ module Capstrap
2
+ module Chef
3
+
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ namespace :chef do
8
+ namespace :install do
9
+
10
+ desc "Installs chef solo"
11
+ task :solo do
12
+ cmd = [
13
+ %{use default@global},
14
+ %{gem install chef}
15
+ ]
16
+ rvm_run cmd.join(" && ")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ if Capistrano::Configuration.instance
26
+ Capstrap::Chef.load_into(Capistrano::Configuration.instance)
27
+ end
@@ -0,0 +1,121 @@
1
+ ##
2
+ # Runs a remote if condition and returns true/false.
3
+ #
4
+ # @param [String] conditional to be tested
5
+ # @return [true, false] whether or not the conditional passes
6
+ def cmd_if(test, rvm=false)
7
+ load_rvm = ""
8
+ load_rvm = rvm_env
9
+ r = capture %{#{rvm_env} if #{test} ; then echo true; else echo false; fi},
10
+ :shell => "bash"
11
+ puts " * Result is: #{r.to_s}"
12
+ if r.to_s =~ /true/
13
+ true
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ ##
20
+ # Runs a remote if test condition and returns true/false
21
+ #
22
+ # @param [String] test to be tested
23
+ # @return [true, false] whether or not the test passes
24
+ def cmd_test(test, rvm=false)
25
+ cmd_if %{[ #{test} ]}, rvm
26
+ end
27
+
28
+ ##
29
+ # Checks if a package is installed on the remote host.
30
+ #
31
+ # @param [String] package name to check
32
+ # @return [true, false] whether or not the package is installed
33
+ def pkg_installed?(pkg)
34
+ cmd_if %{dpkg-query --showformat='${Essential}\n' --show '#{pkg}' > /dev/null 2>&1}
35
+ end
36
+
37
+ ##
38
+ # Installs a package via apt-get.
39
+ #
40
+ # @param [String] package name to install
41
+ def apt_install(pkg, check=false)
42
+ if check && pkg_installed?(pkg)
43
+ info %{Package "#{pkg}" is already installed, skipping.}
44
+ else
45
+ run %{apt-get install -y #{pkg}}
46
+ end
47
+ end
48
+
49
+ def rvm_env
50
+ %{[[ -s "/usr/local/lib/rvm" ]] && source /usr/local/lib/rvm; }
51
+ end
52
+
53
+ ##
54
+ # Runs a remote command in an RVM aware bubble.
55
+ #
56
+ # @param [String] command to run
57
+ def rvm_run(cmd)
58
+ run %{#{rvm_env} rvm #{cmd}}, :shell => "bash"
59
+ end
60
+
61
+ ##
62
+ # Checks if RVM is installed on the remote host.
63
+ #
64
+ def rvm_installed?
65
+ cmd_test %{-s "/usr/local/lib/rvm"}
66
+ end
67
+
68
+ ##
69
+ # Checks if an RVM ruby is installed on the remote host.
70
+ #
71
+ # @param [String] ruby string
72
+ def ruby_installed?(ruby)
73
+ cmd_if %{rvm list strings | grep -q "#{ruby}" >/dev/null}, true
74
+ end
75
+
76
+ ##
77
+ # Prints an information message.
78
+ #
79
+ # @param [String] message to display
80
+ def info(msg)
81
+ puts "\n ==> #{msg}"
82
+ end
83
+
84
+ ##
85
+ # Prints a message intended to catch attention.
86
+ #
87
+ # @param [String] message to display
88
+ def banner(msg)
89
+ puts "\n #{'*' * (msg.size + 6)}"
90
+ puts " * #{msg} *"
91
+ puts " #{'*' * (msg.size + 6)}\n"
92
+ end
93
+
94
+
95
+ module Capstrap
96
+ module Core
97
+
98
+ def self.load_into(configuration)
99
+ configuration.load do
100
+
101
+ namespace :core do
102
+ desc "Installs entire toolchain."
103
+ task :default do
104
+ unless rvm_installed?
105
+ apt.install.rvm_depends
106
+ rvm.install.system_base
107
+ rvm.install.sugar
108
+ end
109
+ apt.install.mri_depends
110
+ rvm.install.ree187
111
+ rvm.default.ree187
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ if Capistrano::Configuration.instance
120
+ Capstrap::Core.load_into(Capistrano::Configuration.instance)
121
+ end
@@ -0,0 +1,64 @@
1
+ require 'ostruct'
2
+
3
+ module Capstrap
4
+ module RVM
5
+
6
+ RUBIES = [
7
+ OpenStruct.new(:ruby => "ruby-1.8.7", :title => "MRI 1.8.7"),
8
+ OpenStruct.new(:ruby => "ruby-1.9.2", :title => "MRI 1.9.2"),
9
+ OpenStruct.new(:ruby => "ree-1.8.7", :title => "REE 1.8.7"),
10
+ ]
11
+
12
+ def self.load_into(configuration)
13
+ configuration.load do
14
+ namespace :rvm do
15
+ namespace :install do
16
+
17
+ desc "Installs system-wide rvm from github."
18
+ task :system_base do
19
+ unless rvm_installed?
20
+ run %{bash < <( curl -L http://bit.ly/rvm-install-system-wide )},
21
+ :shell => "bash"
22
+ end
23
+ end
24
+
25
+ desc "Installs basic rvm/gem/irb configs."
26
+ task :sugar do
27
+ run %{bash < <( curl -L http://bit.ly/rvm_sugar )},
28
+ :shell => "bash"
29
+ end
30
+
31
+ RUBIES.each do |r|
32
+ desc "Installs latest #{r.title} ruby."
33
+ task r.ruby do
34
+ unless rvm_installed?
35
+ apt.install.rvm_depends
36
+ rvm.install.system_base
37
+ rvm.install.sugar
38
+ end
39
+ unless ruby_installed?(r.ruby)
40
+ apt.install.mri_depends
41
+ rvm_run %{#{r.ruby} install}
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ namespace :default do
48
+
49
+ RUBIES.each do |r|
50
+ desc "Sets #{r.title} as default ruby."
51
+ task :"#{r.ruby}" do
52
+ rvm_run %{#{r.ruby} --default}
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ if Capistrano::Configuration.instance
63
+ Capstrap::RVM.load_into(Capistrano::Configuration.instance)
64
+ end
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+ require 'capistrano'
3
+ require 'capistrano/cli'
4
+
5
+ require 'capistrano/ext/capstrap/apt'
6
+ require 'capistrano/ext/capstrap/core'
7
+ require 'capistrano/ext/capstrap/rvm'
8
+ require 'capistrano/ext/capstrap/chef'
9
+
10
+ require 'capstrap/cli'
@@ -0,0 +1,55 @@
1
+ module Capstrap
2
+ class CLI < Thor
3
+
4
+ def initialize(*)
5
+ super
6
+ end
7
+
8
+ default_task :help
9
+
10
+ desc "ruby HOST", "Install an RVM ruby on remote SSH host HOST"
11
+ method_option "ruby", :type => :string, :banner =>
12
+ "Version of ruby to install.", :default => "ree-1.8.7"
13
+ method_option "default", :type => :boolean, :banner =>
14
+ "Set this ruby to be RVM default."
15
+ def ruby(ssh_host)
16
+ @ssh_host = ssh_host
17
+ abort ">> HOST must be set" unless @ssh_host
18
+
19
+ config.find_and_execute_task "rvm:install:#{options[:ruby]}"
20
+ if options[:default]
21
+ config.find_and_execute_task "rvm:default:#{options[:ruby]}"
22
+ end
23
+ end
24
+
25
+ desc "chefsolo HOST", "Install chef solo on remote SSH host HOST"
26
+ method_option "ruby", :type => :string, :banner =>
27
+ "Version of ruby to install.", :default => "ree-1.8.7"
28
+ def chefsolo(ssh_host)
29
+ @ssh_host = ssh_host
30
+ abort ">> HOST must be set" unless @ssh_host
31
+
32
+ invoke :ruby, [ssh_host], :ruby => options[:ruby], :default => true
33
+ config.find_and_execute_task "chef:install:solo"
34
+ end
35
+
36
+ private
37
+
38
+ def config
39
+ @config ||= prep_config
40
+ end
41
+
42
+ def prep_config
43
+ config = Capistrano::Configuration.new
44
+ config.logger.level = Capistrano::Logger::TRACE
45
+ config.role(:remote_host, @ssh_host)
46
+
47
+ Capstrap::Apt.load_into(config)
48
+ Capstrap::Core.load_into(config)
49
+ Capstrap::RVM.load_into(config)
50
+ Capstrap::Chef.load_into(config)
51
+
52
+ config
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Capstrap
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Capstrap" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'capstrap'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capstrap
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fletcher Nichol
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-21 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 33
30
+ segments:
31
+ - 0
32
+ - 14
33
+ - 3
34
+ version: 0.14.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: capistrano
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 61
46
+ segments:
47
+ - 2
48
+ - 5
49
+ - 19
50
+ version: 2.5.19
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 2
64
+ - 0
65
+ - 0
66
+ version: 2.0.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: A command to remotely install git, rvm, ruby, and chef-solo using capistrano.
70
+ email:
71
+ - fnichol@nichol.ca
72
+ executables:
73
+ - capstrap
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .document
80
+ - .gitignore
81
+ - .rvmrc
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE
85
+ - README.rdoc
86
+ - Rakefile
87
+ - bin/capstrap
88
+ - capstrap.gemspec
89
+ - lib/capistrano/ext/capstrap.rb
90
+ - lib/capistrano/ext/capstrap/apt.rb
91
+ - lib/capistrano/ext/capstrap/chef.rb
92
+ - lib/capistrano/ext/capstrap/core.rb
93
+ - lib/capistrano/ext/capstrap/rvm.rb
94
+ - lib/capstrap.rb
95
+ - lib/capstrap/cli.rb
96
+ - lib/capstrap/version.rb
97
+ - spec/capstrap_spec.rb
98
+ - spec/spec.opts
99
+ - spec/spec_helper.rb
100
+ has_rdoc: true
101
+ homepage: http://rubygems.org/gems/capstrap
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project: capstrap
130
+ rubygems_version: 1.3.7
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: bootstrapping chef solo from capistrano
134
+ test_files:
135
+ - spec/capstrap_spec.rb
136
+ - spec/spec.opts
137
+ - spec/spec_helper.rb