composer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/CHANGELOG +7 -0
- data/README.md +2 -24
- data/Rakefile +6 -0
- data/bin/composer +6 -0
- data/composer.gemspec +5 -0
- data/lib/composer.rb +8 -1
- data/lib/composer/aws.rb +7 -0
- data/lib/composer/aws/ec2.rb +20 -0
- data/lib/composer/cli.rb +88 -0
- data/lib/composer/compose.rb +74 -0
- data/lib/composer/config.rb +18 -0
- data/lib/composer/deploy.rb +7 -0
- data/lib/composer/deploy/heirloom.rb +35 -0
- data/lib/composer/deploy/stack.rb +26 -0
- data/lib/composer/exceptions.rb +34 -0
- data/lib/composer/logger.rb +34 -0
- data/lib/composer/setup.rb +7 -0
- data/lib/composer/setup/heirloom.rb +54 -0
- data/lib/composer/setup/simple_deploy.rb +33 -0
- data/lib/composer/verify.rb +11 -0
- data/lib/composer/verify/config.rb +28 -0
- data/lib/composer/verify/directory.rb +42 -0
- data/lib/composer/verify/key.rb +28 -0
- data/lib/composer/verify/name.rb +24 -0
- data/lib/composer/verify/region.rb +29 -0
- data/lib/composer/verify/ruby.rb +15 -0
- data/lib/composer/version.rb +1 -1
- data/spec/compose_spec.rb +66 -0
- data/spec/spec_helper.rb +8 -0
- metadata +68 -7
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p327@composer --create
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
@@ -1,29 +1,7 @@
|
|
1
1
|
# Composer
|
2
2
|
|
3
|
-
|
3
|
+
I help setup new projects on the Intuit Cloud Agility Platform
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
gem 'composer'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install composer
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
7
|
+
I'm primarly used with [liftoff](https://github.com/intuit/liftoff).
|
data/Rakefile
CHANGED
data/bin/composer
ADDED
data/composer.gemspec
CHANGED
@@ -16,4 +16,9 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'aws-sdk', '1.7.1'
|
19
24
|
end
|
data/lib/composer.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
require "composer/aws"
|
2
|
+
require "composer/config"
|
3
|
+
require "composer/compose"
|
4
|
+
require "composer/deploy"
|
5
|
+
require "composer/exceptions"
|
6
|
+
require "composer/logger"
|
7
|
+
require "composer/setup"
|
8
|
+
require "composer/verify"
|
1
9
|
require "composer/version"
|
2
10
|
|
3
11
|
module Composer
|
4
|
-
# Your code goes here...
|
5
12
|
end
|
data/lib/composer/aws.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Composer
|
2
|
+
module AWS
|
3
|
+
class EC2
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def key_pairs
|
10
|
+
ec2.key_pairs
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def ec2
|
16
|
+
@ec2 ||= ::AWS::EC2.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/composer/cli.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Composer
|
4
|
+
class Cli
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@opts = parse_options
|
8
|
+
@config = Config.new :log_level => @opts[:log_level]
|
9
|
+
@logger = @config.logger
|
10
|
+
|
11
|
+
validate_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
configure_aws
|
16
|
+
|
17
|
+
compose = Compose.new :config => @config,
|
18
|
+
:name => @opts[:name],
|
19
|
+
:key => @opts[:key],
|
20
|
+
:directory => @opts[:directory] ||= '.'
|
21
|
+
begin
|
22
|
+
compose.check
|
23
|
+
compose.run
|
24
|
+
rescue Composer::ComposerException => e
|
25
|
+
@logger.error e.message
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def configure_aws
|
33
|
+
@config.aws_secret_key = @opts[:aws_secret_key]
|
34
|
+
@config.aws_access_key = @opts[:aws_access_key]
|
35
|
+
@config.region = @opts[:region]
|
36
|
+
@config.configure_aws
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_options
|
40
|
+
required_keys = [:key, :name, :region]
|
41
|
+
missing_keys = required_keys - @opts.keys
|
42
|
+
|
43
|
+
unless missing_keys.empty?
|
44
|
+
@logger.error "Missing options: #{missing_keys.join(', ')}."
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_options
|
50
|
+
options = {}
|
51
|
+
|
52
|
+
OptionParser.new do |opts|
|
53
|
+
|
54
|
+
opts.banner = "Usage: composer [options]"
|
55
|
+
|
56
|
+
opts.on("-d", "--name [NAME]", "Directory to upload.") do |d|
|
57
|
+
options[:directory] = d
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on("-k", "--key [SSH_KEY_NAME]", "SSH Key Name.") do |k|
|
61
|
+
options[:key] = k
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on("-l", "--log-level [LOG_LEVEL]", "Log Level.") do |l|
|
65
|
+
options[:log_level] = l
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on("-n", "--name [NAME]", "Name of application.") do |n|
|
69
|
+
options[:name] = n
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on("-r", "--region [REGION]", "Deployment Region.") do |r|
|
73
|
+
options[:region] = r
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on("-a", "--aws-access-key [AWS_ACCESS_KEY]", "AWS Access Key.") do |a|
|
77
|
+
options[:aws_access_key] = a
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on("-s", "--aws-secret-key [AWS_SECRET_KEY]", "AWS Secret Key.") do |s|
|
81
|
+
options[:aws_secret_key] = s
|
82
|
+
end
|
83
|
+
end.parse!
|
84
|
+
|
85
|
+
options
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Composer
|
2
|
+
class Compose
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@name = args[:name]
|
6
|
+
@key = args[:key]
|
7
|
+
@directory = args[:directory]
|
8
|
+
@config = args[:config]
|
9
|
+
end
|
10
|
+
|
11
|
+
def check
|
12
|
+
verify_ruby.verify
|
13
|
+
verify_config.verify_simple_deploy
|
14
|
+
verify_config.verify_heirloom
|
15
|
+
verify_name.verify :name => @name
|
16
|
+
verify_key.verify :key => @key
|
17
|
+
verify_directory.verify :directory => @directory
|
18
|
+
verify_region.verify
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
setup_heirloom.setup :name => @name
|
23
|
+
setup_simple_deploy.setup
|
24
|
+
deploy_heirloom.upload :directory => @directory,
|
25
|
+
:name => @name
|
26
|
+
deploy_stack.create :key => @key,
|
27
|
+
:name => @name,
|
28
|
+
:directory => @directory
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def verify_ruby
|
34
|
+
@verify_ruby ||= Verify::Ruby.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def verify_config
|
38
|
+
@verify_config ||= Verify::Config.new :config => @config
|
39
|
+
end
|
40
|
+
|
41
|
+
def verify_name
|
42
|
+
@verify_name ||= Verify::Name.new :config => @config
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify_key
|
46
|
+
@verify_key ||= Verify::Key.new :config => @config
|
47
|
+
end
|
48
|
+
|
49
|
+
def verify_directory
|
50
|
+
@verify_directory ||= Verify::Directory.new :config => @config
|
51
|
+
end
|
52
|
+
|
53
|
+
def verify_region
|
54
|
+
@verify_region ||= Verify::Region.new :config => @config
|
55
|
+
end
|
56
|
+
|
57
|
+
def setup_heirloom
|
58
|
+
@setup_heirloom ||= Setup::Heirloom.new :config => @config
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_simple_deploy
|
62
|
+
@setup_simple_deploy ||= Setup::SimpleDeploy.new :config => @config
|
63
|
+
end
|
64
|
+
|
65
|
+
def deploy_heirloom
|
66
|
+
@deploy_heirloom ||= Deploy::Heirloom.new :config => @config
|
67
|
+
end
|
68
|
+
|
69
|
+
def deploy_stack
|
70
|
+
@deploy_stack ||= Deploy::Stack.new :config => @config
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Composer
|
2
|
+
class Config
|
3
|
+
attr_accessor :aws_secret_key, :aws_access_key,
|
4
|
+
:region, :logger
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
log_level = args[:log_level]
|
8
|
+
@logger = ComposerLogger.new :log_level => log_level
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure_aws
|
12
|
+
::AWS.config :access_key_id => aws_access_key,
|
13
|
+
:secret_access_key => aws_secret_key,
|
14
|
+
:region => region
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Composer
|
2
|
+
module Deploy
|
3
|
+
class Heirloom
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def upload(args)
|
10
|
+
@directory = args[:directory]
|
11
|
+
@name = args[:name]
|
12
|
+
@force = args[:force]
|
13
|
+
|
14
|
+
["chef-repo", "app"].each do |heirloom|
|
15
|
+
upload_heirloom heirloom
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def upload_heirloom(heirloom)
|
22
|
+
directory_to_upload = "#{@directory}/#{heirloom}"
|
23
|
+
command = "heirloom upload -d #{directory_to_upload} -n #{@name}-#{heirloom} -i v1.0.0"
|
24
|
+
@logger.info "Uploading Heirloom: '#{@name}-#{heirloom}'"
|
25
|
+
@logger.debug "Executing: `#{command}`"
|
26
|
+
output = `#{command}`
|
27
|
+
@logger.debug "Exited with status: '#{$?.exitstatus}'"
|
28
|
+
unless $?.success?
|
29
|
+
raise CommandError.new output
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Composer
|
2
|
+
module Deploy
|
3
|
+
class Stack
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(args)
|
9
|
+
directory = args[:directory]
|
10
|
+
key = args[:key]
|
11
|
+
name = args[:name]
|
12
|
+
|
13
|
+
app_version = 'v1.0.0'
|
14
|
+
chef_version = 'v1.0.0'
|
15
|
+
environment_secret = 'password'
|
16
|
+
environment = 'default'
|
17
|
+
template = "#{directory}/cloud-formation-templates/examples/classic/asg_with_cpu_scaling_policies.json"
|
18
|
+
|
19
|
+
puts ""
|
20
|
+
puts "Deploy Example Stack:"
|
21
|
+
puts ""
|
22
|
+
puts "simple_deploy create -e #{environment} -n #{name} -t #{template} -a AppName=#{name} -a EnvironmentSecret=#{environment_secret} -a KeyName=#{key} -a app=#{app_version} -a chef_repo=#{chef_version} -a app_domain=#{name}-app -a chef_repo_domain=#{name}-chef-repo -a app_bucket_prefix=#{name} -a chef_repo_bucket_prefix=#{name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Composer
|
2
|
+
class ComposerException < RuntimeError
|
3
|
+
attr_accessor :message
|
4
|
+
|
5
|
+
def initialize(message="")
|
6
|
+
@message = message
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class InvalidDirectory < ComposerException
|
11
|
+
end
|
12
|
+
|
13
|
+
class InvalidKeyPair < ComposerException
|
14
|
+
end
|
15
|
+
|
16
|
+
class InvalidName < ComposerException
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidRegion < ComposerException
|
20
|
+
end
|
21
|
+
|
22
|
+
class UnsupportedRubyVersion < ComposerException
|
23
|
+
end
|
24
|
+
|
25
|
+
class CommandError < ComposerException
|
26
|
+
end
|
27
|
+
|
28
|
+
class HeirloomConfigExists < ComposerException
|
29
|
+
end
|
30
|
+
|
31
|
+
class SimpleDeployConfigExists < ComposerException
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Composer
|
4
|
+
class ComposerLogger
|
5
|
+
|
6
|
+
require 'forwardable'
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :@logger, :debug, :error, :info, :warn
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
@log_level = args[:log_level] ||= 'info'
|
14
|
+
@logger = args[:logger] ||= new_logger(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def new_logger(args)
|
20
|
+
Logger.new(STDOUT).tap do |l|
|
21
|
+
l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
|
22
|
+
l.formatter = proc do |severity, datetime, progname, msg|
|
23
|
+
"#{datetime} #{severity} : #{msg}\n"
|
24
|
+
end
|
25
|
+
l.level = logger_level
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger_level
|
30
|
+
Logger.const_get @log_level.upcase
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Composer
|
2
|
+
module Setup
|
3
|
+
class Heirloom
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup(args)
|
10
|
+
name = args[:name]
|
11
|
+
|
12
|
+
write_config_file
|
13
|
+
|
14
|
+
["#{name}-chef-repo", "#{name}-app"].each do |heirloom|
|
15
|
+
if heirloom_exists?(heirloom)
|
16
|
+
raise HeirloomExists "#{@name}-#{heirloom} exists. Use force to continue."
|
17
|
+
end
|
18
|
+
|
19
|
+
command = "heirloom setup -b #{name} -n #{heirloom} -r us-west-1 -r us-west-2 -r us-east-1 -m us-west-1"
|
20
|
+
@logger.info "Setting up Heirloom: '#{heirloom}'"
|
21
|
+
@logger.debug "Executing: `#{command}`"
|
22
|
+
output = `#{command}`
|
23
|
+
@logger.debug "Exited with status: '#{$?.exitstatus}'"
|
24
|
+
unless $?.success?
|
25
|
+
raise CommandError.new output
|
26
|
+
end
|
27
|
+
sleep 15
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def write_config_file
|
34
|
+
file = "#{ENV['HOME']}/.heirloom.yml"
|
35
|
+
config = {
|
36
|
+
'aws' => {
|
37
|
+
'secret_key' => @config.aws_secret_key,
|
38
|
+
'access_key' => @config.aws_access_key
|
39
|
+
}
|
40
|
+
}
|
41
|
+
@logger.info "Writing config file #{file}."
|
42
|
+
File.open(file, 'w') {|f| f.write(config.to_yaml) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def heirloom_exists?(heirloom)
|
46
|
+
command = "heirloom catalog -n #{heirloom}"
|
47
|
+
@logger.debug "Executing: `#{command}`"
|
48
|
+
output = `#{command}`
|
49
|
+
@logger.debug "Exited with status: '#{$?.exitstatus}'"
|
50
|
+
$?.success? == '0' ? true : false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Composer
|
2
|
+
module Setup
|
3
|
+
class SimpleDeploy
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@config = args[:config]
|
7
|
+
@logger = @config.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
write_config_file
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def write_config_file
|
17
|
+
file = "#{ENV['HOME']}/.simple_deploy.yml"
|
18
|
+
config = {
|
19
|
+
'environments' => {
|
20
|
+
'default' => {
|
21
|
+
'secret_key' => @config.aws_secret_key,
|
22
|
+
'access_key' => @config.aws_access_key,
|
23
|
+
'region' => @config.region
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
@logger.info "Writing config file #{file}."
|
28
|
+
File.open(file, 'w') {|f| f.write(config.to_yaml) }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Config
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_heirloom
|
10
|
+
if File.exists? "#{ENV['HOME']}/.heirloom.yml"
|
11
|
+
raise HeirloomConfigExists.new "#{ENV['HOME']}/.heirloom.yml already exists."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def verify_simple_deploy
|
16
|
+
if File.exists? "#{ENV['HOME']}/.simple_deploy.yml"
|
17
|
+
raise SimpleDeployConfigExists.new "#{ENV['HOME']}/.simple_deploy.yml already exists."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def ec2
|
24
|
+
@ec2 ||= AWS::EC2.new :config => @config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Directory
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify(args)
|
10
|
+
@directory = args[:directory]
|
11
|
+
|
12
|
+
unless Dir.exists? @directory
|
13
|
+
error = "Directory '#{@directory}' does not exist."
|
14
|
+
raise InvalidDirectory.new error
|
15
|
+
end
|
16
|
+
|
17
|
+
unless entries.include? 'chef-repo'
|
18
|
+
error = "Directory '#{@directory}' does not include chef-repo."
|
19
|
+
raise InvalidDirectory.new error
|
20
|
+
end
|
21
|
+
|
22
|
+
unless entries.include? 'app'
|
23
|
+
error = "Directory '#{@directory}' does not include app."
|
24
|
+
raise InvalidDirectory.new error
|
25
|
+
end
|
26
|
+
|
27
|
+
unless entries.include? 'cloud-formation-templates'
|
28
|
+
error = "Directory '#{@directory}' does not include cloud-formation-template."
|
29
|
+
raise InvalidDirectory.new error
|
30
|
+
end
|
31
|
+
|
32
|
+
@logger.info "Directory '#{@directory}' is valid."
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def entries
|
38
|
+
@entries ||= Dir.entries @directory
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Key
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify(args)
|
10
|
+
key = args[:key]
|
11
|
+
|
12
|
+
key_pairs = ec2.key_pairs.entries.map { |k| k.name }
|
13
|
+
|
14
|
+
@logger.debug "Existing keypairs: #{key_pairs.join ', '}"
|
15
|
+
|
16
|
+
unless key_pairs.include? key
|
17
|
+
raise InvalidKeyPair.new "Key #{key} does not exist in target region."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def ec2
|
24
|
+
@ec2 ||= AWS::EC2.new :config => @config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Name
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@config = args[:config]
|
7
|
+
@logger = @config.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def verify(args)
|
11
|
+
name = args[:name]
|
12
|
+
|
13
|
+
if name.length < 3
|
14
|
+
raise InvalidName.new "'#{name}' must be at least 3 characters"
|
15
|
+
elsif ! (name =~ /^[0-9a-z\-]+$/)
|
16
|
+
raise InvalidName.new "'#{name}' contains invalid character. Only lowercase letter, numbers and dashes."
|
17
|
+
end
|
18
|
+
|
19
|
+
@logger.info "Application name '#{name}' is valid."
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Region
|
4
|
+
def initialize(args)
|
5
|
+
@config = args[:config]
|
6
|
+
@logger = @config.logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify
|
10
|
+
region = @config.region
|
11
|
+
|
12
|
+
@logger.debug "Valid Regions: #{valid_regions.join ', '}"
|
13
|
+
|
14
|
+
unless valid_regions.include? region
|
15
|
+
raise InvalidRegion.new "Region '#{region}' is not valid."
|
16
|
+
end
|
17
|
+
|
18
|
+
@logger.info "Region '#{region}' is valid."
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def valid_regions
|
24
|
+
['us-west-1', 'us-west-2', 'us-east-1']
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Composer
|
2
|
+
module Verify
|
3
|
+
class Ruby
|
4
|
+
def verify
|
5
|
+
unless ruby_version >= '1.9.1'
|
6
|
+
raise UnsupportedRubyVersion.new "Ruby version '#{ruby_version}' is less than 1.9.1"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def ruby_version
|
11
|
+
RUBY_VERSION
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/composer/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Composer::Compose do
|
4
|
+
before do
|
5
|
+
@logger_stub = stub 'logger'
|
6
|
+
@config_stub = stub 'config', :logger => @logger_stub
|
7
|
+
|
8
|
+
@compose = Composer::Compose.new :name => 'name',
|
9
|
+
:key => 'key',
|
10
|
+
:directory => '/tmp/dir',
|
11
|
+
:config => @config_stub
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should run setup checks" do
|
15
|
+
@verify_config_mock = mock 'verify_config'
|
16
|
+
Composer::Verify::Config.stub :new => @verify_config_mock
|
17
|
+
@verify_config_mock.should_receive :verify_simple_deploy
|
18
|
+
@verify_config_mock.should_receive :verify_heirloom
|
19
|
+
|
20
|
+
@verify_name_mock = mock 'verify_name'
|
21
|
+
Composer::Verify::Name.stub :new => @verify_name_mock
|
22
|
+
@verify_name_mock.should_receive(:verify).with(:name => 'name')
|
23
|
+
|
24
|
+
@verify_key_mock = mock 'verify_key'
|
25
|
+
Composer::Verify::Key.stub :new => @verify_key_mock
|
26
|
+
@verify_key_mock.should_receive(:verify).with(:key => 'key')
|
27
|
+
|
28
|
+
@verify_directory_mock = mock 'verify_directory'
|
29
|
+
Composer::Verify::Directory.stub :new => @verify_directory_mock
|
30
|
+
@verify_directory_mock.should_receive(:verify).
|
31
|
+
with(:directory => '/tmp/dir')
|
32
|
+
|
33
|
+
@verify_region_mock = mock 'verify_region'
|
34
|
+
Composer::Verify::Region.stub :new => @verify_region_mock
|
35
|
+
@verify_region_mock.should_receive(:verify)
|
36
|
+
|
37
|
+
@compose.check
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should run setup" do
|
41
|
+
@setup_heirloom_mock = mock 'setup_heirloom'
|
42
|
+
Composer::Setup::Heirloom.stub :new => @setup_heirloom_mock
|
43
|
+
@setup_heirloom_mock.should_receive(:setup).
|
44
|
+
with(:name => 'name')
|
45
|
+
|
46
|
+
@setup_simple_deploy_mock = mock 'setup_simple_deploy'
|
47
|
+
Composer::Setup::SimpleDeploy.stub :new => @setup_simple_deploy_mock
|
48
|
+
@setup_simple_deploy_mock.should_receive(:setup)
|
49
|
+
|
50
|
+
@deploy_heirloom_mock = mock 'deploy_heirloom'
|
51
|
+
Composer::Deploy::Heirloom.stub :new => @deploy_heirloom_mock
|
52
|
+
@deploy_heirloom_mock.should_receive(:upload).
|
53
|
+
with(:directory => '/tmp/dir',
|
54
|
+
:name => 'name')
|
55
|
+
|
56
|
+
@deploy_stack_mock = mock 'deploy_stack'
|
57
|
+
Composer::Deploy::Stack.stub :new => @deploy_stack_mock
|
58
|
+
@deploy_stack_mock.should_receive(:create).
|
59
|
+
with(:directory => '/tmp/dir',
|
60
|
+
:key => 'key',
|
61
|
+
:name => 'name')
|
62
|
+
|
63
|
+
@compose.run
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,23 +9,82 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70334146608500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70334146608500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70334146607820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70334146607820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: aws-sdk
|
38
|
+
requirement: &70334146607060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - =
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.7.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70334146607060
|
14
47
|
description: I deploy and manage AWS resources.
|
15
48
|
email:
|
16
49
|
- brett@weav.net
|
17
|
-
executables:
|
50
|
+
executables:
|
51
|
+
- composer
|
18
52
|
extensions: []
|
19
53
|
extra_rdoc_files: []
|
20
54
|
files:
|
21
55
|
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- CHANGELOG
|
22
58
|
- Gemfile
|
23
59
|
- LICENSE.txt
|
24
60
|
- README.md
|
25
61
|
- Rakefile
|
62
|
+
- bin/composer
|
26
63
|
- composer.gemspec
|
27
64
|
- lib/composer.rb
|
65
|
+
- lib/composer/aws.rb
|
66
|
+
- lib/composer/aws/ec2.rb
|
67
|
+
- lib/composer/cli.rb
|
68
|
+
- lib/composer/compose.rb
|
69
|
+
- lib/composer/config.rb
|
70
|
+
- lib/composer/deploy.rb
|
71
|
+
- lib/composer/deploy/heirloom.rb
|
72
|
+
- lib/composer/deploy/stack.rb
|
73
|
+
- lib/composer/exceptions.rb
|
74
|
+
- lib/composer/logger.rb
|
75
|
+
- lib/composer/setup.rb
|
76
|
+
- lib/composer/setup/heirloom.rb
|
77
|
+
- lib/composer/setup/simple_deploy.rb
|
78
|
+
- lib/composer/verify.rb
|
79
|
+
- lib/composer/verify/config.rb
|
80
|
+
- lib/composer/verify/directory.rb
|
81
|
+
- lib/composer/verify/key.rb
|
82
|
+
- lib/composer/verify/name.rb
|
83
|
+
- lib/composer/verify/region.rb
|
84
|
+
- lib/composer/verify/ruby.rb
|
28
85
|
- lib/composer/version.rb
|
86
|
+
- spec/compose_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
29
88
|
homepage: ''
|
30
89
|
licenses: []
|
31
90
|
post_install_message:
|
@@ -40,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
99
|
version: '0'
|
41
100
|
segments:
|
42
101
|
- 0
|
43
|
-
hash: -
|
102
|
+
hash: -1303089419036648253
|
44
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
104
|
none: false
|
46
105
|
requirements:
|
@@ -49,11 +108,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
108
|
version: '0'
|
50
109
|
segments:
|
51
110
|
- 0
|
52
|
-
hash: -
|
111
|
+
hash: -1303089419036648253
|
53
112
|
requirements: []
|
54
113
|
rubyforge_project:
|
55
114
|
rubygems_version: 1.8.16
|
56
115
|
signing_key:
|
57
116
|
specification_version: 3
|
58
117
|
summary: I deploy and manage AWS resources.
|
59
|
-
test_files:
|
118
|
+
test_files:
|
119
|
+
- spec/compose_spec.rb
|
120
|
+
- spec/spec_helper.rb
|