gantree 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39f114ba81d91840e2fef5d57423b1c40c926c9d
4
- data.tar.gz: 160d2693dac88a610b48fe3a1dac457bf81877c6
3
+ metadata.gz: 55707434983d9a6fb3e92ceb5e6479cef04b7ebf
4
+ data.tar.gz: aa9014c25226ca29d04ed98ec1b0181c0b1fbe07
5
5
  SHA512:
6
- metadata.gz: 20ca6f938c503b9305ff44083088c1b98014484ab828c91f862db19f0101cd2afab2bec944ffdb38d4bfabca8aa1e9ed629e0e23abdce3cdcdfd20b0eed5e811
7
- data.tar.gz: 0c16d2039823e005fe96bae6ca5f9785adaa51c180d58fc1c0d1f20cbc56fa4bf440d949fbe5d3b056e4bab7fde7f35b475a4a95785da4d790a1fb2a11e06f02
6
+ metadata.gz: 9372ab0fa8f27dd9d7578717872fecc93b54e1fedfec1839d9cedb79c32c983e954108127453dbf7251f45e2aabbd617d4a6cb725d038cf10ebae9d777376cf8
7
+ data.tar.gz: da4954bce0ce6cd070b96861e35ca579367c7261c98a911843162858317145f04b2ede5aaf5cbb8f8b343c1197531af0ced596fd6f1280aac3b64d35832ce9ad
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gem "guard", group: :test
7
7
  gem "rspec", group: :test
8
8
  gem "rake"
9
9
  gem "guard-rspec", require: false
10
- gem "webmock"
10
+ gem "webmock"
11
+ gem "cloudformation-ruby-dsl"
@@ -9,11 +9,14 @@ GEM
9
9
  nokogiri (>= 1.4.4)
10
10
  celluloid (0.15.2)
11
11
  timers (~> 1.1.0)
12
+ cloudformation-ruby-dsl (0.4.6)
13
+ detabulator
12
14
  codeclimate-test-reporter (0.4.0)
13
15
  simplecov (>= 0.7.1, < 1.0.0)
14
16
  coderay (1.1.0)
15
17
  crack (0.4.2)
16
18
  safe_yaml (~> 1.0.0)
19
+ detabulator (0.1.0)
17
20
  diff-lcs (1.2.5)
18
21
  docile (1.1.5)
19
22
  ffi (1.9.3)
@@ -76,6 +79,7 @@ PLATFORMS
76
79
 
77
80
  DEPENDENCIES
78
81
  aws-sdk
82
+ cloudformation-ruby-dsl
79
83
  codeclimate-test-reporter
80
84
  guard
81
85
  guard-rspec
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- equire "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
4
  task :default => :spec
