stacker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -5
- data/lib/stacker/aws.rb +8 -0
- data/lib/stacker/cli.rb +42 -40
- data/lib/stacker/repo.rb +8 -5
- data/lib/stacker/stack.rb +20 -8
- data/lib/stacker/template.rb +31 -23
- data/lib/stacker/version.rb +1 -1
- metadata +12 -12
data/README.md
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
-
Stacker like to build full application stacks.
|
1
|
+
Stacker like to build full application stacks. Creates cloud formation templates from a set of attributes, resource templates and data files.
|
2
2
|
|
3
|
-
Getting started
|
3
|
+
Getting started, first get the gem
|
4
4
|
|
5
5
|
gem install stacker
|
6
6
|
|
7
|
-
|
7
|
+
Then set the following environment variables to your AWS credentials:
|
8
8
|
|
9
|
-
AWS_SECRET_ACCESS_KEY
|
10
|
-
|
9
|
+
export AWS_SECRET_ACCESS_KEY='my aws secret key'
|
10
|
+
|
11
|
+
export AWS_ACCESS_KEY_ID='my aws access key'
|
12
|
+
|
13
|
+
export STACKER_DEFAULT_KEY='the name of my ssh key in AWS'
|
14
|
+
|
15
|
+
Create your first stack from our repository
|
16
|
+
|
17
|
+
stacker create -g git@github.com:brettweavnet/stacker-repo.git -n my-new-app
|
18
|
+
|
19
|
+
You can then see the status on the stack build
|
20
|
+
|
21
|
+
stacker describe -n my_new_app
|
data/lib/stacker/aws.rb
CHANGED
@@ -24,6 +24,14 @@ module Stacker
|
|
24
24
|
@connect.describe_stacks('StackName' => args[:name])
|
25
25
|
end
|
26
26
|
|
27
|
+
def events(args)
|
28
|
+
@connect.describe_stack_events(args[:name])
|
29
|
+
end
|
30
|
+
|
31
|
+
def resources(args)
|
32
|
+
@connect.describe_stack_resources('StackName' => args[:name])
|
33
|
+
end
|
34
|
+
|
27
35
|
private
|
28
36
|
|
29
37
|
def self.connect
|
data/lib/stacker/cli.rb
CHANGED
@@ -6,68 +6,60 @@ module Stacker
|
|
6
6
|
def self.start
|
7
7
|
read_variables
|
8
8
|
|
9
|
-
@stack = Stack.new
|
9
|
+
@stack = Stack.new(:name => @opts[:name])
|
10
10
|
|
11
11
|
explain if verbose?
|
12
12
|
|
13
|
-
|
14
|
-
describe if @cmd == 'describe'
|
15
|
-
delete if @cmd == 'delete'
|
16
|
-
list if @cmd == 'list'
|
13
|
+
self.send @cmd
|
17
14
|
end
|
18
15
|
|
19
16
|
def self.create
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@stack.create(:name => @opts[:name], :template => @opts[:output])
|
17
|
+
build_template
|
18
|
+
@stack.create(:template => @opts[:output])
|
19
|
+
describe
|
24
20
|
end
|
25
21
|
|
26
22
|
def self.delete
|
27
|
-
|
28
|
-
|
23
|
+
@stack.delete
|
24
|
+
describe
|
29
25
|
end
|
30
26
|
|
31
27
|
def self.describe
|
32
|
-
status
|
28
|
+
status @stack.describe.to_yaml
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.events
|
32
|
+
status @stack.events.to_yaml
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.resources
|
36
|
+
status @stack.resources.to_yaml
|
33
37
|
end
|
34
38
|
|
35
39
|
def self.list
|
36
40
|
Stack.list.each do |stack|
|
37
|
-
status
|
41
|
+
status stack.to_yaml
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
def self.
|
42
|
-
template = Template.new(:git_repo => @opts[:git_repo]
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
template.build(:attributes => @opts[:attributes],
|
49
|
-
:output => @opts[:output],
|
50
|
-
:resources => @opts[:resources])
|
45
|
+
def self.build_template
|
46
|
+
template = Template.new(:git_repo => @opts[:git_repo],
|
47
|
+
:attributes => @opts[:attributes],
|
48
|
+
:output => @opts[:output],
|
49
|
+
:path => @opts[:path],
|
50
|
+
:resources => @opts[:resources])
|
51
|
+
template.build
|
51
52
|
end
|
52
53
|
|
53
54
|
def self.read_variables
|
54
55
|
@cmd = ARGV.shift
|
55
56
|
|
56
|
-
@opts = case @cmd
|
57
|
-
when "template"
|
58
|
-
Trollop::options do
|
59
|
-
opt :attributes, "Attributes definition file", :default => 'attributes.json.erb'
|
60
|
-
opt :git_repo, "Git repository to export.", :default => 'git@github.com:brettweavnet/stacker-repo.git'
|
61
|
-
opt :output, "Template output file.", :default => 'stack.json'
|
62
|
-
opt :resources, "Resource definition file", :default => 'resources.json.erb'
|
63
|
-
opt :silent, "Silent mode.", :default => false
|
64
|
-
opt :temp_dir, "Directory to export configuration git repo.", :default => File.join(Dir.home, "stack-repo")
|
65
|
-
opt :verbose, "Verbose mode.", :default => false
|
66
|
-
end
|
57
|
+
@opts = case @cmd
|
67
58
|
when "create"
|
68
59
|
Trollop::options do
|
69
60
|
opt :attributes, "Attributes definition file", :default => 'attributes.json.erb'
|
70
|
-
opt :git_repo, "Git repository to export.", :default => 'git@github.com:brettweavnet/stacker-repo.git'
|
61
|
+
opt :git_repo, "Git repository to export.", :type => String #:default => 'git@github.com:brettweavnet/stacker-repo.git'
|
62
|
+
opt :path, "Path to configuraiton repo. If a -g or --git_repo is specified, it will override this setting.", :type => String
|
71
63
|
opt :name, "Name of stack to create.", :type => String
|
72
64
|
opt :output, "Template output file.", :default => 'stack.json'
|
73
65
|
opt :resources, "Resource definition file", :default => 'resources.json.erb'
|
@@ -86,20 +78,30 @@ module Stacker
|
|
86
78
|
opt :name, "Name of stack to describe.", :type => String
|
87
79
|
opt :verbose, "Verbose mode.", :default => false
|
88
80
|
end
|
81
|
+
when "events"
|
82
|
+
Trollop::options do
|
83
|
+
opt :name, "Name of stack who's events to display.", :type => String
|
84
|
+
opt :verbose, "Verbose mode.", :default => false
|
85
|
+
end
|
89
86
|
when "list"
|
90
87
|
Trollop::options do
|
91
88
|
opt :verbose, "Verbose mode.", :default => false
|
92
89
|
end
|
90
|
+
when "resources"
|
91
|
+
Trollop::options do
|
92
|
+
opt :name, "Name of stack who's resources to display.", :type => String
|
93
|
+
opt :verbose, "Verbose mode.", :default => false
|
94
|
+
end
|
93
95
|
else
|
94
|
-
status "\nUnknown command: '#{@cmd}'
|
95
|
-
status "\nstacker [create|describe|delete|list] --help"
|
96
|
+
status "\nUnknown command: '#{@cmd}'.\n"
|
97
|
+
status "\nstacker [create|describe|delete|list] --help\n"
|
96
98
|
exit 1
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
102
|
def self.explain
|
101
|
-
status "
|
102
|
-
status
|
103
|
+
status "\nExecuting #{@cmd} with following options:\n\n"
|
104
|
+
status @opts.to_yaml
|
103
105
|
end
|
104
106
|
|
105
107
|
def self.verbose?
|
@@ -111,7 +113,7 @@ module Stacker
|
|
111
113
|
end
|
112
114
|
|
113
115
|
def self.status(msg)
|
114
|
-
printf("#{msg}
|
116
|
+
printf("#{msg}") unless silent?
|
115
117
|
end
|
116
118
|
end
|
117
119
|
end
|
data/lib/stacker/repo.rb
CHANGED
@@ -2,18 +2,21 @@ require "git"
|
|
2
2
|
|
3
3
|
module Stacker
|
4
4
|
class Repo
|
5
|
+
|
6
|
+
attr_accessor :git_repo, :temp_repo_export_dir
|
7
|
+
|
5
8
|
def initialize(args)
|
6
|
-
|
7
|
-
|
9
|
+
self.git_repo = args[:git_repo]
|
10
|
+
self.temp_repo_export_dir = "/tmp/repo-#{(0...8).map{65.+(rand(25)).chr}.join}"
|
8
11
|
end
|
9
12
|
|
10
13
|
def export
|
11
|
-
Dir.mkdir(
|
12
|
-
Git.export(
|
14
|
+
Dir.mkdir(temp_repo_export_dir, 0700)
|
15
|
+
Git.export(git_repo, temp_repo_export_dir)
|
13
16
|
end
|
14
17
|
|
15
18
|
def remove
|
16
|
-
FileUtils.remove_dir(
|
19
|
+
FileUtils.remove_dir(temp_repo_export_dir)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/stacker/stack.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Stacker
|
2
2
|
|
3
3
|
class Stack
|
4
|
+
attr_accessor :name
|
5
|
+
|
4
6
|
def self.list
|
5
7
|
list = []
|
6
8
|
|
@@ -12,21 +14,31 @@ module Stacker
|
|
12
14
|
list
|
13
15
|
end
|
14
16
|
|
17
|
+
def initialize(args={})
|
18
|
+
self.name = args[:name] if args[:name]
|
19
|
+
@stack = AWS::CloudFormation::Stack.new
|
20
|
+
end
|
21
|
+
|
15
22
|
def create(args)
|
16
23
|
file = File.open(args[:template], "rb")
|
17
24
|
contents = file.read
|
18
|
-
stack
|
19
|
-
|
25
|
+
@stack.create(:name => name, :body => contents)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete
|
29
|
+
@stack.delete(:name => name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def describe
|
33
|
+
@stack.describe(:name => name).body["Stacks"].first
|
20
34
|
end
|
21
35
|
|
22
|
-
def
|
23
|
-
stack
|
24
|
-
stack.delete(:name => args[:name])
|
36
|
+
def events
|
37
|
+
@stack.events(:name => name).body["StackEvents"]
|
25
38
|
end
|
26
39
|
|
27
|
-
def
|
28
|
-
stack
|
29
|
-
stack.describe(:name => args[:name]).body.first
|
40
|
+
def resources
|
41
|
+
@stack.resources(:name => name).body["StackResources"]
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
data/lib/stacker/template.rb
CHANGED
@@ -5,37 +5,43 @@ module Stacker
|
|
5
5
|
|
6
6
|
class Template
|
7
7
|
|
8
|
+
attr_accessor :attributes_file, :git_repo, :output_file,
|
9
|
+
:repo_path, :resources_file
|
10
|
+
|
8
11
|
def initialize(args)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
self.attributes_file = args[:attributes]
|
13
|
+
self.git_repo = args[:git_repo]
|
14
|
+
self.output_file = args[:output]
|
15
|
+
self.repo_path = args[:path]
|
16
|
+
self.resources_file = args[:resources]
|
17
|
+
|
18
|
+
@repo = Repo.new(:git_repo => git_repo)
|
13
19
|
end
|
14
20
|
|
15
|
-
def build
|
21
|
+
def build
|
16
22
|
begin
|
17
|
-
export_git_repo if
|
18
|
-
load_attributes
|
23
|
+
export_git_repo if git_repo
|
24
|
+
load_attributes
|
19
25
|
load_data
|
20
|
-
load_resources
|
21
|
-
create_template
|
26
|
+
load_resources
|
27
|
+
create_template
|
22
28
|
ensure
|
23
|
-
remove_git_repo if
|
29
|
+
remove_git_repo if git_repo
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
33
|
private
|
28
34
|
|
29
|
-
def load_attributes
|
30
|
-
template = IO.read("#{
|
35
|
+
def load_attributes
|
36
|
+
template = IO.read("#{repo_path}/attributes/#{attributes_file}")
|
31
37
|
attributes_json = ERB.new(template).result(binding).to_s
|
32
|
-
|
33
|
-
@data =
|
34
|
-
@resources =
|
38
|
+
parsed_attributes = JSON.parse(attributes_json)
|
39
|
+
@data = parsed_attributes['data']
|
40
|
+
@resources = parsed_attributes['resources']
|
35
41
|
end
|
36
42
|
|
37
43
|
def load_data
|
38
|
-
data_dir = "#{
|
44
|
+
data_dir = "#{repo_path}/data"
|
39
45
|
|
40
46
|
Dir.entries(data_dir).each do |data_file|
|
41
47
|
if data_file =~ /.erb$/
|
@@ -46,24 +52,26 @@ module Stacker
|
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
|
-
def load_resources
|
50
|
-
resource_template = IO.read("#{
|
51
|
-
|
55
|
+
def load_resources
|
56
|
+
resource_template = IO.read("#{repo_path}/resources/#{resources_file}")
|
57
|
+
ERB.new(resource_template).result(binding)
|
52
58
|
end
|
53
59
|
|
54
|
-
def create_template
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
def create_template
|
61
|
+
output_file_handle = File.new(output_file,'w')
|
62
|
+
output_file_handle.puts load_resources
|
63
|
+
output_file_handle.close
|
58
64
|
end
|
59
65
|
|
60
66
|
def export_git_repo
|
61
67
|
@repo.export
|
68
|
+
self.repo_path = @repo.temp_repo_export_dir
|
62
69
|
end
|
63
70
|
|
64
71
|
def remove_git_repo
|
65
72
|
@repo.remove
|
66
73
|
end
|
74
|
+
|
67
75
|
end
|
68
76
|
|
69
77
|
end
|
data/lib/stacker/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stacker
|
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,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-10 00:00:00.000000000 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &84986040 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *84986040
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: fog
|
28
|
-
requirement: &
|
28
|
+
requirement: &84985830 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *84985830
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: git
|
39
|
-
requirement: &
|
39
|
+
requirement: &84985620 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *84985620
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: json
|
50
|
-
requirement: &
|
50
|
+
requirement: &84985410 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *84985410
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: trollop
|
61
|
-
requirement: &
|
61
|
+
requirement: &84985200 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *84985200
|
70
70
|
description: stacker integrates with git and AWS cloud formation to rapidley build
|
71
71
|
full application stacks from dynamic templates
|
72
72
|
email:
|