cap-strap 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cap-strap might be problematic. Click here for more details.

data/README.md CHANGED
@@ -8,7 +8,6 @@ deploy key.
8
8
 
9
9
  Currently cap-strap has only been tested on Ubuntu 10.04 and 10.10.
10
10
 
11
-
12
11
  ## Installation
13
12
 
14
13
  Add this line to your application's Gemfile:
@@ -21,10 +20,13 @@ And then execute:
21
20
 
22
21
  ## Usage
23
22
 
24
- You will be prompted for the name of the future deploy_user, location of authorized keys and
25
- the deploy user's deploy_key. Deploy key isn't required, and you may skip.
23
+ ####Upload deploy_key for deploy_user
24
+ Set the relative path to the deploy_key and run:
25
+ `$ cap <stage> bootstrap:upload_deploy_key`
26
26
 
27
- You may re-run the deploy_key task by `$ cap <stage> bootstrap:upload_deploy_key`
27
+ ####Upload authorized keys for deploy_user
28
+ Set the relative path to the deploy_key and run:
29
+ `$cap <stage> bootstrap:upload_authorized_keys`
28
30
 
29
31
  In your deploy.rb, you may override the following variables:
30
32
 
@@ -32,11 +34,14 @@ You may specificy any additional packages for installation by setting the :packa
32
34
 
33
35
  Note: Paths are relative to the root
34
36
 
35
- * `set :deploy_user, "<name of user for future deployes>"`
36
- * `set :authorized_keys_file, "<location of authorized keys>"`
37
- * `set :deploy_key_file, "<location of deploy-key>"`
38
- * `set :known_hosts, "<string of known hosts">` - Default is github.com
39
- * `set :default_ruby, "1.9.3-p125"` - Default is 1.9.3-p125
37
+ * `set :bootstrap_user, "<name of root user for bootstraping>"` - default: prompt for user input
38
+ * `set :bootstrap_password, "<password associated with the root user>"` - default: prompt for user input
39
+ * `set :deploy_user, "<name of user for future deployes>"` - default: 'deploy'
40
+ * `set :deploy_user_password, "<password for deploy user>"` - default: skips. Recommend using authorized keys
41
+ * `set :authorized_keys_file, "<location of authorized keys>"` - skips if not specified
42
+ * `set :deploy_key_file, "<location of deploy-key>"` - skips if not specified
43
+ * `set :known_hosts, "<string of known hosts">` - default: github.com
44
+ * `set :default_ruby, "1.9.3-p125"` - default: '1.9.3-p125'
40
45
  * `set :rubies, [
41
46
  "ree-1.8.7-2012.02",
42
47
  {
@@ -44,13 +49,13 @@ Note: Paths are relative to the root
44
49
  :patch => "falcon,debug --force-autoconf -j 3"
45
50
  }
46
51
  ]`
47
- * `set :gemset, "<default gemset>"` - Default is global
48
- * `set :global_gems, ["bundler", "other-gem"]` - Default is ["bundler"]
52
+ * `set :gemset, "<default gemset>"` - default 'global'
53
+ * `set :global_gems, ["bundler", "other-gem"]` - default: ["bundler"]
49
54
  * `set :packages, ["git", "vim"]` - default: []
50
55
 
51
56
  Note: Run from project root
52
57
 
53
- $ cap <stage> bootstrap -s user=<root_username>
58
+ $ cap <stage> bootstrap
54
59
 
55
60
  ## Testing
56
61
 
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "cap-strap"
6
- s.version = "0.0.9"
6
+ s.version = "0.1.0"
7
7
  s.authors = ["Shaun Dern"]
8
8
  s.email = ["shaun@substantial.com"]
9
9
  s.homepage = "http://github.com/substantial/cap-strap"
@@ -4,8 +4,8 @@ server "localhost", :test
4
4
 
5
5
  set :port, 2222
6
6
 
7
- set :user, "vagrant"
8
- set :password, "vagrant"
7
+ set :bootstrap_user, "vagrant"
8
+ set :bootstrap_password, "vagrant"
9
9
 
10
10
  set :gemset, "build-agent"