@@ -0,0 +1,311 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "Knarr Service Parent Template (2014-08-15)",
4
+ "Mappings": {
5
+ "LongName": {
6
+ "stag": {
7
+ "name": "staging"
8
+ },
9
+ "prod": {
10
+ "name": "production"
11
+ }
12
+ },
13
+ "HostedZoneName": {
14
+ "stag": {
15
+ "name": "sbleacherreport.com"
16
+ },
17
+ "prod": {
18
+ "name": "bleacherreport.com"
19
+ }
20
+ }
21
+ },
22
+ "Parameters": {
23
+ "KeyName": {
24
+ "Description": "The Key Pair to launch instances with",
25
+ "Type": "String",
26
+ "Default": "default"
27
+ },
28
+ "InstanceSecurityGroup": {
29
+ "Type": "String"
30
+ },
31
+ "InstanceType": {
32
+ "Description": "EC2 Instance Type",
33
+ "Type": "String",
34
+ "AllowedValues": [
35
+ "t1.micro",
36
+ "m1.small",
37
+ "m3.medium",
38
+ "m3.large",
39
+ "m3.xlarge",
40
+ "m3.2xlarge",
41
+ "c3.large",
42
+ "c3.xlarge",
43
+ "c3.2xlarge",
44
+ "c3.4xlarge",
45
+ "c3.8xlarge"
46
+ ],
47
+ "Default": "m3.large"
48
+ },
49
+ "ApplicationName": {
50
+ "Description": "The name of the Elastic Beanstalk Application",
51
+ "Type": "String",
52
+ "Default": "knarr"
53
+ },
54
+ "Environment": {
55
+ "Type": "String"
56
+ },
57
+ "IamInstanceProfile": {
58
+ "Type": "String",
59
+ "Default": "EbApp"
60
+ }
61
+ },
62
+ "Resources": {
63
+ "Application": {
64
+ "Type": "AWS::ElasticBeanstalk::Application",
65
+ "Properties": {
66
+ "Description": {
67
+ "Ref": "ApplicationName"
68
+ },
69
+ "ApplicationName": {
70
+ "Fn::Join": [
71
+ "-",
72
+ [
73
+ {
74
+ "Ref": "ApplicationName"
75
+ },
76
+ {
77
+ "Ref": "Environment"
78
+ }
79
+ ]
80
+ ]
81
+ }
82
+ }
83
+ },
84
+ "ApplicationVersion": {
85
+ "Type": "AWS::ElasticBeanstalk::ApplicationVersion",
86
+ "Properties": {
87
+ "ApplicationName": {
88
+ "Ref": "Application"
89
+ },
90
+ "Description": "Initial Version",
91
+ "SourceBundle": {
92
+ "S3Bucket": "br-repos",
93
+ "S3Key": {
94
+ "Fn::Join": [
95
+ "",
96
+ [
97
+ {
98
+ "Ref": "ApplicationName"
99
+ },
100
+ "-",
101
+ {
102
+ "Ref": "Environment"
103
+ },
104
+ ".zip"
105
+ ]
106
+ ]
107
+ }
108
+ }
109
+ }
110
+ },
111
+ "ConfigurationTemplate": {
112
+ "Type": "AWS::ElasticBeanstalk::ConfigurationTemplate",
113
+ "Properties": {
114
+ "ApplicationName": {
115
+ "Ref": "Application"
116
+ },
117
+ "SolutionStackName": "64bit Amazon Linux 2014.03 v1.0.1 running Docker 1.0.0",
118
+ "Description": "Default Configuration Version 1.0 - with SSH access",
119
+ "OptionSettings": [
120
+ {
121
+ "Namespace": "aws:elasticbeanstalk:application:environment",
122
+ "OptionName": "AWS_REGION",
123
+ "Value": "us-east-1"
124
+ },
125
+ {
126
+ "Namespace": "aws:elasticbeanstalk:application:environment",
127
+ "OptionName": "RACK_ENV",
128
+ "Value": {
129
+ "Fn::FindInMap": [
130
+ "LongName",
131
+ {
132
+ "Ref": "Environment"
133
+ },
134
+ "name"
135
+ ]
136
+ }
137
+ },
138
+ {
139
+ "Namespace": "aws:autoscaling:launchconfiguration",
140
+ "OptionName": "EC2KeyName",
141
+ "Value": {
142
+ "Ref": "KeyName"
143
+ }
144
+ },
145
+ {
146
+ "Namespace": "aws:autoscaling:launchconfiguration",
147
+ "OptionName": "IamInstanceProfile",
148
+ "Value": {
149
+ "Ref": "IamInstanceProfile"
150
+ }
151
+ },
152
+ {
153
+ "Namespace": "aws:autoscaling:launchconfiguration",
154
+ "OptionName": "InstanceType",
155
+ "Value": {
156
+ "Ref": "InstanceType"
157
+ }
158
+ },
159
+ {
160
+ "Namespace": "aws:autoscaling:launchconfiguration",
161
+ "OptionName": "SecurityGroups",
162
+ "Value": {
163
+ "Fn::Join": [
164
+ ",",
165
+ [
166
+ {
167
+ "Fn::Join": [
168
+ "-",
169
+ [
170
+ {
171
+ "Ref": "Environment"
172
+ },
173
+ "br"
174
+ ]
175
+ ]
176
+ },
177
+ {
178
+ "Ref": "InstanceSecurityGroup"
179
+ }
180
+ ]
181
+ ]
182
+ }
183
+ },
184
+ {
185
+ "Namespace": "aws:autoscaling:updatepolicy:rollingupdate",
186
+ "OptionName": "RollingUpdateEnabled",
187
+ "Value": "true"
188
+ },
189
+ {
190
+ "Namespace": "aws:autoscaling:updatepolicy:rollingupdate",
191
+ "OptionName": "MaxBatchSize",
192
+ "Value": "1"
193
+ },
194
+ {
195
+ "Namespace": "aws:autoscaling:updatepolicy:rollingupdate",
196
+ "OptionName": "MinInstancesInService",
197
+ "Value": "2"
198
+ },
199
+ {
200
+ "Namespace": "aws:elasticbeanstalk:hostmanager",
201
+ "OptionName": "LogPublicationControl",
202
+ "Value": "true"
203
+ }
204
+ ]
205
+ }
206
+ },
207
+ "EbEnvironment": {
208
+ "Type": "AWS::ElasticBeanstalk::Environment",
209
+ "Properties": {
210
+ "ApplicationName": {
211
+ "Ref": "Application"
212
+ },
213
+ "EnvironmentName": {
214
+ "Fn::Join": [
215
+ "-",
216
+ [
217
+ {
218
+ "Ref": "Environment"
219
+ },
220
+ {
221
+ "Ref": "ApplicationName"
222
+ },
223
+ "app"
224
+ ]
225
+ ]
226
+ },
227
+ "Description": "Default Environment",
228
+ "VersionLabel": {
229
+ "Ref": "ApplicationVersion"
230
+ },
231
+ "TemplateName": {
232
+ "Ref": "ConfigurationTemplate"
233
+ },
234
+ "OptionSettings": [
235
+
236
+ ]
237
+ }
238
+ },
239
+ "HostRecord": {
240
+ "Type": "AWS::Route53::RecordSet",
241
+ "Properties": {
242
+ "Comment": "DNS name for my stack",
243
+ "HostedZoneName": {
244
+ "Fn::Join": [
245
+ "",
246
+ [
247
+ {
248
+ "Fn::FindInMap": [
249
+ "HostedZoneName",
250
+ {
251
+ "Ref": "Environment"
252
+ },
253
+ "name"
254
+ ]
255
+ },
256
+ "."
257
+ ]
258
+ ]
259
+ },
260
+ "Name": {
261
+ "Fn::Join": [
262
+ ".",
263
+ [
264
+ {
265
+ "Ref": "ApplicationName"
266
+ },
267
+ {
268
+ "Fn::FindInMap": [
269
+ "HostedZoneName",
270
+ {
271
+ "Ref": "Environment"
272
+ },
273
+ "name"
274
+ ]
275
+ }
276
+ ]
277
+ ]
278
+ },
279
+ "ResourceRecords": [
280
+ {
281
+ "Fn::GetAtt": [
282
+ "EbEnvironment",
283
+ "EndpointURL"
284
+ ]
285
+ }
286
+ ],
287
+ "TTL": "60",
288
+ "Type": "CNAME"
289
+ }
290
+ }
291
+ },
292
+ "Outputs": {
293
+ "URL": {
294
+ "Description": "URL of the AWS Elastic Beanstalk Environment",
295
+ "Value": {
296
+ "Fn::Join": [
297
+ "",
298
+ [
299
+ "http://",
300
+ {
301
+ "Fn::GetAtt": [
302
+ "EbEnvironment",
303
+ "EndpointURL"
304
+ ]
305
+ }
306
+ ]
307
+ ]
308
+ }
309
+ }
310
+ }
311
+ }
@@ -0,0 +1,113 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "stag-knarr-app-s3 Master Template",
4
+ "Parameters": {
5
+ "ResourcesTemplate": {
6
+ "Description": "The key of the template for the resources required to run the app",
7
+ "Type": "String",
8
+ "Default": "stag-knarr-app-s3-resources.cfn.json"
9
+ },
10
+ "AppTemplate": {
11
+ "Description": "The key of the template for the EB app/env substack",
12
+ "Type": "String",
13
+ "Default": "stag-knarr-app-s3-elasticbeanstalk.cfn.json"
14
+ },
15
+ "KeyName": {
16
+ "Default": "default"
17
+ },
18
+ "InstanceType": {
19
+ "Type": "String",
20
+ "Default": "t1.micro"
21
+ },
22
+ "ApplicationName": {
23
+ "Type": "String"
24
+ },
25
+ "Environment": {
26
+ "Type": "String",
27
+ "Default": "knarr-stag-s3"
28
+ },
29
+ "IamInstanceProfile": {
30
+ "Type": "String",
31
+ "Default": "EbApp"
32
+ }
33
+ },
34
+ "Resources": {
35
+ "AppResources": {
36
+ "Type": "AWS::CloudFormation::Stack",
37
+ "Properties": {
38
+ "TemplateURL": {
39
+ "Fn::Join": [
40
+ "/",
41
+ [
42
+ "http://s3.amazonaws.com/br-templates",
43
+ {
44
+ "Ref": "ApplicationName"
45
+ },
46
+ {
47
+ "Ref": "ResourcesTemplate"
48
+ }
49
+ ]
50
+ ]
51
+ },
52
+ "Parameters": {
53
+ "ApplicationName": {
54
+ "Ref": "ApplicationName"
55
+ }
56
+ }
57
+ }
58
+ },
59
+ "App": {
60
+ "Type": "AWS::CloudFormation::Stack",
61
+ "Properties": {
62
+ "TemplateURL": {
63
+ "Fn::Join": [
64
+ "/",
65
+ [
66
+ "http://s3.amazonaws.com/",
67
+ {
68
+ "Ref": "ApplicationName"
69
+ },
70
+ {
71
+ "Ref": "AppTemplate"
72
+ }
73
+ ]
74
+ ]
75
+ },
76
+ "Parameters": {
77
+ "KeyName": {
78
+ "Ref": "KeyName"
79
+ },
80
+ "InstanceSecurityGroup": {
81
+ "Fn::GetAtt": [
82
+ "AppResources",
83
+ "Outputs.InstanceSecurityGroup"
84
+ ]
85
+ },
86
+ "InstanceType": {
87
+ "Ref": "InstanceType"
88
+ },
89
+ "ApplicationName": {
90
+ "Ref": "ApplicationName"
91
+ },
92
+ "Environment": {
93
+ "Ref": "Environment"
94
+ },
95
+ "IamInstanceProfile": {
96
+ "Ref": "IamInstanceProfile"
97
+ }
98
+ }
99
+ }
100
+ }
101
+ },
102
+ "Outputs": {
103
+ "URL": {
104
+ "Description": "URL of the AWS Elastic Beanstalk Environment",
105
+ "Value": {
106
+ "Fn::GetAtt": [
107
+ "App",
108
+ "Outputs.URL"
109
+ ]
110
+ }
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "knarr-stag-s3 Services Resources (2014-06-30)",
4
+ "Parameters": {
5
+ "ApplicationName": {
6
+ "Type": "String",
7
+ "Default": {
8
+ "Ref": "ApplicationName"
9
+ }
10
+ }
11
+ },
12
+ "Resources": {
13
+ "InstanceSecurityGroup": {
14
+ "Type": "AWS::EC2::SecurityGroup",
15
+ "Properties": {
16
+ "GroupDescription": {
17
+ "Fn::Join": [
18
+ "",
19
+ [
20
+ "an EC2 instance security group created for ",
21
+ {
22
+ "Ref": "ApplicationName"
23
+ }
24
+ ]
25
+ ]
26
+ },
27
+ "SecurityGroupIngress": [
28
+
29
+ ]
30
+ }
31
+ }
32
+ },
33
+ "Outputs": {
34
+ "InstanceSecurityGroup": {
35
+ "Value": {
36
+ "Ref": "InstanceSecurityGroup"
37
+ }
38
+ }
39
+ }
40
+ }
@@ -2,6 +2,7 @@ $:.unshift(File.expand_path("../", __FILE__))
2
2
  require "gantree/version"
3
3
  require "gantree/deploy"
4
4
  require "gantree/init"
5
+ require "gantree/cfn"
5
6
 
6
7
  module Gantree
7
8
  autoload :CLI, 'gantree/cli'
@@ -0,0 +1,66 @@
1
+ require 'cloudformation-ruby-dsl'
2
+ require_relative 'cfn/master'
3
+ require_relative 'cfn/beanstalk'
4
+ require_relative 'cfn/resources'
5
+
6
+ module Gantree
7
+ class Stack
8
+ def initialize stack_name,options
9
+ AWS.config(
10
+ :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
11
+ :secret_access_key => ENV['AWS_SECRET_ACCES_KEY'])
12
+ @s3 = AWS::S3.new
13
+ @requirements = "#!/usr/bin/env ruby
14
+ require 'bundler/setup'
15
+ require 'cloudformation-ruby-dsl/cfntemplate'
16
+ require 'cloudformation-ruby-dsl/spotprice'
17
+ require 'cloudformation-ruby-dsl/table'"
18
+ @stack_name = stack_name
19
+ @env = options[:env] || stack_name.match(/^[a-zA-Z]*\-([a-zA-Z]*)\-[a-zA-Z]*\-([a-zA-Z]*\d*)/)[1] + "-" + stack_name.match(/^([a-zA-Z]*)\-([a-zA-Z]*)\-[a-zA-Z]*\-([a-zA-Z]*\d*)/)[1] + '-' + stack_name.match(/^([a-zA-Z]*)\-([a-zA-Z]*)\-[a-zA-Z]*\-([a-zA-Z]*\d*)/)[3]
20
+ @params = {
21
+ stack_name: @stack_name,
22
+ requirements: @requirements,
23
+ cfn_bucket: "br-templates",
24
+ env: @env
25
+ }
26
+ end
27
+
28
+ def create
29
+ generate("master", MasterTemplate.new(@params).create)
30
+ generate("beanstalk", BeanstalkTemplate.new(@params).create)
31
+ generate("resources", ResourcesTemplate.new(@params).create)
32
+ end
33
+
34
+ def generate(template_name, template)
35
+ IO.write("cfn/#{template_name}.rb", template)
36
+ json = `ruby cfn/#{template_name}.rb expand`
37
+ Dir.mkdir 'cfn' rescue Errno::ENOENT
38
+ template_file_name = "#{@params[:env]}-#{template_name}.cfn.json"
39
+ IO.write("cfn/#{template_file_name}", json)
40
+ puts "Created #{template_file_name} in the cfn directory"
41
+ FileUtils.rm("cfn/#{template_name}.rb")
42
+ upload_template_to_s3("cfn/#{template_file_name}")
43
+ end
44
+
45
+ def upload_template_to_s3(filename)
46
+ begin
47
+ puts "uploading cfn template to #{@params[:cfn_bucket]}/#{@env}"
48
+ key = File.basename(filename)
49
+ @s3.buckets["#{@params[:cfn_bucket]}/#{@env}"].objects[key].write(:file => filename)
50
+ rescue AWS::S3::Errors::NoSuchBucket
51
+ puts "bucket didn't exist...creating"
52
+ bucket = @s3.buckets.create("#{@params[:cfn_bucket]}/#{@env}")
53
+ retry
54
+ rescue AWS::S3::Errors::AccessDenied
55
+ puts "Your key is not configured for s3 access, please let your operations team know"
56
+ end
57
+ end
58
+
59
+ def create_aws_cfn_stack
60
+ puts "Creating stack on aws..."
61
+ cfm = AWS::CloudFormation.new
62
+ stack = cfm.stacks.create(stack_name, template)
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,132 @@
1
+ class BeanstalkTemplate
2
+
3
+ def initialize params
4
+ @stack_name = params[:stack_name]
5
+ @env = params[:env]
6
+ @requirements = params[:requirements]
7
+ end
8
+
9
+ def create
10
+ "#{@requirements}
11
+ template do
12
+
13
+ value :AWSTemplateFormatVersion => '2010-09-09'
14
+
15
+ value :Description => '#{@env} Service Parent Template (2014-08-15)'
16
+
17
+ mapping 'LongName',
18
+ :stag => { :name => 'staging' },
19
+ :prod => { :name => 'production' }
20
+
21
+ mapping 'HostedZoneName',
22
+ :stag => { :name => 'sbleacherreport.com' },
23
+ :prod => { :name => 'bleacherreport.com' }
24
+
25
+ parameter 'KeyName',
26
+ :Description => 'The Key Pair to launch instances with',
27
+ :Type => 'String',
28
+ :Default => 'default'
29
+
30
+ parameter 'InstanceSecurityGroup',
31
+ :Type => 'String'
32
+
33
+ parameter 'InstanceType',
34
+ :Description => 'EC2 Instance Type',
35
+ :Type => 'String',
36
+ :AllowedValues => %w(t1.micro m1.small m3.medium m3.large m3.xlarge m3.2xlarge c3.large c3.xlarge c3.2xlarge c3.4xlarge c3.8xlarge),
37
+ :Default => 'm3.large'
38
+
39
+ parameter 'ApplicationName',
40
+ :Description => 'The name of the Elastic Beanstalk Application',
41
+ :Type => 'String',
42
+ :Default => ref('ApplicationName')
43
+
44
+ parameter 'Environment',
45
+ :Type => 'String'
46
+
47
+ parameter 'IamInstanceProfile',
48
+ :Type => 'String',
49
+ :Default => 'EbApp'
50
+
51
+ resource 'Application', :Type => 'AWS::ElasticBeanstalk::Application', :Properties => {
52
+ :Description => ref('ApplicationName'),
53
+ :ApplicationName => join('-', ref('ApplicationName'), ref('Environment')),
54
+ }
55
+
56
+ resource 'ApplicationVersion', :Type => 'AWS::ElasticBeanstalk::ApplicationVersion', :Properties => {
57
+ :ApplicationName => ref('Application'),
58
+ :Description => 'Initial Version',
59
+ :SourceBundle => {
60
+ :S3Bucket => join('/','br-repos',ref('Environment')),
61
+ :S3Key => join('',ref('Environment'), '-Dockerrun.aws.json'),
62
+ },
63
+ }
64
+
65
+ resource 'ConfigurationTemplate', :Type => 'AWS::ElasticBeanstalk::ConfigurationTemplate', :Properties => {
66
+ :ApplicationName => ref('Application'),
67
+ :SolutionStackName => '64bit Amazon Linux 2014.03 v1.0.1 running Docker 1.0.0',
68
+ :Description => 'Default Configuration Version 1.0 - with SSH access',
69
+ :OptionSettings => [
70
+ {
71
+ :Namespace => 'aws:elasticbeanstalk:application:environment',
72
+ :OptionName => 'AWS_REGION',
73
+ :Value => aws_region,
74
+ },
75
+ {
76
+ :Namespace => 'aws:elasticbeanstalk:application:environment',
77
+ :OptionName => 'RACK_ENV',
78
+ :Value => find_in_map('LongName', ref('Environment'), 'name'),
79
+ },
80
+ {
81
+ :Namespace => 'aws:autoscaling:launchconfiguration',
82
+ :OptionName => 'EC2KeyName',
83
+ :Value => ref('KeyName'),
84
+ },
85
+ {
86
+ :Namespace => 'aws:autoscaling:launchconfiguration',
87
+ :OptionName => 'IamInstanceProfile',
88
+ :Value => ref('IamInstanceProfile'),
89
+ },
90
+ {
91
+ :Namespace => 'aws:autoscaling:launchconfiguration',
92
+ :OptionName => 'InstanceType',
93
+ :Value => ref('InstanceType'),
94
+ },
95
+ {
96
+ :Namespace => 'aws:autoscaling:launchconfiguration',
97
+ :OptionName => 'SecurityGroups',
98
+ :Value => join(',', join('-', ref('Environment'), 'br'), ref('InstanceSecurityGroup')),
99
+ },
100
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'RollingUpdateEnabled', :Value => 'true' },
101
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MaxBatchSize', :Value => '1' },
102
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MinInstancesInService', :Value => '2' },
103
+ { :Namespace => 'aws:elasticbeanstalk:hostmanager', :OptionName => 'LogPublicationControl', :Value => 'true' },
104
+ ],
105
+ }
106
+
107
+ resource 'EbEnvironment', :Type => 'AWS::ElasticBeanstalk::Environment', :Properties => {
108
+ :ApplicationName => ref('Application'),
109
+ :EnvironmentName => join('-', ref('Environment'), ref('ApplicationName'), 'app'),
110
+ :Description => 'Default Environment',
111
+ :VersionLabel => ref('ApplicationVersion'),
112
+ :TemplateName => ref('ConfigurationTemplate'),
113
+ :OptionSettings => [],
114
+ }
115
+
116
+ resource 'HostRecord', :Type => 'AWS::Route53::RecordSet', :Properties => {
117
+ :Comment => 'DNS name for my stack',
118
+ :HostedZoneName => join('', find_in_map('HostedZoneName', ref('Environment'), 'name'), '.'),
119
+ :Name => join('.', ref('ApplicationName'), find_in_map('HostedZoneName', ref('Environment'), 'name')),
120
+ :ResourceRecords => [ get_att('EbEnvironment', 'EndpointURL') ],
121
+ :TTL => '60',
122
+ :Type => 'CNAME',
123
+ }
124
+
125
+ output 'URL',
126
+ :Description => 'URL of the AWS Elastic Beanstalk Environment',
127
+ :Value => join('', 'http://', get_att('EbEnvironment', 'EndpointURL'))
128
+
129
+ end.exec!
130
+ "
131
+ end
132
+ end
@@ -0,0 +1,67 @@
1
+ class MasterTemplate
2
+
3
+ def initialize params
4
+ @stack_name = params[:stack_name]
5
+ @env = params[:env]
6
+ @requirements = params[:requirements]
7
+ end
8
+
9
+ def create
10
+ "#{@requirements}
11
+ template do
12
+ value :AWSTemplateFormatVersion => '2010-09-09'
13
+ value :Description => '#{@stack_name} Master Template'
14
+
15
+ parameter 'ResourcesTemplate',
16
+ :Description => 'The key of the template for the resources required to run the app',
17
+ :Type => 'String',
18
+ :Default => '#{@env}-resources.cfn.json'
19
+
20
+ parameter 'AppTemplate',
21
+ :Description => 'The key of the template for the EB app/env substack',
22
+ :Type => 'String',
23
+ :Default => '#{@env}-elasticbeanstalk.cfn.json'
24
+
25
+ parameter 'KeyName',
26
+ :Default => 'default'
27
+
28
+ parameter 'InstanceType',
29
+ :Type => 'String',
30
+ :Default => 't1.micro'
31
+
32
+ parameter 'ApplicationName',
33
+ :Type => 'String'
34
+ :Default => '#{@stack_name}'
35
+
36
+ parameter 'Environment',
37
+ :Type => 'String',
38
+ :Default => '#{@env}'
39
+
40
+ parameter 'IamInstanceProfile',
41
+ :Type => 'String',
42
+ :Default => 'EbApp'
43
+
44
+ resource 'AppResources', :Type => 'AWS::CloudFormation::Stack', :Properties => {
45
+ :TemplateURL => join('/', 'http://s3.amazonaws.com/br-templates', ref('ApplicationName'), ref('ResourcesTemplate')),
46
+ :Parameters => { :ApplicationName => ref('ApplicationName') },
47
+ }
48
+
49
+ resource 'App', :Type => 'AWS::CloudFormation::Stack', :Properties => {
50
+ :TemplateURL => join('/', 'http://s3.amazonaws.com/#{@cfn_bucket}', ref('ApplicationName'), ref('AppTemplate')),
51
+ :Parameters => {
52
+ :KeyName => ref('KeyName'),
53
+ :InstanceSecurityGroup => get_att('AppResources', 'Outputs.InstanceSecurityGroup'),
54
+ :InstanceType => ref('InstanceType'),
55
+ :ApplicationName => ref('ApplicationName'),
56
+ :Environment => ref('Environment'),
57
+ :IamInstanceProfile => ref('IamInstanceProfile'),
58
+ },
59
+ }
60
+
61
+ output 'URL',
62
+ :Description => 'URL of the AWS Elastic Beanstalk Environment',
63
+ :Value => get_att('App', 'Outputs.URL')
64
+
65
+ end.exec!"
66
+ end
67
+ end
@@ -0,0 +1,32 @@
1
+ class ResourcesTemplate
2
+
3
+ def initialize params
4
+ @stack_name = params[:stack_name]
5
+ @env = params[:env]
6
+ @requirements = params[:requirements]
7
+ end
8
+
9
+ def create
10
+ "#{@requirements}
11
+ template do
12
+
13
+ value :AWSTemplateFormatVersion => '2010-09-09'
14
+
15
+ value :Description => '#{@env} Services Resources (2014-06-30)'
16
+
17
+ parameter 'ApplicationName',
18
+ :Type => 'String',
19
+ :Default => ref('ApplicationName')
20
+
21
+ resource 'InstanceSecurityGroup', :Type => 'AWS::EC2::SecurityGroup', :Properties => {
22
+ :GroupDescription => join('', 'an EC2 instance security group created for ', ref('ApplicationName')),
23
+ :SecurityGroupIngress => [],
24
+ }
25
+
26
+ output 'InstanceSecurityGroup',
27
+ :Value => ref('InstanceSecurityGroup')
28
+
29
+ end.exec!
30
+ "
31
+ end
32
+ end
@@ -19,5 +19,11 @@ module Gantree
19
19
  def init image
