simple_deploy 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/simple_deploy +6 -0
- data/lib/simple_deploy/artifact/artifact_lister.rb +18 -0
- data/lib/simple_deploy/artifact/artifact_reader.rb +11 -0
- data/lib/simple_deploy/artifact.rb +37 -0
- data/lib/simple_deploy/cli/variables.rb +21 -0
- data/lib/simple_deploy/cli.rb +95 -0
- data/lib/simple_deploy/config.rb +44 -0
- data/lib/simple_deploy/deployment.rb +65 -0
- data/lib/simple_deploy/stack/stack_lister.rb +13 -0
- data/lib/simple_deploy/stack/stack_reader.rb +39 -0
- data/lib/simple_deploy/stack.rb +76 -0
- data/lib/simple_deploy/version.rb +3 -0
- data/lib/simple_deploy.rb +5 -0
- data/simple_deploy.gemspec +27 -0
- data/spec/config_spec.rb +11 -0
- data/spec/spec_helper.rb +8 -0
- metadata +129 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p125@simple_deploy --create
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/simple_deploy
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'heirloom'
|
2
|
+
require 'simple_deploy/artifact/artifact_lister'
|
3
|
+
|
4
|
+
module SimpleDeploy
|
5
|
+
class Artifact
|
6
|
+
|
7
|
+
attr_accessor :metadata
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
@region = args[:region]
|
11
|
+
self.metadata = Heirloom::Heirloom.info(args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_endpoints
|
15
|
+
{
|
16
|
+
's3' => s3_url,
|
17
|
+
'http' => http_url,
|
18
|
+
'https' => https_url
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def s3_url
|
23
|
+
key = "#{@region}-s3-url"
|
24
|
+
metadata[key] ? metadata[key].first : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def http_url
|
28
|
+
key = "#{@region}-http-url"
|
29
|
+
metadata[key] ? metadata[key].first : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def https_url
|
33
|
+
key = "#{@region}-https-url"
|
34
|
+
metadata[key] ? metadata[key].first : nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SimpleDeploy
|
2
|
+
module CLI
|
3
|
+
def self.attributes
|
4
|
+
attrs = []
|
5
|
+
read_attributes.each do |attribs|
|
6
|
+
a = attribs.split('=')
|
7
|
+
attrs << { a.first => a.last }
|
8
|
+
end
|
9
|
+
attrs
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.read_attributes
|
13
|
+
@opts[:attributes].nil? ? [] : @opts[:attributes].split(',')
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.environment_provided?
|
17
|
+
@opts[:environment].nil? != true
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'simple_deploy/cli/variables'
|
3
|
+
|
4
|
+
module SimpleDeploy
|
5
|
+
module CLI
|
6
|
+
def self.start
|
7
|
+
@opts = Trollop::options do
|
8
|
+
banner <<-EOS
|
9
|
+
|
10
|
+
Deploy and manage resources in AWS
|
11
|
+
|
12
|
+
simple_deploy environments
|
13
|
+
simple_deploy list -e ENVIRONMENT
|
14
|
+
simple_deploy create -n STACK_NAME -e ENVIRONMENT -a ATTRIBUTES -t TEMPLATE_PATH
|
15
|
+
simple_deploy update -n STACK_NAME -e ENVIRONMENT -a ATTRIBUTES
|
16
|
+
simple_deploy deploy -n STACK_NAME -e ENVIRONMENT
|
17
|
+
simple_deploy destroy -n STACK_NAME -e ENVIRONMENT
|
18
|
+
simple_deploy instances -n STACK_NAME -e ENVIRONMENT
|
19
|
+
simple_deploy status -n STACK_NAME -e ENVIRONMENT
|
20
|
+
simple_deploy attributes -n STACK_NAME -e ENVIRONMENT
|
21
|
+
simple_deploy events -n STACK_NAME -e ENVIRONMENT
|
22
|
+
simple_deploy resources -n STACK_NAME -e ENVIRONMENT
|
23
|
+
simple_deploy outputs -n STACK_NAME -e ENVIRONMENT
|
24
|
+
simple_deploy template -n STACK_NAME -e ENVIRONMENT
|
25
|
+
|
26
|
+
EOS
|
27
|
+
opt :help, "Display Help"
|
28
|
+
opt :attributes, "CSV list of updates attributes", :type => :string
|
29
|
+
opt :environment, "Set the target environment", :type => :string
|
30
|
+
opt :name, "Stack name to manage", :type => :string
|
31
|
+
opt :template, "Path to the template file", :type => :string
|
32
|
+
end
|
33
|
+
|
34
|
+
@cmd = ARGV.shift
|
35
|
+
|
36
|
+
unless @cmd
|
37
|
+
puts "Please specify a command."
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
read_attributes
|
42
|
+
|
43
|
+
unless @cmd == 'artifacts' || @cmd == 'environments'
|
44
|
+
@config = Config.new.environment(@opts[:environment])
|
45
|
+
unless environment_provided?
|
46
|
+
puts "Please specify an environment."
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
case @cmd
|
52
|
+
when 'create', 'delete', 'deploy', 'destroy', 'instances',
|
53
|
+
'status', 'attributes', 'events', 'resources',
|
54
|
+
'outputs', 'template', 'update'
|
55
|
+
@stack = Stack.new :environment => @opts[:environment],
|
56
|
+
:name => @opts[:name],
|
57
|
+
:config => @config
|
58
|
+
end
|
59
|
+
|
60
|
+
case @cmd
|
61
|
+
when 'attributes'
|
62
|
+
@stack.attributes.each_pair { |k, v| puts "#{k}: #{v}" }
|
63
|
+
when 'artifacts'
|
64
|
+
a = ArtifactLister.new
|
65
|
+
puts a.summary
|
66
|
+
when 'create'
|
67
|
+
@stack.create :attributes => attributes,
|
68
|
+
:template => @opts[:template]
|
69
|
+
puts "#{@opts[:name]} created."
|
70
|
+
when 'delete', 'destroy'
|
71
|
+
@stack.destroy
|
72
|
+
puts "#{@opts[:name]} destroyed."
|
73
|
+
when 'deploy'
|
74
|
+
@stack.deploy
|
75
|
+
puts "#{@opts[:name]} deployed."
|
76
|
+
when 'environments'
|
77
|
+
Config.new.environments.keys.each { |e| puts e }
|
78
|
+
when 'update'
|
79
|
+
@stack.update :attributes => attributes
|
80
|
+
puts "#{@opts[:name]} updated."
|
81
|
+
when 'instances'
|
82
|
+
@stack.instances.each { |s| puts s }
|
83
|
+
when 'list'
|
84
|
+
puts Stack.list(:config => @config)
|
85
|
+
when 'template'
|
86
|
+
jj @stack.template
|
87
|
+
when 'events', 'outputs', 'resources', 'status'
|
88
|
+
puts (@stack.send @cmd.to_sym).to_yaml
|
89
|
+
else
|
90
|
+
puts "Unknown command. Use -h for help."
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SimpleDeploy
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
load_config_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_config_file
|
11
|
+
config_file = "#{ENV['HOME']}/.simpledeploy.yml"
|
12
|
+
self.config = YAML::load( File.open( config_file ) )
|
13
|
+
end
|
14
|
+
|
15
|
+
def artifacts
|
16
|
+
config['roles']['default']['artifacts']
|
17
|
+
end
|
18
|
+
|
19
|
+
def keys
|
20
|
+
config['keys']
|
21
|
+
end
|
22
|
+
|
23
|
+
def user
|
24
|
+
config['user']
|
25
|
+
end
|
26
|
+
|
27
|
+
def deploy_script
|
28
|
+
config['roles']['default']['deploy_script']
|
29
|
+
end
|
30
|
+
|
31
|
+
def environments
|
32
|
+
config['environments']
|
33
|
+
end
|
34
|
+
|
35
|
+
def environment(name)
|
36
|
+
environments[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def region(name)
|
40
|
+
environment(name)['region']
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/cli'
|
3
|
+
|
4
|
+
module SimpleDeploy
|
5
|
+
class Deployment
|
6
|
+
def initialize(args)
|
7
|
+
@config = args[:config]
|
8
|
+
@instances = args[:instances]
|
9
|
+
@environment = args[:environment]
|
10
|
+
@attributes = args[:attributes]
|
11
|
+
|
12
|
+
@region = @config.region(@environment)
|
13
|
+
@deploy_script = @config.deploy_script
|
14
|
+
|
15
|
+
create_deployment
|
16
|
+
set_deploy_command
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute
|
20
|
+
@deployment.simpledeploy
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_deploy_command
|
26
|
+
cmd = ""
|
27
|
+
get_artifact_endpoints.each_pair do |k,v|
|
28
|
+
cmd += "env #{k}=#{v} "
|
29
|
+
end
|
30
|
+
cmd += @deploy_script
|
31
|
+
|
32
|
+
@deployment.load :string => "task :simpledeploy do
|
33
|
+
sudo '#{cmd}'
|
34
|
+
end"
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_artifact_endpoints
|
38
|
+
h = {}
|
39
|
+
@config.artifacts.each do |a|
|
40
|
+
name = a['name']
|
41
|
+
endpoint = a['endpoint']
|
42
|
+
artifact = Artifact.new :class => name,
|
43
|
+
:sha => @attributes[name],
|
44
|
+
:region => @region
|
45
|
+
h[name] = artifact.all_endpoints[endpoint]
|
46
|
+
end
|
47
|
+
h
|
48
|
+
end
|
49
|
+
|
50
|
+
def ssh_options
|
51
|
+
{
|
52
|
+
:keys => @config.keys,
|
53
|
+
:paranoid => false
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_deployment
|
58
|
+
@deployment = Capistrano::Configuration.new
|
59
|
+
@deployment.set :user, @config.user
|
60
|
+
@deployment.variables[:ssh_options] = ssh_options
|
61
|
+
@instances.each { |i| @deployment.server i, :instances }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
module SimpleDeploy
|
3
|
+
class StackReader
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@sf = Stackster::StackFormater.new args
|
7
|
+
@sr = Stackster::StackReader.new args
|
8
|
+
end
|
9
|
+
|
10
|
+
def attributes
|
11
|
+
@sf.attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def instances
|
15
|
+
@sf.instances_public_ip_addresses
|
16
|
+
end
|
17
|
+
|
18
|
+
def status
|
19
|
+
@sr.status
|
20
|
+
end
|
21
|
+
|
22
|
+
def events
|
23
|
+
@sr.events
|
24
|
+
end
|
25
|
+
|
26
|
+
def outputs
|
27
|
+
@sr.outputs
|
28
|
+
end
|
29
|
+
|
30
|
+
def resources
|
31
|
+
@sr.resources
|
32
|
+
end
|
33
|
+
|
34
|
+
def template
|
35
|
+
@sr.template
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'stackster'
|
2
|
+
require 'simple_deploy/stack/stack_reader'
|
3
|
+
require 'simple_deploy/stack/stack_lister'
|
4
|
+
|
5
|
+
module SimpleDeploy
|
6
|
+
class Stack
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@environment = args[:environment]
|
10
|
+
@name = args[:name]
|
11
|
+
@config = Config.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.list(args)
|
15
|
+
StackLister.new(:config => args[:config]).all
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(args)
|
19
|
+
stack.create :attributes => args[:attributes],
|
20
|
+
:template => args[:template]
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(args)
|
24
|
+
stack.update :attributes => args[:attributes]
|
25
|
+
end
|
26
|
+
|
27
|
+
def deploy
|
28
|
+
deployment = Deployment.new :config => @config,
|
29
|
+
:environment => @environment,
|
30
|
+
:instances => instances,
|
31
|
+
:attributes => attributes
|
32
|
+
deployment.execute
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
stack.destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
def events
|
40
|
+
stack.events
|
41
|
+
end
|
42
|
+
|
43
|
+
def outputs
|
44
|
+
stack.outputs
|
45
|
+
end
|
46
|
+
|
47
|
+
def resources
|
48
|
+
stack.resources
|
49
|
+
end
|
50
|
+
|
51
|
+
def instances
|
52
|
+
stack.instances_public_ip_addresses
|
53
|
+
end
|
54
|
+
|
55
|
+
def status
|
56
|
+
stack.status
|
57
|
+
end
|
58
|
+
|
59
|
+
def attributes
|
60
|
+
stack.attributes
|
61
|
+
end
|
62
|
+
|
63
|
+
def template
|
64
|
+
JSON.parse stack.template
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def stack
|
70
|
+
@stack ||= Stackster::Stack.new :environment => @environment,
|
71
|
+
:name => @name,
|
72
|
+
:config => @config.environment(@environment)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simple_deploy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simple_deploy"
|
7
|
+
s.version = SimpleDeploy::VERSION
|
8
|
+
s.authors = ["Brett Weaver"]
|
9
|
+
s.email = ["brett@weav.net"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{I help with deployments}
|
12
|
+
s.description = %q{Its what I do}
|
13
|
+
|
14
|
+
s.rubyforge_project = "simple_deploy"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
s.add_runtime_dependency "capistrano"
|
24
|
+
s.add_runtime_dependency "heirloom", '= 0.0.7'
|
25
|
+
s.add_runtime_dependency "stackster", '= 0.0.3'
|
26
|
+
s.add_runtime_dependency "trollop"
|
27
|
+
end
|
data/spec/config_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brett Weaver
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70245152037260 !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: *70245152037260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: capistrano
|
27
|
+
requirement: &70245152036580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70245152036580
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: heirloom
|
38
|
+
requirement: &70245152036000 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - =
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.7
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70245152036000
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: stackster
|
49
|
+
requirement: &70245152035460 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.3
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70245152035460
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: trollop
|
60
|
+
requirement: &70245152035040 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70245152035040
|
69
|
+
description: Its what I do
|
70
|
+
email:
|
71
|
+
- brett@weav.net
|
72
|
+
executables:
|
73
|
+
- simple_deploy
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rvmrc
|
79
|
+
- Gemfile
|
80
|
+
- Rakefile
|
81
|
+
- bin/simple_deploy
|
82
|
+
- lib/simple_deploy.rb
|
83
|
+
- lib/simple_deploy/artifact.rb
|
84
|
+
- lib/simple_deploy/artifact/artifact_lister.rb
|
85
|
+
- lib/simple_deploy/artifact/artifact_reader.rb
|
86
|
+
- lib/simple_deploy/cli.rb
|
87
|
+
- lib/simple_deploy/cli/variables.rb
|
88
|
+
- lib/simple_deploy/config.rb
|
89
|
+
- lib/simple_deploy/deployment.rb
|
90
|
+
- lib/simple_deploy/stack.rb
|
91
|
+
- lib/simple_deploy/stack/stack_lister.rb
|
92
|
+
- lib/simple_deploy/stack/stack_reader.rb
|
93
|
+
- lib/simple_deploy/version.rb
|
94
|
+
- simple_deploy.gemspec
|
95
|
+
- spec/config_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses: []
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 3040328796696586179
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: 3040328796696586179
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project: simple_deploy
|
123
|
+
rubygems_version: 1.8.16
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: I help with deployments
|
127
|
+
test_files:
|
128
|
+
- spec/config_spec.rb
|
129
|
+
- spec/spec_helper.rb
|