public
Rubygem
Description: A Capistrano extension for managing and running your app on Amazon EC2.
Clone URL: git://github.com/jnewland/capsize.git
Search Repo:
make the setup process interactive
jnewland (author)
Thu Apr 10 06:41:36 -0700 2008
commit  ea0471f9a749dc711479538f2b09ea275f767db8
tree    3f491eb0862b1f65015a13689ed488beb2999837
parent  bdc77333629324c1aec68df9759b9b5ed2757cdb
...
7
8
9
10
11
12
13
...
7
8
9
 
10
11
12
0
@@ -7,7 +7,6 @@
0
 config/requirements.rb
0
 examples/capsize.yml.template
0
 examples/deploy.rb
0
-examples/secure.yml.template
0
 lib/capsize.rb
0
 lib/capsize/capsize.rb
0
 lib/capsize/configuration.rb
...
412
413
414
415
 
416
417
418
...
412
413
414
 
415
416
417
418
0
@@ -412,7 +412,7 @@
0
 
0
         begin
0
           capsize_ec2.authorize_ingress({:group_name => capsize.get(:group_name), :from_port => capsize.get(:from_port), :to_port => capsize.get(:to_port)})
0
- puts "Firewall ingress granted for :group_name => #{capsize.get(:group_name)} on ports #{capsize.get(:from_port)} to #{capsize.get(:to_port)}"
0
+ puts "Firewall ingress granted for #{capsize.get(:group_name)} on ports #{capsize.get(:from_port)} to #{capsize.get(:to_port)}"
0
         rescue EC2::InvalidPermissionDuplicate => e
0
           puts "The firewall ingress rule you specified for group name \"#{capsize.get(:group_name)}\" on ports #{capsize.get(:from_port)} to #{capsize.get(:to_port)} was already set (EC2::InvalidPermissionDuplicate)."
0
           # Don't re-raise this exception
...
22
23
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
 
56
57
 
 
 
58
59
 
60
61
 
 
 
 
62
63
64
65
 
66
67
68
 
69
70
71
72
 
 
73
74
75
 
 
 
76
77
78
 
 
79
80
 
 
81
82
83
84
85
86
87
 
 
88
89
90
 
 
 
 
91
92
 
93
94
 
 
 
 
 
 
 
95
96
 
 
 
 
 
97
98
99
100
 
101
102
 
103
104
105
106
107
108
 
109
110
111
112
113
 
114
115
 
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
134
135
136
 
137
138
139
 
140
141
 
142
143
144
145
146
147
148
149
150
151
152
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
22
23
24
 
 
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
40
41
42
 
 
 
 
 
 
 
43
 
 
 
 
44
45
46
 
47
48
49
50
 
51
52
 
53
54
55
56
57
 
 
 
58
59
 
 
60
61
 
62
 
63
64
65
 
 
66
67
68
69
 
 
70
71
72
 
73
74
75
 
 
 
 
 
 
76
77
78
 
 
79
80
81
82
83
 
84
85
 
86
87
88
89
90
91
92
93
 
94
95
96
97
98
99
 
 
 
100
101
 
102
103
 
 
 
 
 
104
105
 
 
 
 
106
107
 
108
109
 
 
 
 
 
 
 
 
 
 
110
111
112
 
 
113
 
114
115
116
 
117
118
119
 
120
121
 
122
123
 
 
 
 
124
125
126
127
128
129
...
130
131
132
 
 
133
134
 
 
 
135
136
 
 
137
 
 
138
139
140
0
@@ -22,8 +22,7 @@
0
       - Create :capsize_config_dir
0
       - Create :capsize_secure_config_dir
0
       - Copy capsize.yml.template to :capsize_config_dir/capsize.yml unless it already exists
0
- - Copy secure.yml.template to :capsize_secure_config_dir/secure.yml unless it already exists
0
- - Instruct user to add AWS keys to secure.yml or capsize.yml
0
+ - Automatically generate :capsize_secure_config_dir/secure.yml unless it already exists
0
       - Instruct user to test configuration with "cap ec2:images:describe"
0
       - Instruct user how to create a new keypair
0
       - Instruct user how to setup a new security group.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
@@ -41,109 +40,87 @@
0
         end
0
 
0
         # copy the standard config file template, unless the dest file alread exists
0
- unless File.exists?("#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}")
0
- FileUtils.cp("#{fetch(:capsize_examples_dir)}/capsize.yml.template", "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}", :verbose => true)
0
- else
0
- puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}"
0
- end
0
-
0
- # copy the secure config file template, unless the dest file alread exists
0
         unless File.exists?("#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}")
0
- FileUtils.cp("#{fetch(:capsize_examples_dir)}/secure.yml.template", "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}", :verbose => true)
0
- else
0
- puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
- end
0
+ puts "Please enter your EC2 account information."
0
+ puts "We'll then write it to a config file at #{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
 
0
- message = <<-MESSAGE
0
+ require "yaml"
0
+ set :aws_access_key_id, proc { Capistrano::CLI.ui.ask("AWS Access Key ID : ") }
0
+ set :aws_secret_access_key, proc { Capistrano::CLI.ui.ask("AWS Secret Access Key : ") }
0
 
0
- Capsize Config Setup Instructions:
0
+ yaml = {}
0
 
0
- Step 1:
0
+ # Populate production element
0
+ yaml['common'] = {}
0
+ yaml['common']['aws_access_key_id'] = aws_access_key_id
0
+ yaml['common']['aws_secret_access_key'] = aws_secret_access_key
0
 
0
- Your Capsize config files have been created. You should now add your
0
- Amazon Web Services 'Access Key ID' and 'Secret Access Key' to the secure.yml
0
- file we created for you in your config dir.
0
+ yaml = YAML::dump(yaml).split("\n").collect { |line| line == "common: " ? line += "&common" : line }.join("\n")
0
 
