stemcell 0.0.3 → 0.0.4

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.
data/bin/stem CHANGED
@@ -16,7 +16,7 @@ END_OF_BANNER
16
16
  "aws access key",
17
17
  :type => String,
18
18
  :default => ENV['AWS_ACCESS_KEY']
19
- )
19
+ )
20
20
 
21
21
  opt('aws_secret_key',
22
22
  "aws secret key",
@@ -24,18 +24,6 @@ END_OF_BANNER
24
24
  :default => ENV['AWS_SECRET_KEY']
25
25
  )
26
26
 
27
- opt('chef_validation_key_name',
28
- 'chef validation key name',
29
- :type => String,
30
- :default => ENV['CHEF_VALIDATION_KEY_NAME'],
31
- )
32
-
33
- opt('chef_validation_key',
34
- 'chef validation key path',
35
- :type => String,
36
- :default => ENV['CHEF_VALIDATION_KEY'],
37
- )
38
-
39
27
  opt('chef_data_bag_secret',
40
28
  'path to chef data bag encryption secret',
41
29
  :type => String,
@@ -48,10 +36,22 @@ END_OF_BANNER
48
36
  :default => ENV['CHEF_ROLE'],
49
37
  )
50
38
 
51
- opt('chef_environment',
52
- 'chef environment of instance to be launched',
39
+ opt('git_branch',
40
+ 'git branch to run off',
41
+ :type => String,
42
+ :default => ENV['GIT_BRANCH'],
43
+ )
44
+
45
+ opt('git_key',
46
+ 'git key to use',
47
+ :type => String,
48
+ :default => ENV['GIT_KEY'],
49
+ )
50
+
51
+ opt('git_origin',
52
+ 'git origin to use',
53
53
  :type => String,
54
- :default => ENV['CHEF_ENVIRONMENT'],
54
+ :default => ENV['GIT_ORIGIN'],
55
55
  )
56
56
 
57
57
  opt('key_name',
@@ -95,15 +95,15 @@ end
95
95
  required_parameters = [
96
96
  'aws_access_key',
97
97
  'aws_secret_key',
98
- 'chef_validation_key_name',
99
- 'chef_validation_key',
100
98
  'chef_role',
101
- 'chef_environment',
99
+ 'git_branch',
100
+ 'git_key',
101
+ 'git_origin',
102
102
  'key_name',
103
103
  ]
104
104
 
105
105
  required_parameters.each do |arg|
106
- raise ArgumentError, "--#{arg} needs to be specified on the commandline or set \
106
+ raise ArgumentError, "--#{arg.gsub('_','-')} needs to be specified on the commandline or set \
107
107
  by the #{arg.upcase.gsub('-','_')} environment variable" if
108
108
  options[arg].nil? or ! options[arg]
109
109
  end
@@ -2,7 +2,8 @@
2
2
  #
3
3
  # This script will bootstrap and run chef
4
4
  #
5
- # You need to specify a run_list, environment, and validator key info below
5
+ # You need to specify a role, origin, git_key, branch name, and data
6
+ # bag secret info below
6
7
  #
7
8
  # Martin Rhoads
8
9
 
@@ -10,6 +11,13 @@
10
11
  set -o pipefail
11
12
 
12
13
 
14
+ # ensure we were called by root
15
+ if [ $UID != 0 ]; then
16
+ echo "this script needs to be run as root. exiting..."
17
+ exit 1
18
+ fi
19
+
20
+
13
21
  # redirect stdout to /var/log/init
14
22
  exec > /var/log/init
15
23
 
@@ -22,11 +30,13 @@ exec 2> /var/log/init.err
22
30
  ##
23
31
 
24
32
 
25
- run_list=role[<%= @chef_role %>]
26
- environment=<%= @chef_environment %>
27
- validator_name=<%= @chef_validation_key_name %>
28
- validator_value="<%= @chef_validation_key_value %>"
29
- data_bag_secret="<%= @chef_data_bag_secret %>"
33
+ repo_dir=/etc/chef/src
34
+ role=<%= @chef_role %>
35
+ origin=<%= @git_origin %>
36
+ branch=<%= @git_branch %>
37
+ git_key='<%= @git_key_contents %>'
38
+ data_bag_secret='<%= @chef_data_bag_secret %>'
39
+
30
40
 
31
41
  ##
32
42
  ## common function
@@ -54,40 +64,77 @@ get_instance_id() {
54
64
  }
55
65
 
56
66
 
67
+ install_chef() {
68
+ if ! which chef-solo > /dev/null ; then
69
+ echo installing chef via omnibus...
70
+ curl -L --silent https://www.opscode.com/chef/install.sh | sudo bash -s -- -v 11.2.0 1>&2
71
+ else
72
+ echo chef is already installed
73
+ fi
74
+ }
75
+
76
+
57
77
  configure_chef() {
58
78
  echo configuring chef...
59
79
  mkdir -p /etc/chef
60
- echo -e "$validator_value" > /etc/chef/validation.pem
61
- cat<<EOF>/etc/chef/client.rb
80
+ cat<<EOF>/etc/chef/solo.json
81
+ {
82
+ "run_list": "role[$role]"
83
+ }
84
+ EOF
85
+
86
+ cat<<EOF>/etc/chef/solo.rb
62
87
  log_level :info
63
88
  log_location STDOUT
64
- chef_server_url "https://api.opscode.com/organizations/airbnb"
65
- validation_client_name "$validator_name"
66
- node_name "$instance_id"
89
+ cookbook_path "$repo_dir/cookbooks"
90
+ role_path "$repo_dir/roles"
91
+ data_bag_path "$repo_dir/data_bags"
92
+ json_attribs '/etc/chef/solo.json'
67
93
  EOF
68
94
  echo -e "$data_bag_secret" > /etc/chef/encrypted_data_bag_secret
69
95
  echo chef configured
70
96
  }
71
97
 
72
98
 
73
- install_chef() {
74
- if ! which chef-client > /dev/null ; then
75
- echo installing chef via omnibus...
76
- curl -L --silent https://www.opscode.com/chef/install.sh | sudo bash 1>&2
77
- curl -L --silent https://www.opscode.com/chef/install.sh | sudo bash -s -- -v 11.2.0 1>&2
78
- else
79
- echo chef is already installed
99
+ update_repo() {
100
+ git_wrapper=/etc/chef/git_wrapper
101
+ local keyfile=/etc/chef/git_key
102
+ if [ -d $repo_dir ]; then
103
+ echo updating source...
104
+ (cd $repo_dir && GIT_SSH=$git_wrapper git pull && git reset --hard && git clean -fdx)
105
+ else
106
+ echo -e "$git_key" > $keyfile
107
+ chmod 0400 $keyfile
108
+ echo "ssh -i $keyfile -o StrictHostKeyChecking=no \$1 \$2" > $git_wrapper
109
+ chmod 0500 $git_wrapper
110
+ echo downloading cookbook repo...
111
+ GIT_SSH=$git_wrapper git clone --branch $branch --depth 1 $origin $repo_dir
80
112
  fi
113
+ echo done updating code
114
+ }
115
+
116
+
117
+ configure_converger() {
118
+ cat<<EOF>/usr/local/bin/converge
119
+ #!/bin/bash -e
120
+
121
+ cd $repo_dir
122
+ GIT_SSH=$git_wrapper git pull
123
+ git reset --hard
124
+ git clean -fdx
125
+ chef-solo
126
+ EOF
127
+ chmod 0544 /usr/local/bin/converge
81
128
  }
82
129
 
83
130
 
84
131
  configure_chef_daemon() {
85
- cat<<EOF>/etc/init/chef-client.conf
86
- description "chef-client"
132
+ cat<<EOF>/etc/init/chef-solo.conf
133
+ description "chef-solo"
87
134
  author "Martin Rhoads"
88
135
  start on networking
89
136
  script
90
- chef-client --interval 300 --splay 150 | logger -t chef-client 2>&1
137
+ chef-solo --interval 600 --splay 600 | logger -t chef-solo 2>&1
91
138
  end script
92
139
  respawn
93
140
  EOF
@@ -95,14 +142,14 @@ EOF
95
142
 
96
143
 
97
144
  run_chef() {
98
- echo running chef-client...
99
- chef-client --environment $environment --override-runlist $run_list 1>&2
100
- echo done running chef-client
145
+ echo running chef-solo...
146
+ chef-solo 1>&2
147
+ echo done running chef-solo
101
148
  }
102
149
 
103
150
 
104
151
  start_chef_daemon() {
105
- start chef-client
152
+ start chef-solo
106
153
  }
107
154
 
108
155
 
@@ -114,12 +161,15 @@ start_chef_daemon() {
114
161
  echo starting chef bootstrapping...
115
162
  update
116
163
  install curl
164
+ install git
117
165
  get_instance_id
118
- configure_chef
119
166
  install_chef
167
+ configure_chef
168
+ update_repo
169
+ configure_converger
120
170
  run_chef
121
171
  configure_chef_daemon
122
- start_chef_daemon
172
+ # start_chef_daemon
123
173
 
124
174
 
125
175
  ##
@@ -1,3 +1,3 @@
1
1
  module Stemcell
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/stemcell.rb CHANGED
@@ -11,10 +11,10 @@ module Stemcell
11
11
  @log.debug "opts are #{opts.inspect}"
12
12
  ['aws_access_key',
13
13
  'aws_secret_key',
14
- 'chef_validation_key_name',
15
- 'chef_validation_key',
16
14
  'chef_role',
17
- 'chef_environment',
15
+ 'git_branch',
16
+ 'git_key',
17
+ 'git_origin',
18
18
  'key_name',
19
19
  ].each do |req|
20
20
  raise ArgumentError, "missing required param #{req}" unless opts[req]
@@ -30,11 +30,11 @@ module Stemcell
30
30
  @start_time = Time.new
31
31
 
32
32
  begin
33
- @chef_validation_key_value = File.read(@chef_validation_key)
33
+ @git_key_contents = File.read(@git_key)
34
34
  rescue Object => e
35
35
  # TODO(mkr): we may want to do something better here
36
- @chef_validation_key_value = @chef_validation_key
37
- # raise "\ncould not open specified key #{@chef_validation_key}:\n#{e.inspect}#{e.backtrace}"
36
+ @git_key_contents = @chef_validation_key
37
+ # raise "\ncould not open specified key #{@git_key}:\n#{e.inspect}#{e.backtrace}"
38
38
  end
39
39
 
40
40
  if opts['chef_data_bag_secret']
@@ -50,7 +50,6 @@ module Stemcell
50
50
  AWS.config({:access_key_id => @aws_access_key, :secret_access_key => @aws_secret_key})
51
51
  @ec2 = AWS::EC2.new(:ec2_endpoint => @ec2_url)
52
52
  @ec2_region = @ec2.regions[@region]
53
-
54
53
  @user_data = render_template
55
54
  end
56
55
 
@@ -59,16 +58,11 @@ module Stemcell
59
58
  instances = do_launch(opts)
60
59
  wait(instances)
61
60
  print_run_info(instances)
62
- print_config_info
63
61
  return instances
64
62
  end
65
63
 
66
64
  private
67
65
 
68
- def print_config_info
69
- puts "install logs will be in /var/log/init and /var/log/init.err"
70
- end
71
-
72
66
  def print_run_info(instances)
73
67
  puts "here is the info for what's launched:"
74
68
  instances.each do |instance|
@@ -76,6 +70,7 @@ module Stemcell
76
70
  puts "\tpublic ip: #{instance.public_ip_address}"
77
71
  puts
78
72
  end
73
+ puts "install logs will be in /var/log/init and /var/log/init.err"
79
74
  end
80
75
 
81
76
  def wait(instances)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stemcell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop