stemcell 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stemcell (0.5.0)
5
+ aws-creds (~> 0.2.2)
6
+ aws-sdk (~> 1.9)
7
+ chef (~> 11.4.0)
8
+ colored (~> 1.2)
9
+ json (~> 1.7.7)
10
+ net-ssh (~> 2.6)
11
+ trollop (~> 2.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ aws-creds (0.2.2)
17
+ trollop (~> 2.0)
18
+ aws-sdk (1.21.0)
19
+ json (~> 1.4)
20
+ nokogiri (>= 1.4.4, < 1.6.0)
21
+ uuidtools (~> 2.1)
22
+ chef (11.4.4)
23
+ erubis
24
+ highline (>= 1.6.9)
25
+ json (>= 1.4.4, <= 1.7.7)
26
+ mixlib-authentication (>= 1.3.0)
27
+ mixlib-cli (~> 1.3.0)
28
+ mixlib-config (>= 1.1.2)
29
+ mixlib-log (>= 1.3.0)
30
+ mixlib-shellout
31
+ net-ssh (~> 2.6)
32
+ net-ssh-multi (~> 1.1.0)
33
+ ohai (>= 0.6.0)
34
+ rest-client (>= 1.0.4, < 1.7.0)
35
+ yajl-ruby (~> 1.1)
36
+ colored (1.2)
37
+ erubis (2.7.0)
38
+ highline (1.6.19)
39
+ ipaddress (0.8.0)
40
+ json (1.7.7)
41
+ mime-types (1.23)
42
+ mixlib-authentication (1.3.0)
43
+ mixlib-log
44
+ mixlib-cli (1.3.0)
45
+ mixlib-config (1.1.2)
46
+ mixlib-log (1.6.0)
47
+ mixlib-shellout (1.1.0)
48
+ net-ssh (2.7.0)
49
+ net-ssh-gateway (1.2.0)
50
+ net-ssh (>= 2.6.5)
51
+ net-ssh-multi (1.1)
52
+ net-ssh (>= 2.1.4)
53
+ net-ssh-gateway (>= 0.99.0)
54
+ nokogiri (1.5.9)
55
+ ohai (6.16.0)
56
+ ipaddress
57
+ mixlib-cli
58
+ mixlib-config
59
+ mixlib-log
60
+ mixlib-shellout
61
+ systemu
62
+ yajl-ruby
63
+ rest-client (1.6.7)
64
+ mime-types (>= 1.16)
65
+ systemu (2.5.2)
66
+ trollop (2.0)
67
+ uuidtools (2.1.4)
68
+ yajl-ruby (1.1.0)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ stemcell!
data/examples/stemcellrc CHANGED
@@ -13,6 +13,9 @@ export KEY_NAME=your_aws_ssh_key_name
13
13
  # http://docs.opscode.com/chef/essentials_data_bags.html#secret-keys
14
14
  export CHEF_DATA_BAG_SECRET=/path/to/encrypted/data/bag/secret
15
15
 
16
+ # Chef environment
17
+ CHEF_ENVIRONMENT=default
18
+
16
19
  # This expects a standard opscode mono-repo, like the one
17
20
  # modeled here: https://github.com/opscode/chef-repo
18
21
  export LOCAL_CHEF_ROOT=/path/to/your/local/chef/repository
@@ -21,9 +24,12 @@ export LOCAL_CHEF_ROOT=/path/to/your/local/chef/repository
21
24
  # local chef root; we use a github enterprise server
22
25
  export GIT_ORIGIN=git@git.airbnb.com:airbnb/chef.git
23
26
 
27
+ # The git branch to use by default
28
+ export GIT_BRANCH=production
29
+
24
30
  # The git key is an SSH key which has pull permissions on
25
31
  # the GIT_ORIGIN repo
26
32
  export GIT_KEY=/path/to/chef/deploy/key
27
33
 
28
- # Which security group should you launch
29
- export SECURITY_GROUP=default
34
+ # Which security groups should you launch
35
+ export SECURITY_GROUPS=default
@@ -38,6 +38,8 @@ module Stemcell
38
38
  'git_origin',
39
39
  'key_name',
40
40
  'instance_type',
41
+ 'instance_hostname',
42
+ 'instance_domain_name',
41
43
  'image_id',
42
44
  'availability_zone',
43
45
  'count',
@@ -87,7 +89,7 @@ module Stemcell
87
89
  tags = {
88
90
  'Name' => "#{opts['chef_role']}-#{opts['chef_environment']}",
89
91
  'Group' => "#{opts['chef_role']}-#{opts['chef_environment']}",
90
- 'created_by' => ENV['USER'],
92
+ 'created_by' => opts.fetch('user', ENV['USER']),
91
93
  'stemcell' => VERSION,
92
94
  }
93
95
  tags.merge!(opts['tags']) if opts['tags']
@@ -96,7 +98,6 @@ module Stemcell
96
98
  launch_options = {
97
99
  :image_id => opts['image_id'],
98
100
  :security_groups => opts['security_groups'],
99
- :user_data => opts['user_data'],
100
101
  :instance_type => opts['instance_type'],
101
102
  :key_name => opts['key_name'],
102
103
  :count => opts['count'],
@@ -142,19 +143,22 @@ module Stemcell
142
143
 
143
144
  # generate user data script to bootstrap instance, include in launch
144
145
  # options UNLESS we have manually set the user-data (ie. for ec2admin)
145
- launch_options[:user_data] ||= render_template(opts)
146
+ launch_options[:user_data] = opts.fetch('user_data', render_template(opts))
146
147
 
147
148
  # launch instances
148
149
  instances = do_launch(launch_options)
149
150
 
150
- # wait for aws to report instance stats
151
- wait(instances)
152
-
153
151
  # set tags on all instances launched
154
152
  set_tags(instances, tags)
153
+ @log.info "sent ec2 api requests successfully"
154
+
155
+ # wait for aws to report instance stats
156
+ if opts.fetch('wait', true)
157
+ wait(instances)
158
+ print_run_info(instances)
159
+ @log.info "launched instances successfully"
160
+ end
155
161
 
156
- print_run_info(instances)
157
- @log.info "launched instances successfully"
158
162
  return instances
159
163
  end
160
164
 
@@ -9,7 +9,9 @@ module Stemcell
9
9
  DEFAULT_OPTIONS = {
10
10
  'chef_environment' => 'production',
11
11
  'git_branch' => 'production',
12
- 'count' => 1
12
+ 'count' => 1,
13
+ 'instance_hostname' => '',
14
+ 'instance_domain_name' => '',
13
15
  }
14
16
 
15
17
  # Search for instance metadata in the following role attributes, with
@@ -148,6 +148,18 @@ module Stemcell
148
148
  :type => String,
149
149
  :env => 'GIT_KEY'
150
150
  },
151
+ {
152
+ :name => 'instance_hostname',
153
+ :desc => "the hostname of new instances; defaults to the instance id if omitted",
154
+ :type => String,
155
+ :env => 'INSTANCE_HOSTNAME'
156
+ },
157
+ {
158
+ :name => 'instance_domain_name',
159
+ :desc => "the domain part of the FQDN of created instances (like airbnb.com)",
160
+ :type => String,
161
+ :env => 'INSTANCE_DOMAIN_NAME'
162
+ },
151
163
  {
152
164
  :name => 'count',
153
165
  :desc => "number of instances to launch",
@@ -65,8 +65,10 @@ role=<%= opts['chef_role'] %>
65
65
  environment=<%= opts['chef_environment'] %>
66
66
  origin=<%= opts['git_origin'] %>
67
67
  branch=<%= opts['git_branch'] %>
68
- git_key='<%= opts["git_key"] %>'
68
+ git_key='<%= opts['git_key'] %>'
69
69
  data_bag_secret='<%= opts["chef_data_bag_secret"] %>'
70
+ hostname='<%= opts['instance_hostname'] %>'
71
+ domain_name='<%= opts['instance_domain_name'] %>'
70
72
 
71
73
 
72
74
  ##
@@ -89,11 +91,25 @@ install() {
89
91
  }
90
92
 
91
93
 
92
- get_instance_id() {
93
- instance_id=`curl --retry 5 --retry-delay 5 169.254.169.254/latest/meta-data/instance-id` 1>&2
94
- echo instance_id is $instance_id
95
- }
94
+ set_hostname() {
95
+ instance_id=`curl --silent --retry 5 --retry-delay 5 169.254.169.254/latest/meta-data/instance-id` 1>&2
96
+ local_ip=`curl --silent --retry 5 --retry-delay 5 169.254.169.254/latest/meta-data/local-ipv4` 1>&2
97
+
98
+ if [ "z$hostname" == "z" ]; then
99
+ hostname=$instance_id
100
+ fi
101
+ if [ "z${domain_name}" == "z" ]; then
102
+ domain_name="localdomain"
103
+ fi
96
104
 
105
+ fqdn="${hostname}.${domain_name}"
106
+ echo "setting hostname to $hostname ($fqdn)"
107
+ echo $hostname > /etc/hostname
108
+ hostname -F /etc/hostname
109
+
110
+ # allow a proper `hostname -f` to return something
111
+ echo "$local_ip $fqdn $hostname" >> /etc/hosts
112
+ }
97
113
 
98
114
  install_chef() {
99
115
  if ! which chef-solo > /dev/null ; then
@@ -125,7 +141,10 @@ update_repo() {
125
141
 
126
142
 
127
143
  configure_chef() {
128
- echo "saving current branch ($branch), role ($role), and environment ($environment)"
144
+ echo "saving current origin ($origin), branch ($branch), role ($role), and environment ($environment)"
145
+ echo "$origin" > $originfile
146
+ chmod 644 $originfile
147
+
129
148
  echo "$branch" > $branchfile
130
149
  chmod 644 $branchfile
131
150
 
@@ -221,6 +240,7 @@ keyfile=${chef_dir}/git_key
221
240
  envfile=${chef_dir}/environment
222
241
  rolefile=${chef_dir}/role
223
242
  branchfile=${chef_dir}/branch
243
+ originfile=${chef_dir}/origin
224
244
  git_wrapper=${chef_dir}/git_wrapper
225
245
 
226
246
  echo "starting chef bootstrapping..."
@@ -228,7 +248,7 @@ mkdir -p ${chef_dir}
228
248
  update
229
249
  install curl
230
250
  install git
231
- get_instance_id
251
+ set_hostname
232
252
  install_chef
233
253
  update_repo
234
254
  configure_chef
@@ -1,3 +1,3 @@
1
1
  module Stemcell
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
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.4.4
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-10-21 00:00:00.000000000 Z
15
+ date: 2013-11-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: aws-sdk
@@ -138,6 +138,7 @@ extra_rdoc_files: []
138
138
  files:
139
139
  - .gitignore
140
140
  - Gemfile
141
+ - Gemfile.lock
141
142
  - LICENSE.txt
142
143
  - README.md
143
144
  - Rakefile