0
- Once you have done this you should be able to test out your ability to use
0
- Capsize by running the following command:
0
+ env_config =<<EOF
0
 
0
- RUN:
0
 
0
- cap ec2:setup:check
0
+development:
0
+ <<: *common
0
 
0
- If you receive a congratulatory response then you are ready to continue using Capsize.
0
- If you receive an Exception message please use that to help you troubleshoot further.
0
+ # Uncomment and I only apply to the dev environment
0
+ # or overwrite a common value
0
+ #foo: 'bar'
0
 
0
- Once you have succesfully tested your connection to EC2, please continue with the next
0
- steps...
0
+test:
0
+ <<: *common
0
 
0
- Step 2 : Create a new key pair (highly recommended but optional):
0
+staging:
0
+ <<: *common
0
 
0
- Once you have completed the first step successfully, the next recommended step
0
- is to create a an Amazon EC2 keypair that is specifically tailored for use
0
- with your application. This keypair will be used to allow you to create new
0
- EC2 instances that can accept public key authentication for passwordless login.
0
- By default the keypair created will be named the same as the :application setting
0
- in your deploy.rb file (run 'cap -e ec2:keypairs:create' for more info.).
0
+production:
0
+ <<: *common
0
 
0
- Setting up a new keypair in this fashion does not preclude you from using a
0
- different keypair of your choice in the future.
0
+ # Uncomment and I only apply to the production environment
0
+ # or overwrite a common value
0
+ #foo: 'baz'
0
+EOF
0
 
0
- Run the following command to create a new keypair for your application:
0
+ yaml += env_config
0
 
0
- RUN:
0
+ File.open("#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}", 'w') do |file|
0
+ file.write(yaml)
0
+ end
0
+ File.chmod 0664, "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
+ else
0
+ puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}"
0
+ end
0
 
0
- cap ec2:keypairs:create
0
+ unless File.exists?("#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}")
0
+ FileUtils.cp("#{fetch(:capsize_examples_dir)}/capsize.yml.template", "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}", :verbose => true)
0
+ else
0
+ puts "Warning : The following file was not copied over since it already exists: " + "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}"
0
+ end
0
 
0
- WARNING:
0
- Once you successfully create your keypair, guard your new private key carefully
0
- as it allows the holder of that key to access EC2 instances started using that key.
0
+ check
0
 
0
- Step 3 : Create a new security group + open ports (highly recommended but optional):
0
+ ec2.keypairs.create
0
 
0
- Security groups contain a set of firewall rules that apply to any
0
- EC2 instance started that is configured to use that specific security
0
- group. Running the command below will create a new security group
0
- that is named after your :application setting in deploy.rb which you can
0
- use instead of the 'default' security group that EC2 creates for you.
0
+ ec2.security_groups.create_with_standard_ports
0
 
0
- This command will also open firewall ports for your new group that match the standard
0
- web ports most applications need (22-SSH, 80-HTTP, 443-HTTPS). If this is
0
- not suitable for you then please read the docs for 'ec2:security_groups:create'
0
- and 'ec2:security_groups:authorize_ingress'
0
+ message = <<-MESSAGE
0
 
0
- RUN:
0
+ Next up: Pick an Amazon Machine Image and Run it!
0
 
0
- cap ec2:security_groups:create_with_standard_ports
0
-
0
- -------------------------------------------------------------------------------
0
- At this point your configuration is complete and we can get down to running and
0
- using Amazon EC2 instances. In most cases, you should not have to repeat any
0
- of the previous commands again.
0
- -------------------------------------------------------------------------------
0
-
0
- Step 4 : Pick an Amazon Machine Image and Run it!
0
-
0
           Now you need to select an Amazon EC2 image ID that you want to start as a new
0
           instance. The easiest way to do that is to get a list of available images from EC2.
0
 
0
- RUN (pick one):
0
-
0
             # Show ALL registered images
0
- cap ec2:images:describe
0
+ cap ec2:images:show
0
 
0
             # Show MY registered images
0
- cap ec2:images:describe OWNER_ID='self'
0
+ cap ec2:images:show OWNER_ID='self'
0
 
0
             # Show the AMAZON registered images
0
- cap ec2:images:describe OWNER_ID='amazon'
0
+ cap ec2:images:show OWNER_ID='amazon'
0
 
0
- Select an 'imageId' from the results, it will look like: 'ami-2bb65342'
0
+ Select an 'imageId' from the results, and run it:
0
 
0
- Now lets start it:
0
-
0
- RUN :
0
-
0
             cap ec2:instances:run IMAGE_ID='ami-2bb65342'
0
 
0
           You should see some progress information scroll by and finally you should see
0
0
0
0
@@ -153,20 +130,11 @@
0
           Now lets connect to it with SSH (this may take a few tries, sometimes it takes a
0
           minute for the new instance to respond to SSH):
0
 
0
- RUN (replace instance ID with the one reported in the previous step):
0
-
0
             cap ec2:instances:ssh INSTANCE_ID='i-xxxxxx'
0
 
0
- TADA! You should be connected to your new instance in an SSH terminal. When you are
0
- done looking around type ^d (control-d) to exit the SSH shell.
0
-
0
           If you want to terminate your instance...
0
 
0
- RUN (replace the instance ID with the one reported in the previous step):
0
-
0
             cap ec2:instances:terminate INSTANCE_ID='i-xxxxxx'
0
-
0
- You're done with your first amazon-ec2 and Capsize tutorial!
0
 
0
         Enjoy Capsize!
0
 

Comments

    No one has commented yet.