20
20
  Gantree::Init.new(image,options).run
21
21
  end
22
+
23
+ desc "create APP", "create or update a cfn stack"
24
+ method_option :env, :aliases => "-e", :desc => "(optional) environment name"
25
+ def create app
26
+ Gantree::Stack.new(app, options).create
27
+ end
22
28
  end
23
29
  end
@@ -1,3 +1,3 @@
1
1
  module Gantree
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gantree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -153,12 +153,18 @@ files:
153
153
  - README.md
154
154
  - Rakefile
155
155
  - bin/gantree
156
+ - cfn/knarr-stag-s3-beanstalk.cfn.json
157
+ - cfn/knarr-stag-s3-master.cfn.json
158
+ - cfn/knarr-stag-s3-resources.cfn.json
156
159
  - gantree.gemspec
157
160
  - lib/gantree.rb
161
+ - lib/gantree/cfn.rb
162
+ - lib/gantree/cfn/beanstalk.rb
163
+ - lib/gantree/cfn/master.rb
164
+ - lib/gantree/cfn/resources.rb
158
165
  - lib/gantree/cli.rb
159
166
  - lib/gantree/cli/help.rb
160
167
  - lib/gantree/deploy.rb
161
- - lib/gantree/generate.rb
162
168
  - lib/gantree/init.rb
163
169
  - lib/gantree/version.rb
164
170
  - spec/lib/cli_spec.rb
@@ -1,12 +0,0 @@
1
- module Gantree
2
- class Generate
3
-
4
- def initialize app,options
5
- @options = options
6
- AWS.config(
7
- :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
8
- :secret_access_key => ENV['AWS_SECRET_ACCES_KEY'])
9
- end
10
-
11
- end
12
- end