11
11
  set :rubies, [
@@ -19,6 +19,7 @@ set :rubies, [
19
19
  set :default_ruby, "1.9.3-p125-perf"
20
20
 
21
21
  set :deploy_user, "deploy"
22
+ set :deploy_user_password, "vagrant"
22
23
  set :group, "rvm"
23
24
  set :authorized_keys_file, "config/test-authorized-keys"
24
25
  set :deploy_key_file, "config/test-deploy-key"
@@ -17,9 +17,12 @@ def install_packages(packages)
17
17
  end
18
18
  end
19
19
 
20
- def create_user(user)
20
+ def create_user(user, password)
21
21
  unless user_exists?(user)
22
- sudo "useradd -s /bin/bash -d /home/#{user} -m #{user}"
22
+ command = "useradd -s /bin/bash -d /home/#{user}"
23
+ command << " -p `perl -e 'print crypt(#{password}, salt)'`" if password
24
+ command << " -m #{user}"
25
+ sudo command
23
26
  end
24
27
  end
25
28
 
@@ -85,3 +88,10 @@ def gemrc
85
88
  gem: --no-ri --no-rdoc
86
89
  TEXT
87
90
  end
91
+
92
+ def make_directory(location, opts={})
93
+ sudo "mkdir -p #{location}"
94
+ if opts[:mode]
95
+ sudo "chmod #{opts[:mode]} #{location}"
96
+ end
97
+ end
@@ -5,63 +5,71 @@ require 'capistrano/cli'
5
5
  module Capistrano::CapStrap
6
6
  module Bootstrap
7
7
  def self.load_into(configuration)
8
- configuration.load do
9
- before 'rvm:install_system_wide_rvm', 'bootstrap:install_rvm_dependencies'
10
-
11
- rvm_packages = %w( build-essential openssl libreadline6 libreadline6-dev
8
+ rvm_packages = %w( build-essential openssl libreadline6 libreadline6-dev
12
9
  curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev
13
10
  libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf
14
11
  libc6-dev ncurses-dev automake libtool bison subversion )
15
12
 
16
- _cset(:deploy_user) { Capistrano::CLI.ui.ask("deploy user: ") }
17
- _cset(:user) { Capistrano::CLI.ui.ask("bootstrap root user: ") }
18
- _cset(:authorized_keys_file) { Capistrano::CLI.ui.ask("Location of authorized keys relative to root to upload: ") }
19
- _cset(:deploy_key_file) { Capistrano::CLI.ui.ask("Location of deploy key for upload, press enter to skip: ") }
13
+ configuration.load do
14
+
15
+ namespace :bootstrap do
16
+ before 'rvm:install_system_wide_rvm', 'bootstrap:install_rvm_dependencies'
17
+
18
+ _cset(:deploy_user, "deploy")
19
+ _cset(:bootstrap_user) { Capistrano::CLI.ui.ask("bootstrap root user: ") }
20
+ _cset(:bootstrap_password) { Capistrano::CLI.ui.ask("bootstrap root user password: ") }
20
21
  _cset(:known_hosts) { default_known_hosts }
21
22
  _cset(:packages) { [] }
22
23
 
23
- namespace :bootstrap do
24
- desc "Bootstraps a fresh box. Install RVM, create the deploy user, upload keys."
25
- task :default do
26
- rvm.default
27
- bootstrap.create_deploy_user
28
- bootstrap.upload_deploy_authorized_keys
29
- bootstrap.add_known_hosts
30
- bootstrap.add_rvm_to_sudoers
31
- bootstrap.upload_deploy_key
32
- bootstrap.install_specified_packages
33
- end
24
+ set (:user) { bootstrap_user }
25
+ set (:password) { bootstrap_password }
34
26
 
35
- task :install_specified_packages do
36
- install_packages(packages)
37
- end
27
+ desc "Bootstraps a fresh box. Install RVM, create the deploy user, upload keys."
28
+ task :default do
29
+ set (:user) { bootstrap_user }
30
+ set (:password) { bootstrap_password }
31
+ rvm.default
32
+ bootstrap.create_deploy_user
33
+ bootstrap.upload_deploy_authorized_keys
34
+ bootstrap.add_known_hosts
35
+ bootstrap.add_rvm_to_sudoers
36
+ bootstrap.upload_deploy_key
37
+ bootstrap.install_specified_packages
38
+ end
38
39
 
39
- task :create_deploy_user do
40
- create_user(deploy_user)
41
- add_user_to_group(deploy_user, "rvm")
42
- add_user_to_group(deploy_user, "admin")
43
- end
40
+ task :install_specified_packages do
41
+ install_packages(packages)
42
+ end
44
43
 
45
- desc "Upload authorized keys for the deploy_user. Override by setting :authorized_keys_file. This
44
+ task :create_deploy_user do
45
+ create_user(deploy_user, deploy_user_password)
46
+ add_user_to_group(deploy_user, "rvm")
47
+ add_user_to_group(deploy_user, "admin")
48
+ end
49
+
50
+ desc "Upload authorized keys for the deploy_user. Override by setting :authorized_keys_file. This
46
51
  is the relative path from the project root"
47
52
  task :upload_deploy_authorized_keys do
48
- begin
49
- authorized_keys_path = File.join(File.expand_path(Dir.pwd), authorized_keys_file)
50
- puts "************Looking for Authorized Keys at: #{authorized_keys_path}"
51
- authorized_keys = File.read(authorized_keys_file)
52
- put(authorized_keys, "authorized_keys", :mode => "0600")
53
- sudo "mkdir -p /home/#{deploy_user}/.ssh"
54
- sudo "chmod 0700 /home/#{deploy_user}/.ssh"
55
- sudo "mv ~/authorized_keys /home/#{deploy_user}/.ssh/"
56
- sudo "chown -R #{deploy_user}:rvm /home/#{deploy_user}/.ssh"
57
- rescue Exception => e
58
- puts e
53
+ if authorized_keys_file.empty?
54
+ puts "No authorized keys file, skipping"
55
+ else
56
+ begin
57
+ authorized_keys_path = File.join(File.expand_path(Dir.pwd), authorized_keys_file)
58
+ puts "************Looking for Authorized Keys at: #{authorized_keys_path}"
59
+ authorized_keys = File.read(authorized_keys_file)
60
+ put(authorized_keys, "authorized_keys", :mode => "0600")
61
+ make_directory("/home/#{deploy_user}/.ssh", :mode => "0700")
62
+ sudo "mv ~/authorized_keys /home/#{deploy_user}/.ssh/"
63
+ sudo "chown -R #{deploy_user}:rvm /home/#{deploy_user}/.ssh"
64
+ rescue Exception => e
65
+ puts e
66
+ end
59
67
  end
60
68
  end
61
69
 
62
70
  task :add_known_hosts do
71
+ make_directory("/home/#{deploy_user}/.ssh", :mode => "0700")
63
72
  put(known_hosts, "known_hosts", :mode => "0644")
64
- sudo "mkdir -p /home/#{deploy_user}/.ssh"
65
73
  sudo "mv ~/known_hosts /home/#{deploy_user}/.ssh/known_hosts"
66
74
  sudo "chown -R #{deploy_user}:rvm /home/#{deploy_user}/.ssh"
67
75
  end
@@ -84,8 +92,7 @@ module Capistrano::CapStrap
84
92
  puts "************Looking for Deploy key at: #{deploy_key_path}"
85
93
  id_rsa = File.read(deploy_key_path)
86
94
  put(id_rsa, "id_rsa", :mode => "0600")
87
- sudo "mkdir -p /home/#{deploy_user}/.ssh"
88
- sudo "chmod 0700 /home/#{deploy_user}/.ssh"
95
+ make_directory("/home/#{deploy_user}/.ssh", :mode => "0700")
89
96
  sudo "mv ~/id_rsa /home/#{deploy_user}/.ssh/"
90
97
  sudo "chown -R #{deploy_user}:rvm /home/#{deploy_user}/.ssh"
91
98
  rescue Exception => e
@@ -93,7 +100,7 @@ module Capistrano::CapStrap
93
100
  end
94
101
  end
95
102
  end
96
- end
103
+ end
97
104
  end
98
105
  end
99
106
  end
@@ -3,6 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe Capistrano::CapStrap::Bootstrap do
4
4
  load_capistrano_recipe(Capistrano::CapStrap::Bootstrap)
5
5
 
6
+ before do
7
+ Capistrano::CLI.ui.stubs(:ask).returns('prompt')
8
+ end
9
+
6
10
  describe "tasks" do
7
11
  it "has a default task" do
8
12
  recipe.must_have_task "bootstrap:default"
@@ -34,44 +38,34 @@ describe Capistrano::CapStrap::Bootstrap do
34
38
  end
35
39
 
36
40
  describe "default variables" do
37
- before do
38
- Capistrano::CLI.ui.stubs(:ask).returns('prompt')
39
- end
40
-
41
- it "prompts for a bootstrap user" do
42
- recipe.fetch(:user).must_equal 'prompt'
43
- end
44
-
45
- it "prompts for a deploy user" do
46
- recipe.fetch(:deploy_user).must_equal 'prompt'
41
+ it "bootstrap user" do
42
+ recipe.fetch(:bootstrap_user).must_equal 'prompt'
47
43
  end
48
44
 
49
- it 'prompts for authorized keys if no path set' do
50
- recipe.fetch(:authorized_keys_file).must_equal 'prompt'
45
+ it "bootstrap user password" do
46
+ recipe.fetch(:bootstrap_password).must_equal 'prompt'
51
47
  end
52
48
 
53
- it "prompts for deploy key location if not set" do
54
- recipe.fetch(:deploy_key_file).must_equal 'prompt'
49
+ it "deploy user" do
50
+ recipe.fetch(:deploy_user).must_equal 'deploy'
55
51
  end
56
52
 
57
- it "packages is empty" do
53
+ it "packages" do
58
54
  recipe.fetch(:packages).must_be_empty
59
55
  end
60
56
  end
61
57
 
62
58
  describe "variables set" do
63
59
  before do
64
- recipe.set(:user, "foo")
65
- recipe.set(:deploy_user, "bar")
66
60
  recipe.set(:known_hosts, "baz")
67
61
  end
68
62
 
69
- it "doesn't prompt for a bootstrap user" do
70
- recipe.fetch(:user).must_equal "foo"
63
+ it "user gets bootstrap_user" do
64
+ recipe.fetch(:user).must_equal recipe.fetch(:bootstrap_user)
71
65
  end
72
66
 
73
- it "doesn't prompt for a deploy user" do
74
- recipe.fetch(:deploy_user).must_equal "bar"
67
+ it "password gets bootstrap_password" do
68
+ recipe.fetch(:password).must_equal recipe.fetch(:bootstrap_password)
75
69
  end
76
70
 
77
71
  it "replaces known_hosts with ones that are set" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-strap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70296715639640 !ruby/object:Gem::Requirement
16
+ requirement: &70359382906800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70296715639640
24
+ version_requirements: *70359382906800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70296715636900 !ruby/object:Gem::Requirement
27
+ requirement: &70359382904140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.12.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70296715636900
35
+ version_requirements: *70359382904140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest-capistrano
38
- requirement: &70296715636080 !ruby/object:Gem::Requirement
38
+ requirement: &70359382903240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.0.8
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70296715636080
46
+ version_requirements: *70359382903240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest-colorize
49
- requirement: &70296715634720 !ruby/object:Gem::Requirement
49
+ requirement: &70359382901880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.0.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70296715634720
57
+ version_requirements: *70359382901880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-minitest
60
- requirement: &70296715634040 !ruby/object:Gem::Requirement
60
+ requirement: &70359382901200 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.5.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70296715634040
68
+ version_requirements: *70359382901200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70296715633040 !ruby/object:Gem::Requirement
71
+ requirement: &70359382900200 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.11.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70296715633040
79
+ version_requirements: *70359382900200
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: vagrant
82
- requirement: &70296715648840 !ruby/object:Gem::Requirement
82
+ requirement: &70359382915520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.0.2
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70296715648840
90
+ version_requirements: *70359382915520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: capistrano
93
- requirement: &70296715647060 !ruby/object:Gem::Requirement
93
+ requirement: &70359382914200 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 2.0.0
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70296715647060
101
+ version_requirements: *70359382914200
102
102
  description: Bootstrap a machine. Install packages, create a deploy user, upload authorized
103
103
  keys and deploy key. Uses RVM to install desired rubies, with patch support.
104
104
  email: