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 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
- Set the following env variables to your AWS credentials
7
+ Then set the following environment variables to your AWS credentials:
8
8
 
9
- AWS_SECRET_ACCESS_KEY
10
- AWS_ACCESS_KEY_ID
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
@@ -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
@@ -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
- create if @cmd == 'create'
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
- template
21
- status "Creating Stack"
22
- status "Name: #{@opts[:name]}"
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
- status("Deleting stack: #{@opts[:name]}.")
28
- @stack.delete(:name => @opts[:name])
23
+ @stack.delete
24
+ describe
29
25
  end
30
26
 
31
27
  def self.describe
32
- status(@stack.describe(:name => @opts[:name]).to_yaml)
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 "#{stack.to_yaml}"
41
+ status stack.to_yaml
38
42
  end
39
43
  end
40
44
 
41
- def self.template
42
- template = Template.new(:git_repo => @opts[:git_repo])
43
- status "Building Template"
44
- status "Attributes: #{@opts[:attributes]}"
45
- status "Resources: #{@opts[:resources]}"
46
- status "Output: #{@opts[:output]}"
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.downcase
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 "Executing #{@cmd} with following options:"
102
- status "#{@opts.to_yaml}"
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}\n") unless silent?
116
+ printf("#{msg}") unless silent?
115
117
  end
116
118
  end
117
119
  end
@@ -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
- @temp_repo_export_dir = args[:temp_repo_export_dir]
7
- @git_repo = args[:git_repo]
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(@temp_repo_export_dir, 0700)
12
- Git.export(@git_repo, @temp_repo_export_dir)
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(@temp_repo_export_dir)
19
+ FileUtils.remove_dir(temp_repo_export_dir)
17
20
  end
18
21
  end
19
22
  end
@@ -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 = AWS::CloudFormation::Stack.new
19
- stack.create(:name => args[:name], :body => contents)
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 delete(args)
23
- stack = AWS::CloudFormation::Stack.new
24
- stack.delete(:name => args[:name])
36
+ def events
37
+ @stack.events(:name => name).body["StackEvents"]
25
38
  end
26
39
 
27
- def describe(args)
28
- stack = AWS::CloudFormation::Stack.new
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
 
@@ -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
- @temp_repo_export_dir = "/tmp/repo-#{(0...8).map{65.+(rand(25)).chr}.join}"
10
- @git_repo = args[:git_repo]
11
- @repo = Repo.new(:git_repo => @git_repo,
12
- :temp_repo_export_dir => @temp_repo_export_dir)
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(args)
21
+ def build
16
22
  begin
17
- export_git_repo if @git_repo
18
- load_attributes(args[:attributes])
23
+ export_git_repo if git_repo
24
+ load_attributes
19
25
  load_data
20
- load_resources(args[:resources])
21
- create_template(args[:output])
26
+ load_resources
27
+ create_template
22
28
  ensure
23
- remove_git_repo if @git_repo
29
+ remove_git_repo if git_repo
24
30
  end
25
31
  end
26
32
 
27
33
  private
28
34
 
29
- def load_attributes(attributes_file)
30
- template = IO.read("#{@temp_repo_export_dir}/attributes/#{attributes_file}")
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
- attributes = JSON.parse(attributes_json)
33
- @data = attributes['data']
34
- @resources = attributes['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 = "#{@temp_repo_export_dir}/data"
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(resource_template_file)
50
- resource_template = IO.read("#{@temp_repo_export_dir}/resources/#{resource_template_file}")
51
- @resources = ERB.new(resource_template).result(binding)
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(output)
55
- output_file = File.new(output,'w')
56
- output_file.puts @resources
57
- output_file.close
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
@@ -1,3 +1,3 @@
1
1
  module Stacker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-09 00:00:00.000000000 -08:00
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: &79634830 !ruby/object:Gem::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: *79634830
25
+ version_requirements: *84986040
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: fog
28
- requirement: &79634620 !ruby/object:Gem::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: *79634620
36
+ version_requirements: *84985830
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: git
39
- requirement: &79634410 !ruby/object:Gem::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: *79634410
47
+ version_requirements: *84985620
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: json
50
- requirement: &79634200 !ruby/object:Gem::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: *79634200
58
+ version_requirements: *84985410
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: trollop
61
- requirement: &79633990 !ruby/object:Gem::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: *79633990
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: