provisionator 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,22 +9,23 @@ module Provisionator
9
9
  end
10
10
 
11
11
  def initialize options={}
12
- options[:instance_type] ||= ENV['P_INSTANCE_TYPE'] || 'm1.small'
13
- options[:no_release] ||= ENV['P_NO_RELEASE']
14
- options[:ec2_region] ||= ENV['P_EC2_REGION'] || 'us-east-1'
15
- options[:ec2_endpoint] ||= ENV['P_EC2_ENDPOINT'] || "ec2.#{options[:ec2_region]}.amazonaws.com"
16
- options[:ami_id] ||= ENV['P_AMI_ID']
17
- options[:ebs_volumes] ||= []
18
- options[:key_name] ||= ENV['P_KEY_NAME']
19
- options[:security_groups] ||= ENV['P_SECURITY_GROUPS'].try(:split, ',')
20
- options[:availability_zones] ||= ENV['P_AVAILABILITY_ZONES'].try(:split, ',') || ["us-east-1a","us-east-1b","us-east-1c"]
21
- options[:instance_count] ||= ENV['P_INSTANCE_COUNT'].try(:to_i) || 1
22
- options[:load_balancer_name] ||= ENV['P_LOAD_BALANCER_NAME']
12
+ @options = options
13
+
14
+ @options[:instance_type] ||= ENV['P_INSTANCE_TYPE'] || 'm1.small'
15
+ @options[:no_release] ||= ENV['P_NO_RELEASE']
16
+ @options[:ec2_region] ||= ENV['P_EC2_REGION'] || 'us-east-1'
17
+ @options[:ec2_endpoint] ||= ENV['P_EC2_ENDPOINT'] || "ec2.#{@options[:ec2_region]}.amazonaws.com"
18
+ @options[:ami_id] ||= ENV['P_AMI_ID']
19
+ @options[:ebs_volumes] ||= []
20
+ @options[:key_name] ||= ENV['P_KEY_NAME']
21
+ @options[:security_groups] ||= ENV['P_SECURITY_GROUPS'].try(:split, ',')
22
+ @options[:availability_zones] ||= ENV['P_AVAILABILITY_ZONES'].try(:split, ',') || ec2.regions[@options[:ec2_region]].availability_zones.map(&:name)
23
+ @options[:instance_count] ||= ENV['P_INSTANCE_COUNT'].try(:to_i) || 1
24
+ @options[:load_balancer_name] ||= ENV['P_LOAD_BALANCER_NAME']
23
25
 
24
- [:app_name, :chef_node_definition, :ami_id, :key_name, :security_groups].each do |option|
26
+ [:app_name, :chef_node, :ami_id, :key_name, :security_groups].each do |option|
25
27
  raise "option ':#{option}' is required" if options[option].nil?
26
28
  end
27
- @options = options
28
29
  end
29
30
 
30
31
  def launch
@@ -72,7 +73,7 @@ module Provisionator
72
73
  puts instance_options.inspect
73
74
  instance = ec2.instances.create(instance_options)
74
75
 
75
- instance.tags['Name'] = "#{@options[:chef_node_definition]}-#{availability_zone.split('').last}-#{instance.id}"
76
+ instance.tags['Name'] = "#{@options[:app_name]}-#{@options[:chef_node]}-#{availability_zone.split('').last}-#{instance.id}"
76
77
  puts "Launching instance '#{instance.id}' in availability_zone '#{availability_zone}...'"
77
78
  instance
78
79
  end
@@ -3,13 +3,12 @@ require 'erb'
3
3
  module Provisionator
4
4
  class Ec2Userdata
5
5
  def initialize options={}
6
- [:app_name, :chef_node_definition, :chef_repo, :config_repo, :app_repo].each do |option|
6
+ [:app_name, :chef_node, :chef_repo, :config_repo, :app_repo].each do |option|
7
7
  raise "option ':#{option}' is required" if options[option].nil?
8
8
  end
9
+ @app_dir = "/home/ubuntu/.#{options[:app_name]}"
10
+ @chef_dir = "#{@app_dir}/#{options[:chef_dir] || 'provision/chef'}"
9
11
 
10
- options[:chef_solo_rb_path] ||= "/home/ubuntu/.#{options[:app_name]}/provision/chef/solo.rb"
11
- options[:chef_node_definition_base_file] ||= "/home/ubuntu/.#{options[:app_name]}/provision/chef/base.json"
12
- options[:chef_node_definition_file] ||= "/home/ubuntu/.#{options[:app_name]}/provision/chef/#{options[:chef_node_definition]}.json"
13
12
  options[:ruby_patch] ||= 'p195'
