bschwartz-capsize 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,18 @@
1
+ == 2007/06/13
2
+
3
+ * Re-branded Capsize 'Capsize' with 'Capazon' no more...
4
+ * Compatibility w/ Amazon EC2 (amazon-ec2) Gem v. >= 0.2.0
5
+ * Lots of enhancements (See website or README.txt)
6
+
7
+ == 2007/04/30
8
+
9
+ * Compatibility w/ Capistrano 2.0
10
+
11
+ == 2007/03/28
12
+
13
+ * Fix gem dependancies
14
+
15
+ == 2007/03/27
16
+
17
+ * Initial Release
18
+ * Provides Capistrano tasks wrapping the Amazon EC2 API
data/License.txt ADDED
@@ -0,0 +1,67 @@
1
+ Copyright (c) 2007-2008 Jesse Newland
2
+ Copyright (c) 2007 Glenn Rempe
3
+
4
+ This software is distributed under the Ruby License. A copy of which is
5
+ provided below.
6
+
7
+ RUBY LICENSE
8
+
9
+ http://www.ruby-lang.org/en/LICENSE.txt
10
+
11
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
12
+ You can redistribute it and/or modify it under either the terms of the GPL
13
+ (see COPYING.txt file), or the conditions below:
14
+
15
+ 1. You may make and give away verbatim copies of the source form of the
16
+ software without restriction, provided that you duplicate all of the
17
+ original copyright notices and associated disclaimers.
18
+
19
+ 2. You may modify your copy of the software in any way, provided that
20
+ you do at least ONE of the following:
21
+
22
+ a) place your modifications in the Public Domain or otherwise
23
+ make them Freely Available, such as by posting said
24
+ modifications to Usenet or an equivalent medium, or by allowing
25
+ the author to include your modifications in the software.
26
+
27
+ b) use the modified software only within your corporation or
28
+ organization.
29
+
30
+ c) rename any non-standard executables so the names do not conflict
31
+ with standard executables, which must also be provided.
32
+
33
+ d) make other distribution arrangements with the author.
34
+
35
+ 3. You may distribute the software in object code or executable
36
+ form, provided that you do at least ONE of the following:
37
+
38
+ a) distribute the executables and library files of the software,
39
+ together with instructions (in the manual page or equivalent)
40
+ on where to get the original distribution.
41
+
42
+ b) accompany the distribution with the machine-readable source of
43
+ the software.
44
+
45
+ c) give non-standard executables non-standard names, with
46
+ instructions on where to get the original software distribution.
47
+
48
+ d) make other distribution arrangements with the author.
49
+
50
+ 4. You may modify and include the part of the software into any other
51
+ software (possibly commercial). But some files in the distribution
52
+ are not written by the author, so that they are not under this terms.
53
+
54
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
55
+ files under the ./missing directory. See each file for the copying
56
+ condition.
57
+
58
+ 5. The scripts and library files supplied as input to or produced as
59
+ output from the software do not automatically fall under the
60
+ copyright of the software, but belong to whomever generated them,
61
+ and may be sold commercially, and may be aggregated with this
62
+ software.
63
+
64
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
65
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
66
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
67
+ PURPOSE.
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ examples/capsize.yml.template
9
+ examples/deploy.rb
10
+ lib/capsize.rb
11
+ lib/capsize/capsize.rb
12
+ lib/capsize/configuration.rb
13
+ lib/capsize/ec2.rb
14
+ lib/capsize/ec2_plugin.rb
15
+ lib/capsize/meta_tasks.rb
16
+ lib/capsize/sqs.rb
17
+ lib/capsize/sqs_plugin.rb
18
+ lib/capsize/version.rb
19
+ setup.rb
20
+ tasks/deployment.rake
21
+ tasks/environment.rake
22
+ tasks/website.rake
23
+ test/test_capsize.rb
24
+ test/test_helper.rb
data/README.textile ADDED
@@ -0,0 +1,83 @@
1
+ h1. Capsize
2
+
3
+ Capsize provides Capistrano tasks to manage Amazon EC2.
4
+
5
+ This project is in no way endorsed, sponsored by, or associated with Amazon, Amazon.com, or Amazon Web Services.
6
+
7
+ h2. Installation
8
+
9
+ * @gem install jnewland-capsize -s http://gems.github.com@
10
+ * Edit your your @config/deploy.rb@:
11
+
12
+ <pre>
13
+ <code>
14
+ # #################################################################
15
+ # CAPSIZE EC2 GEM
16
+ # #################################################################
17
+
18
+ # Include the Capsize EC2 'cap' tasks
19
+ # WARNING : This must be placed in your deploy.rb file anywhere
20
+ # AFTER the line where you set your application name! Looks like:
21
+ # set :application, "foobar".
22
+ # The application name is used by Capsize and the order matters.
23
+ require 'capsize'
24
+
25
+ # Use this to overwrite the standard capsize config dir locations
26
+ #set :capsize_config_dir, 'config/capsize'
27
+ #set :capsize_secure_config_dir, 'config/capsize'
28
+
29
+ # Use these to overwrite the actual config file names stored in the config dirs.
30
+ #set :capsize_config_file_name, 'capsize.yml'
31
+ #set :capsize_secure_config_file_name, 'secure.yml'
32
+ </code>
33
+ </pre>
34
+
35
+ * Run @cap deploy:setup@
36
+ * Paste the generated config into @config/deploy.rb@
37
+
38
+ h2. Tasks
39
+
40
+ Run cap -e <taskname> on any task to get more details
41
+
42
+ * cap ec2:console:output
43
+ * cap ec2:addresses:allocate
44
+ * cap ec2:addresses:associate
45
+ * cap ec2:addresses:disassociate
46
+ * cap ec2:addresses:release
47
+ * cap ec2:addresses:show
48
+ * cap ec2:images:show
49
+ * cap ec2:instances:reboot
50
+ * cap ec2:instances:run
51
+ * cap ec2:instances:show
52
+ * cap ec2:instances:ssh
53
+ * cap ec2:instances:terminate
54
+ * cap ec2:keypairs:create
55
+ * cap ec2:keypairs:delete
56
+ * cap ec2:keypairs:show
57
+ * cap ec2:security_groups:authorize_ingress
58
+ * cap ec2:security_groups:create
59
+ * cap ec2:security_groups:create_with_standard_ports
60
+ * cap ec2:security_groups:delete
61
+ * cap ec2:security_groups:revoke_ingress
62
+ * cap ec2:security_groups:show
63
+ * cap ec2:setup
64
+ * cap ec2:setup:check
65
+
66
+ h4. Notes:
67
+
68
+ * <em>All tasks optionally take environment variables in lieu of capistrano configuration variables.</em>
69
+
70
+ h4. Contributing
71
+
72
+ Source is on "GitHub":http://github.com/jnewland/capsize. You know what to do.
73
+
74
+ h4. Authors
75
+
76
+ * "Jesse Newland":http://jnewland.com/
77
+ * "Glenn Rempe":http://blog.rempe.us/
78
+
79
+ h4. Copyright
80
+
81
+ (c) 2007-2008 Jesse Newland, Glenn Rempe
82
+
83
+ Distributes under the same terms as Ruby
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'capsize/version'
2
+
3
+ AUTHOR = ['Jesse Newland','Glenn Rempe'] # can also be an array of Authors
4
+ EMAIL = "jnewland@gmail.com"
5
+ DESCRIPTION = "Capsize is a Capistrano plugin used to provide an easy way to manage and script interaction with the Amazon EC2 service using the amazon-ec2 Ruby gem."
6
+ GEM_NAME = 'capsize' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'capsize' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "grempe"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Capsize::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'capsize documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README.txt",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+ p.extra_deps = [['capistrano', '>= 2.1.0'], ['amazon-ec2', '>= 0.2.6'], ['rcov', '>= 0.8.1.2.0'], ['SQS', '>= 0.1.5'], ['builder', '>= 2.1.2'], ['RedCloth', '>= 3.0.4']]
64
+
65
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
66
+ p.spec_extras = {
67
+ :extra_rdoc_files => ["README.txt", "History.txt"],
68
+ :rdoc_options => RDOC_OPTS,
69
+ :autorequire => "capsize"
70
+ }
71
+
72
+ end
73
+
74
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
75
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
76
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -0,0 +1,18 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+
7
+ begin
8
+ require req_gem
9
+ rescue LoadError
10
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
11
+ puts "Installation: gem install #{req_gem} -y"
12
+ exit
13
+ end
14
+ end
15
+
16
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
17
+
18
+ #require 'capsize'
@@ -0,0 +1,67 @@
1
+ # capsize.yml
2
+
3
+ # Regular Config Info for the Capsize (capsize) gem
4
+
5
+ # This file should be setup to be deployed by capistrano
6
+ # along with the rest of your application. This file should only
7
+ # contain non-security related config info and thusly can be
8
+ # safely versioned in your version control system.
9
+
10
+ # I should be put in the RAILS_ROOT/config/capsize/secure.yml of your Ruby on Rails app
11
+ # or the location of your choice if you override :capsize_config_dir
12
+
13
+ # set variables in 'common' that are the same across
14
+ # ALL environments. This helps us keep this file nice and DRY.
15
+ common: &common
16
+
17
+ # KEYPAIR CONFIG
18
+ ##########################################################
19
+ #defaults to the name of the :application set in deploy.rb
20
+ #key_name: 'my_cool_key_name'
21
+
22
+
23
+ # CAPSIZE CONFIG
24
+ ##########################################################
25
+ # use an ssl connection to talk to EC2? true or false allowed (no quotes)
26
+ # Defaults to true
27
+ #use_ssl: true
28
+
29
+
30
+ # SECURITY GROUP CONFIG
31
+ ##########################################################
32
+ # Set the default security group to apply firewall ingress rules to.
33
+ # Defaults, appropriately, to 'default' security group.
34
+ #group_name: 'default'
35
+
36
+ # Set the default security group ip protocol to apply firewall ingress rules to.
37
+ # Defaults, appropriately, to 'tcp'.
38
+ #ip_protocol: 'tcp'
39
+
40
+ # other options you can override if needed
41
+ #from_port: nil
42
+ #to_port: nil
43
+ #cidr_ip: '0.0.0.0/0'
44
+ #source_security_group_name: nil
45
+ #source_security_group_owner_id: nil
46
+
47
+
48
+ development:
49
+ <<: *common
50
+
51
+ # Uncomment and I only apply to the dev environment
52
+ # or overwrite a common value
53
+ #foo: 'bar'
54
+
55
+ test:
56
+ <<: *common
57
+
58
+ staging:
59
+ <<: *common
60
+
61
+ production:
62
+ <<: *common
63
+
64
+ # Uncomment and I only apply to the production environment
65
+ # or overwrite a common value
66
+ #foo: 'baz'
67
+
@@ -0,0 +1,29 @@
1
+ # CAPSIZE 'deploy.rb' SAMPLE
2
+ # Use this as a starting point for what you will need to add to your
3
+ # standard Capistrano deploy.rb file to make it function with Capsize.
4
+
5
+ # #################################################################
6
+ # CAPSIZE CONFIG SETTINGS
7
+ # #################################################################
8
+
9
+ # Include the Capsize EC2 'cap' tasks
10
+ # WARNING : This must be placed in your deploy.rb file anywhere
11
+ # AFTER the line where you set your application name! Looks like:
12
+ # set :application, "foobar".
13
+ # The application name is used by Capsize and the order matters!
14
+ require 'capsize'
15
+
16
+ # Uncomment to override the standard capsize config dir
17
+ # used for standard config info.
18
+ #set :capsize_config_dir, 'config/capsize'
19
+
20
+ # Uncomment to override location used to store a
21
+ # secure config file with your AWS credentials,
22
+ # and EC2 private keypair information.
23
+ #set :capsize_secure_config_dir, 'config/capsize'
24
+
25
+ # Uncomment to override the actual config file names
26
+ # that are stored in the config dirs noted above.
27
+ #set :capsize_config_file_name, 'capsize.yml'
28
+ #set :capsize_secure_config_file_name, 'secure.yml'
29
+
@@ -0,0 +1,101 @@
1
+ module Capsize
2
+
3
+ # capsize.get(:symbol_name) checks for variables in several places, with this precedence (from low to high):
4
+ # * default capistrano or capsize set variables (available with fetch())
5
+ # * Set in :capsize_config_dir/:capsize_config_file_name (overwrites previous)
6
+ # * Set in :capsize_config_dir/:capsize_secure_config_file_name (overwrites previous)
7
+ # * Passed in as part of the command line params and available as ENV["SYMBOL_NAME"] (overwrites previous)
8
+ #
9
+ def get(symbol=nil)
10
+
11
+ raise Exception if symbol.nil? || symbol.class != Symbol # TODO : Jesse: fixup exceptions in capsize
12
+
13
+ # populate the OpenStructs with contents of config files so we can query them.
14
+ @capsize_config ||= load_config(:config_file => "#{fetch(:capsize_config_dir)}/#{fetch(:capsize_config_file_name)}")
15
+ @secure_config ||= load_config(:config_file => "#{fetch(:capsize_secure_config_dir)}/#{fetch(:capsize_secure_config_file_name)}")
16
+
17
+ # fetch var from default capsize or default capistrano config vars,
18
+ # and if it doesn't exist set it to nil
19
+ set symbol, fetch(symbol, nil)
20
+
21
+ # if symbol exists as a var in the secure config, then set it to that
22
+ # overriding default cap or capsize config vars
23
+ if @secure_config.respond_to?(symbol)
24
+ set symbol, @secure_config.send(symbol)
25
+ end
26
+
27
+ # if symbol exists as a var in the standard capsize config, then set it to that
28
+ # overriding secure config vars
29
+ if @capsize_config.respond_to?(symbol)
30
+ set symbol, @capsize_config.send(symbol)
31
+ end
32
+
33
+ # if ENV["SYMBOL_NAME"] isn't nil set it to ENV["SYMBOL_NAME"]
34
+ # ENV vars passed on the command line override any previously defined vars
35
+ unless ENV[symbol.to_s.upcase].nil?
36
+ set symbol, ENV[symbol.to_s.upcase]
37
+ end
38
+
39
+ # Some config values should fall back to reasonable defaults.
40
+ # If we didn't find a value set in any config anywhere, then we should
41
+ # set a reasonable default value for these special cases. It is better to
42
+ # do this in this one place instead of specifying fallbacks all over the place
43
+ # in the app. Helps keep it DRY.
44
+ case symbol
45
+ when :group_name
46
+ # the :group_name should fall back to the application name if not provided.
47
+ if fetch(:group_name, nil).nil?
48
+ set symbol, fetch(:application)
49
+ end
50
+ when :key_name
51
+ # the :key_name should fall back to the application name if not provided.
52
+ if fetch(:key_name, nil).nil?
53
+ set symbol, fetch(:application)
54
+ end
55
+ when :group_description
56
+ # the :group_description should fall back to the application name if not provided.
57
+ if fetch(:group_description, nil).nil?
58
+ set symbol, fetch(:application)
59
+ end
60
+ end
61
+
62
+
63
+ # If we have a good set variable then return that variable, else send back a nil
64
+ # if that's what we get and let the calling method either raise an exception
65
+ # or determine how to gracefully handle it. We don't want to raise an exception every
66
+ # time a get fails. nil might be just fine as an answer for some questions.
67
+ return fetch(symbol)
68
+
69
+ end
70
+
71
+
72
+ # load specified ":config_file => 'foo.yaml'" into a OpenStruct object and return it.
73
+ def load_config(options = {})
74
+ options = {:config_file => ""}.merge(options)
75
+
76
+ raise Exception, "Config file location required" if options[:config_file].nil? || options[:config_file].empty?
77
+
78
+ if File.exist?(options[:config_file])
79
+
80
+ # try to load the yaml config file
81
+ begin
82
+ config = OpenStruct.new(YAML.load_file(options[:config_file]))
83
+ env_config = OpenStruct.new(config.send(deploy_env))
84
+ rescue Exception => e
85
+ env_config = nil
86
+ end
87
+
88
+ # Send back an empty OpenStruct if we can't load the config file.
89
+ # config files are not required! Want to avoid method calls on nil
90
+ # if there are no config files to load.
91
+ if env_config.nil?
92
+ return OpenStruct.new
93
+ else
94
+ return env_config
95
+ end
96
+
97
+ end
98
+ end
99
+ end
100
+
101
+ Capistrano.plugin :capsize, Capsize
@@ -0,0 +1,44 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ # Set reasonable defaults for all needed values so in theory this Cap plugin
4
+ # will work out-of-the-box with no external config required. Users
5
+ # can also opt to set any of these in their deploy.rb file to override them.
6
+
7
+ set :capsize_config_dir, 'config/capsize'
8
+ set :capsize_secure_config_dir, 'config/capsize'
9
+
10
+ set :capsize_config_file_name, 'capsize.yml'
11
+ set :capsize_secure_config_file_name, 'secure.yml'
12
+
13
+ # Where are the various extra capsize files stored? Make them easy to get() or override
14
+ set :capsize_examples_dir, "#{File.join(File.dirname(__FILE__), '/../../examples')}"
15
+ set :capsize_bin_dir, "#{File.join(File.dirname(__FILE__), '/../../bin')}"
16
+
17
+ # Determine where we will deploy to. if TARGET is not specified
18
+ # then setup for 'production' environment by default.
19
+ # TODO : CHANGE THIS TO TARGET_ENV IN HERE AND AMAZON-EC2, and in my app
20
+ # TODO : Make this work with capistrano-ext
21
+ set :deploy_env, ENV['TARGET'] ||= "production"
22
+
23
+ # defaults for new security groups
24
+ set :group_name, nil
25
+ set :group_description, "Default security group for the application."
26
+
27
+ set :ip_protocol, 'tcp'
28
+ set :from_port, nil
29
+ set :to_port, nil
30
+ set :cidr_ip, '0.0.0.0/0'
31
+ set :source_security_group_name, nil
32
+ set :source_security_group_owner_id, nil
33
+
34
+ set :image_id, nil
35
+ set :min_count, 1
36
+ set :max_count, 1
37
+ set :instance_type, 'm1.small'
38
+ # FIXME : Breaks loading of this file and tests
39
+ # set :key_name, "#{application}"
40
+ # set :queue_name, "#{application}"
41
+ set :user_data, nil
42
+ set :addressing_type, 'public'
43
+
44
+ end