14
13
  options[:ebs_mount_paths] = ebs_mount_paths(options[:ebs_volumes]) if options[:ebs_volumes]
15
14
  options[:rails_env] ||= 'production'
@@ -45,16 +44,18 @@ exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
45
44
  apt-get update
46
45
  apt-get upgrade -y
47
46
  ntpdate ntp.ubuntu.com
48
- export LC_CTYPE=en_US.UTF-8
49
- export LANG=en_US.UTF-8
50
- unset LC_ALL
51
47
 
52
- echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
53
- echo "UserKnownHostsFile=/dev/null" >> /etc/ssh/ssh_config
54
- echo "gem: --no-ri --no-rdoc" >> /etc/skel/.gemrc
55
- echo "gem: --no-ri --no-rdoc" >> /root/.gemrc
56
- echo "gem: --no-ri --no-rdoc" >> /home/ubuntu/.gemrc
57
- echo "gem: --no-ri --no-rdoc" >> /etc/gemrc
48
+ function add_line_to_file {
49
+ (test -f "$2" && grep "$1" $2) || echo "$1" >> $2
50
+ }
51
+
52
+ add_line_to_file "StrictHostKeyChecking no" /etc/ssh/ssh_config
53
+ add_line_to_file "UserKnownHostsFile=/dev/null" /etc/ssh/ssh_config
54
+
55
+ add_line_to_file "install: --no-document" /etc/skel/.gemrc
56
+ add_line_to_file "install: --no-document" /root/.gemrc
57
+ add_line_to_file "install: --no-document" /home/ubuntu/.gemrc
58
+ add_line_to_file "install: --no-document" /etc/gemrc
58
59
 
59
60
  #install ruby
60
61
  RUBY_PATCH=<%= @options[:ruby_patch] %>
@@ -70,16 +71,19 @@ function install_ruby {
70
71
  }
71
72
  ruby -v | grep 2.0.0$RUBY_PATCH || install_ruby
72
73
 
73
- #install ruby 2.0 compatible version of chef
74
- cd /tmp
75
- curl -o chef.tar.gz -L https://api.github.com/repos/opscode/chef/tarball/CHEF-3935
76
- tar -xvzf chef.tar.gz
77
- cd opscode-chef-634ad58
78
- gem build chef.gemspec
79
- gem install chef-11.4.0.gem
80
- gem install ruby-shadow
81
- mkdir -p /var/cache/chef
82
- chown ubuntu:ubuntu /var/cache/chef
74
+ function install_chef {
75
+ #install ruby 2.0 compatible version of chef
76
+ cd /tmp
77
+ curl -o chef.tar.gz -L https://api.github.com/repos/opscode/chef/tarball/CHEF-3935
78
+ tar -xvzf chef.tar.gz
79
+ cd opscode-chef-634ad58
80
+ gem build chef.gemspec
81
+ gem install chef-11.4.0.gem
82
+ gem install ruby-shadow
83
+ mkdir -p /var/cache/chef
84
+ chown ubuntu:ubuntu /var/cache/chef
85
+ }
86
+ gem list | grep chef || install_chef
83
87
 
84
88
  apt-get install git-core -y
85
89
 
@@ -104,8 +108,8 @@ su ubuntu -c 'git clone <%= @options[:app_repo] %> /home/ubuntu/.<%= @options[:a
104
108
  ln -s /home/ubuntu/.config/$APP_NAME/<%= @options[:rails_env] %>/app.sh /etc/profile.d/$APP_NAME.sh
105
109
 
106
110
  . /etc/profile.d/$APP_NAME.sh
107
-
108
- chef-solo -c <%= @options[:chef_solo_rb_path] %> -o recipe[base] -l debug
111
+ echo <%= @options[:chef_node] %> > /home/ubuntu/.chef_node
112
+ chown ubuntu:ubuntu /home/ubuntu/.chef_node
109
113
 
110
114
  <% unless @options[:no_release] %>
111
115
  mkdir -p $APP_PATH $APP_PATH/releases $APP_PATH/shared $APP_PATH/shared/system $APP_PATH/shared/log $APP_PATH/shared/pids $APP_PATH/shared/sockets
@@ -120,13 +124,16 @@ chef-solo -c <%= @options[:chef_solo_rb_path] %> -o recipe[base] -l debug
120
124
  ln -s $APP_PATH/shared/log $APP_PATH/current/log
121
125
  mkdir $APP_PATH/current/tmp
122
126
  ln -s $APP_PATH/shared/pids/ $APP_PATH/current/tmp/pids
127
+
128
+ <% if @options[:chef_pre_bundle] %>
129
+ chef-solo -c <%= "#{@chef_dir}/solo.rb" %> -j <%= "#{@chef_dir}/#{@options[:chef_pre_bundle]}.json" %> -l debug
130
+ <% end %>
131
+
123
132
  bundle install --gemfile $APP_PATH/releases/20130516070710/Gemfile --path $APP_PATH/shared/bundle --deployment --without development test
124
133
  chown -R ubuntu:ubuntu /u/
125
134
  <% end %>
126
135
 
127
- echo <%= @options[:chef_node_definition] %> > /home/ubuntu/.chef_node_definition
128
- chown ubuntu:ubuntu /home/ubuntu/.chef_node_definition
129
- chef-solo -c <%= @options[:chef_solo_rb_path] %> -j <%= @options[:chef_node_definition_file] %> -l debug
136
+ chef-solo -c <%= "#{@chef_dir}/solo.rb" %> -j <%= "#{@chef_dir}/#{@options[:chef_node]}.json" %> -l debug
130
137
  TEMPLATE
131
138
  end
132
139
  end
@@ -1,3 +1,3 @@
1
1
  module Provisionator
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/pre_bootstrap.txt ADDED
@@ -0,0 +1,44 @@
1
+ #!/bin/bash -xe
2
+
3
+ apt-get update
4
+ apt-get upgrade -y
5
+ ntpdate ntp.ubuntu.com
6
+
7
+ RUBY_PATCH=p195
8
+ function install_ruby {
9
+ apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev
10
+ cd /tmp
11
+ wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-$RUBY_PATCH.tar.gz
12
+ tar -xvzf ruby-2.0.0-$RUBY_PATCH.tar.gz
13
+ cd ruby-2.0.0-$RUBY_PATCH/
14
+ ./configure --prefix=/usr/local
15
+ make
16
+ make install
17
+ }
18
+ ruby -v | grep 2.0.0$RUBY_PATCH || install_ruby
19
+
20
+ function install_chef {
21
+ #install ruby 2.0 compatible version of chef
22
+ cd /tmp
23
+ curl -o chef.tar.gz -L https://api.github.com/repos/opscode/chef/tarball/CHEF-3935
24
+ tar -xvzf chef.tar.gz
25
+ cd opscode-chef-634ad58
26
+ gem build chef.gemspec
27
+ gem install chef-11.4.0.gem
28
+ gem install ruby-shadow
29
+ mkdir -p /var/cache/chef
30
+ chown ubuntu:ubuntu /var/cache/chef
31
+ }
32
+ gem list | grep chef || install_chef
33
+
34
+ function add_line_to_file {
35
+ (test -f "$2" && grep "$1" $2) || echo "$1" >> $2
36
+ }
37
+
38
+ add_line_to_file "StrictHostKeyChecking no" /etc/ssh/ssh_config
39
+ add_line_to_file "UserKnownHostsFile=/dev/null" /etc/ssh/ssh_config
40
+
41
+ add_line_to_file "install: --no-document" /etc/skel/.gemrc
42
+ add_line_to_file "install: --no-document" /root/.gemrc
43
+ add_line_to_file "install: --no-document" /home/ubuntu/.gemrc
44
+ add_line_to_file "install: --no-document" /etc/gemrc
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: provisionator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-05-28 00:00:00.000000000 Z
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -80,6 +80,7 @@ files:
80
80
  - lib/provisionator/ec2_launcher.rb
81
81
  - lib/provisionator/ec2_userdata.rb
82
82
  - lib/provisionator/version.rb
83
+ - pre_bootstrap.txt
83
84
  - provisionator.gemspec
84
85
  homepage: ''
85
86
  licenses:
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  version: '0'
97
98
  segments:
98
99
  - 0
99
- hash: -3090150088130755826
100
+ hash: 4334713208859455962
100
101
  required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  none: false
102
103
  requirements:
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  segments:
107
108
  - 0
108
- hash: -3090150088130755826
109
+ hash: 4334713208859455962
109
110
  requirements: []
110
111
  rubyforge_project:
111
112
  rubygems_version: 1.8.23