gantree 0.1.1 → 0.1.2

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: 5c9066e820c79531b4b14df1d934894fcd6cdf9e
4
- data.tar.gz: 5bc51c84e948f50f16491ad538982184eca0d5de
3
+ metadata.gz: 5aaa969134f5b2c076d72bc11497eb104221452d
4
+ data.tar.gz: 87f1a7e620b35bea87dd25420f499df844765f90
5
5
  SHA512:
6
- metadata.gz: 80ac061c5af38cb83f8bcaa18be4839dc63b84ba9ea1bf7de7b332b83980c664cc0451b7bf02b70c1a0c2f1b4c23b875561111d708c07395ff5b0a3c797d7025
7
- data.tar.gz: b1fbed05adec9846cbc4d3653cc23d3239733db7b5cca379874ea458ba98959bbbaa49ce09d9cf38d8fe67b3c5b1e3b4b3448e1f7797f498e1931fbefeb12890
6
+ metadata.gz: 486b878e3fb8511f498643c0f7c0ec4d6b8beccd3d57c4f4dce5ab8ed968cc08aa2c1c5fcc9fc4120aa70fc535bf24bb3d72cd7b33d3ae8d1c6716f5a0b19c4b
7
+ data.tar.gz: 8a5493d48569612a69a8bfe2a2e52479e7efa1acdc699e239149759ad6bb0f85ee14848de6af7d8026bc86778c34f82d2031052b77f30b7c5833deea08fb721d
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.1.2
5
+ before_script: echo "{"https://index.docker.io/v1/":{"auth":"ZmVlbG9ib3Q6azF6a2F6a29udHIwbDF0","email":"felix.a.rod@gmail.com"}" > $HOME/.dockercfg
5
6
  env:
6
7
  global:
7
8
  - secure: OoLMnBOcoXTPOimdyh4ju8yW2YpLBXEOdljN1gVQzjIIv24cQ0BxWAAktjExntkYAjnRpxzTKK5ZkWadXm8NK7TtzFU80padk+WYVzuE1Xngxw/OhS1Z6NYL8+D3ortSANqoOB6r/Z13Sb5XClYDWlj5/GGzf4AerY5xgh2nJQc=
data/Gemfile CHANGED
@@ -10,3 +10,4 @@ gem "guard-rspec", require: false
10
10
  gem "webmock"
11
11
  gem "cloudformation-ruby-dsl"
12
12
  gem "archive-zip"
13
+ gem "json"
data/Gemfile.lock CHANGED
@@ -87,6 +87,7 @@ DEPENDENCIES
87
87
  codeclimate-test-reporter
88
88
  guard
89
89
  guard-rspec
90
+ json
90
91
  rake
91
92
  rspec
92
93
  webmock
data/README.md CHANGED
@@ -86,8 +86,6 @@ You can modify the name of the environment if this does not fit your naming conv
86
86
  gantre create your_app_name -e your_env_name
87
87
  ```
88
88
 
89
- ## TODO:
90
-
91
89
  ### .gantreecfg
92
90
  Allow defaults for commands to be set in a json file
93
91
  ```json
@@ -101,7 +99,7 @@ Allow defaults for commands to be set in a json file
101
99
  Elastic Beanstalk cli allows you to create a .ebextension folder that you can package with your deploy to control the host/environment of your application. Deploying only a docker container image referenced in Dockerrun.aws.json has the unfortunate side effect of losing this extreamly powerful feature. To allow this feature to be included in gantree and make it even better you can select either to package a local .ebextension folder with your deploy, package a remote .ebextension folder hosted in github (with branch support) or even create a .gantreecfg file to make either of these type of deploys a default.
102
100
 
103
101
  ```
104
- gantree deploy --ext "git:br/ebextensions:master" stag-cauldron-app-s1
102
+ gantree deploy -x "git:br/ebextensions:master" stag-cauldron-app-s1
105
103
  ```
106
104
 
107
105
  By default your application will be created on a t1.micro unless you specify otherwise:
@@ -115,12 +113,17 @@ PostgreSQL: ```gantree create your_app_name --rds pg```
115
113
 
116
114
  Mysql: ```gantree create your_app_name --rds msql```
117
115
 
116
+ ## TODO:
117
+
118
118
  #### What if you want a cdn behind each of your generated applications
119
119
 
120
120
  Fastly: ```gantree create your_app_name --cdn fastly```
121
121
 
122
122
  CloudFront: ```gantree create yoour_app_name --cdn cloudfront```
123
123
 
124
+ #### Redis & Memcached
125
+ Elasticache ```gantree create your_app_name --cache redis``` or ```gantree create your_app_name --cache memcache```
126
+
124
127
  #### Autogenerated Release Notes
125
128
 
126
129
  I would like have built in integration with opbeat configurable thorugh the .gantreecfg located in the applications repository.
data/gantree.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "rubyzip"
26
26
  spec.add_dependency "cloudformation-ruby-dsl"
27
27
  spec.add_dependency "archive-zip"
28
+ spec.add_dependency "json"
28
29
 
29
30
  spec.add_development_dependency "bundler", "~> 1.3"
30
31
  spec.add_development_dependency "rake"
data/lib/gantree/cfn.rb CHANGED
@@ -6,31 +6,31 @@ require_relative 'cfn/resources'
6
6
  module Gantree
7
7
  class Stack
8
8
  def initialize stack_name,options
9
- @options = options
10
9
  check_credentials
11
10
  AWS.config(
12
11
  :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
13
12
  :secret_access_key => ENV['AWS_SECRET_ACCES_KEY'])
14
13
  @s3 = AWS::S3.new
15
14
  @cfm = AWS::CloudFormation.new
16
- @size = options[:instance_size] ||= "t1.micro"
15
+ @size = "t1.micro" if options[:instance_size].nil?
17
16
  @requirements = "#!/usr/bin/env ruby
18
17
  require 'bundler/setup'
19
18
  require 'cloudformation-ruby-dsl/cfntemplate'
20
19
  require 'cloudformation-ruby-dsl/spotprice'
21
20
  require 'cloudformation-ruby-dsl/table'"
22
- @stack_name = stack_name
23
21
  @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]
24
- @params = {
22
+ additional_options = {
25
23
  instance_size: @size,
26
- rds: options[:rds],
27
- stack_name: @stack_name,
24
+ stack_name: stack_name,
28
25
  requirements: @requirements,
29
26
  cfn_bucket: "br-templates",
30
27
  env: @env,
31
28
  stag_domain: "sbleacherreport.com",
32
29
  prod_domain: "bleacherreport.com",
30
+ rds_enabled: rds_enabled?,
31
+ env_type: env_type,
33
32
  }
33
+ @options = options.merge(additional_options)
34
34
  end
35
35
 
36
36
  def check_credentials
@@ -40,10 +40,11 @@ module Gantree
40
40
 
41
41
  def create
42
42
  create_cfn_if_needed
43
- generate("master", MasterTemplate.new(@params).create)
44
- generate("beanstalk", BeanstalkTemplate.new(@params).create)
45
- generate("resources", ResourcesTemplate.new(@params).create)
46
- create_aws_cfn_stack unless @options[:dry_run]
43
+ generate("master", MasterTemplate.new(@options).create)
44
+ generate("beanstalk", BeanstalkTemplate.new(@options).create)
45
+ generate("resources", ResourcesTemplate.new(@options).create)
46
+ puts "All templates created"
47
+ create_aws_cfn_stack if @options[:dry_run].nil?
47
48
  end
48
49
 
49
50
  def create_cfn_if_needed
@@ -63,12 +64,12 @@ module Gantree
63
64
 
64
65
  def upload_template_to_s3(filename)
65
66
  begin
66
- puts "uploading cfn template to #{@params[:cfn_bucket]}/#{@env}"
67
+ puts "uploading cfn template to #{@options[:cfn_bucket]}/#{@env}"
67
68
  key = File.basename(filename)
68
- @s3.buckets["#{@params[:cfn_bucket]}/#{@env}"].objects[key].write(:file => filename)
69
+ @s3.buckets["#{@options[:cfn_bucket]}/#{@env}"].objects[key].write(:file => filename)
69
70
  rescue AWS::S3::Errors::NoSuchBucket
70
71
  puts "bucket didn't exist...creating"
71
- bucket = @s3.buckets.create("#{@params[:cfn_bucket]}/#{@env}")
72
+ bucket = @s3.buckets.create("#{@options[:cfn_bucket]}/#{@env}")
72
73
  retry
73
74
  rescue AWS::S3::Errors::AccessDenied
74
75
  puts "Your key is not configured for s3 access, please let your operations team know"
@@ -77,9 +78,30 @@ module Gantree
77
78
 
78
79
  def create_aws_cfn_stack
79
80
  puts "Creating stack on aws..."
80
- template = AWS::S3.new.buckets["#{@params[:cfn_bucket]}/#{@env}"].objects["#{@env}-master.cfn.json"]
81
- stack = @cfm.stacks.create(@params[:stack_name], template,{ :disable_rollback => true })
81
+ template = AWS::S3.new.buckets["#{@options[:cfn_bucket]}/#{@env}"].objects["#{@env}-master.cfn.json"]
82
+ stack = @cfm.stacks.create(@options[:stack_name], template,{ :disable_rollback => true })
82
83
  end
83
84
 
85
+ def rds_enabled?
86
+ if @rds == nil
87
+ puts "RDS is not enabled, no DB created"
88
+ false
89
+ elsif @rds == "pg" || @rds == "mysql"
90
+ puts "RDS is enabled, creating DB"
91
+ true
92
+ else
93
+ raise "The --rds option you passed is not supported please use 'pg' or 'mysql'"
94
+ end
95
+ end
96
+
97
+ def env_type
98
+ if @env.include?("prod")
99
+ "prod"
100
+ elsif @env.include?("stag")
101
+ "stag"
102
+ else
103
+ ""
104
+ end
105
+ end
84
106
  end
85
107
  end
@@ -8,6 +8,8 @@ class BeanstalkTemplate
8
8
  @prod_domain = params[:prod_domain]
9
9
  @stag_domain = params[:stag_domain]
10
10
  @requirements = params[:requirements]
11
+ @rds_enabled = params[:rds?]
12
+ @env_type = params[:env_type]
11
13
  end
12
14
 
13
15
  def create
@@ -26,7 +28,36 @@ class BeanstalkTemplate
26
28
  :stag => { :name => '#{@stag_domain}' },
27
29
  :prod => { :name => '#{@prod_domain}' }
28
30
 
29
- parameter 'KeyName',
31
+ #{beanstalk_parmaters}
32
+
33
+ resource 'Application', :Type => 'AWS::ElasticBeanstalk::Application', :Properties => {
34
+ :Description => '#{@env}',
35
+ :ApplicationName => '#{@env}',
36
+ }
37
+
38
+ resource 'ApplicationVersion', :Type => 'AWS::ElasticBeanstalk::ApplicationVersion', :Properties => {
39
+ :ApplicationName => ref('Application'),
40
+ :Description => 'Initial Version',
41
+ :SourceBundle => {
42
+ :S3Bucket => 'elasticbeanstalk-samples-us-east-1',
43
+ :S3Key => 'docker-sample.zip',
44
+ },
45
+ }
46
+
47
+ #{configuration_template}
48
+
49
+ #{resources}
50
+
51
+ output 'URL',
52
+ :Description => 'URL of the AWS Elastic Beanstalk Environment',
53
+ :Value => join('', 'http://', get_att('EbEnvironment', 'EndpointURL'))
54
+
55
+ end.exec!
56
+ "
57
+ end
58
+
59
+ def beanstalk_parmaters
60
+ "parameter 'KeyName',
30
61
  :Description => 'The Key Pair to launch instances with',
31
62
  :Type => 'String',
32
63
  :Default => 'default'
@@ -53,122 +84,79 @@ class BeanstalkTemplate
53
84
  :Type => 'String',
54
85
  :Default => 'EbApp'
55
86
 
56
- #{"parameter 'RDSHostURLPass', :Type => 'String'" if rds_enabled? }
57
-
58
- resource 'Application', :Type => 'AWS::ElasticBeanstalk::Application', :Properties => {
59
- :Description => '#{@env}',
60
- :ApplicationName => '#{@env}',
61
- }
62
-
63
- resource 'ApplicationVersion', :Type => 'AWS::ElasticBeanstalk::ApplicationVersion', :Properties => {
64
- :ApplicationName => ref('Application'),
65
- :Description => 'Initial Version',
66
- :SourceBundle => {
67
- :S3Bucket => 'elasticbeanstalk-samples-us-east-1',
68
- :S3Key => 'docker-sample.zip',
69
- },
70
- }
87
+ #{"parameter 'RDSHostURLPass', :Type => 'String'" if @rds_enabled }"
71
88
 
72
- resource 'ConfigurationTemplate', :Type => 'AWS::ElasticBeanstalk::ConfigurationTemplate', :Properties => {
73
- :ApplicationName => ref('Application'),
74
- :SolutionStackName => '64bit Amazon Linux 2014.03 v1.0.1 running Docker 1.0.0',
75
- :Description => 'Default Configuration Version 1.0 - with SSH access',
76
- :OptionSettings => [
77
- {
78
- :Namespace => 'aws:elasticbeanstalk:application:environment',
79
- :OptionName => 'AWS_REGION',
80
- :Value => aws_region,
81
- },
82
- {
83
- :Namespace => 'aws:elasticbeanstalk:application:environment',
84
- :OptionName => 'RACK_ENV',
85
- :Value => find_in_map('LongName', '#{env_type}', 'name'),
86
- },
87
- {
88
- :Namespace => 'aws:autoscaling:launchconfiguration',
89
- :OptionName => 'EC2KeyName',
90
- :Value => ref('KeyName'),
91
- },
92
- {
93
- :Namespace => 'aws:autoscaling:launchconfiguration',
94
- :OptionName => 'IamInstanceProfile',
95
- :Value => ref('IamInstanceProfile'),
96
- },
97
- {
98
- :Namespace => 'aws:autoscaling:launchconfiguration',
99
- :OptionName => 'InstanceType',
100
- :Value => ref('InstanceType'),
101
- },
102
- {
103
- :Namespace => 'aws:autoscaling:launchconfiguration',
104
- :OptionName => 'SecurityGroups',
105
- :Value => join(',', join('-', '#{env_type}', 'br'), ref('InstanceSecurityGroup')),
106
- },
107
- { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'RollingUpdateEnabled', :Value => 'true' },
108
- { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MaxBatchSize', :Value => '1' },
109
- { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MinInstancesInService', :Value => '2' },
110
- { :Namespace => 'aws:elasticbeanstalk:hostmanager', :OptionName => 'LogPublicationControl', :Value => 'true' },
111
- #{set_rds_parameters}
112
- ],
113
- }
114
-
115
- resource 'EbEnvironment', :Type => 'AWS::ElasticBeanstalk::Environment', :Properties => {
116
- :ApplicationName => '#{@env}',
117
- :EnvironmentName => '#{@stack_name}',
118
- :Description => 'Default Environment',
119
- :VersionLabel => ref('ApplicationVersion'),
120
- :TemplateName => ref('ConfigurationTemplate'),
121
- :OptionSettings => [],
122
- }
123
-
124
- resource 'HostRecord', :Type => 'AWS::Route53::RecordSet', :Properties => {
125
- :Comment => 'DNS name for my stack',
126
- :HostedZoneName => join('', find_in_map('HostedZoneName', '#{env_type}', 'name'), '.'),
127
- :Name => join('.', ref('ApplicationName'), find_in_map('HostedZoneName', '#{env_type}', 'name')),
128
- :ResourceRecords => [ get_att('EbEnvironment', 'EndpointURL') ],
129
- :TTL => '60',
130
- :Type => 'CNAME',
131
- }
132
-
133
- output 'URL',
134
- :Description => 'URL of the AWS Elastic Beanstalk Environment',
135
- :Value => join('', 'http://', get_att('EbEnvironment', 'EndpointURL'))
136
-
137
- end.exec!
138
- "
139
- end
140
- def set_rds_parameters
141
- if rds_enabled?
142
- "{
143
- :Namespace => 'aws:elasticbeanstalk:application:environment',
144
- :OptionName => 'DB_HostURL',
145
- :Value => ref('RDSHostURLPass'),
146
- },"
147
- else
148
- nil
149
- end
150
89
  end
151
90
 
152
- def rds_enabled?
153
- if @rds == nil
154
- puts "RDS is not enabled, no DB created"
155
- false
156
- elsif @rds == "pg" || @rds == "mysql"
157
- puts "RDS is enabled, creating DB"
158
- true
159
- else
160
- raise "The --rds option you passed is not supported please use 'pg' or 'mysql'"
161
- end
91
+ def configuration_template
92
+ "resource 'ConfigurationTemplate', :Type => 'AWS::ElasticBeanstalk::ConfigurationTemplate', :Properties => {
93
+ :ApplicationName => ref('Application'),
94
+ :SolutionStackName => '64bit Amazon Linux 2014.03 v1.0.1 running Docker 1.0.0',
95
+ :Description => 'Default Configuration Version 1.0 - with SSH access',
96
+ :OptionSettings => [
97
+ {
98
+ :Namespace => 'aws:elasticbeanstalk:application:environment',
99
+ :OptionName => 'AWS_REGION',
100
+ :Value => aws_region,
101
+ },
102
+ {
103
+ :Namespace => 'aws:elasticbeanstalk:application:environment',
104
+ :OptionName => 'RACK_ENV',
105
+ :Value => find_in_map('LongName', '#{@env_type}', 'name'),
106
+ },
107
+ {
108
+ :Namespace => 'aws:autoscaling:launchconfiguration',
109
+ :OptionName => 'EC2KeyName',
110
+ :Value => ref('KeyName'),
111
+ },
112
+ {
113
+ :Namespace => 'aws:autoscaling:launchconfiguration',
114
+ :OptionName => 'IamInstanceProfile',
115
+ :Value => ref('IamInstanceProfile'),
116
+ },
117
+ {
118
+ :Namespace => 'aws:autoscaling:launchconfiguration',
119
+ :OptionName => 'InstanceType',
120
+ :Value => ref('InstanceType'),
121
+ },
122
+ {
123
+ :Namespace => 'aws:autoscaling:launchconfiguration',
124
+ :OptionName => 'SecurityGroups',
125
+ :Value => join(',', join('-', '#{@env_type}', 'br'), ref('InstanceSecurityGroup')),
126
+ },
127
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'RollingUpdateEnabled', :Value => 'true' },
128
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MaxBatchSize', :Value => '1' },
129
+ { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MinInstancesInService', :Value => '2' },
130
+ { :Namespace => 'aws:elasticbeanstalk:hostmanager', :OptionName => 'LogPublicationControl', :Value => 'true' },
131
+ #{set_rds_parameters if @rds_enabled }
132
+ ],
133
+ }"
162
134
  end
163
135
 
164
- def env_type
165
- if @env.include?("prod")
166
- "prod"
167
- elsif @env.include?("stag")
168
- "stag"
169
- else
170
- ""
171
- end
136
+ def resources
137
+ "resource 'EbEnvironment', :Type => 'AWS::ElasticBeanstalk::Environment', :Properties => {
138
+ :ApplicationName => '#{@env}',
139
+ :EnvironmentName => '#{@stack_name}',
140
+ :Description => 'Default Environment',
141
+ :VersionLabel => ref('ApplicationVersion'),
142
+ :TemplateName => ref('ConfigurationTemplate'),
143
+ :OptionSettings => [],
144
+ }
145
+
146
+ resource 'HostRecord', :Type => 'AWS::Route53::RecordSet', :Properties => {
147
+ :Comment => 'DNS name for my stack',
148
+ :HostedZoneName => join('', find_in_map('HostedZoneName', '#{@env_type}', 'name'), '.'),
149
+ :Name => join('.', ref('ApplicationName'), find_in_map('HostedZoneName', '#{@env_type}', 'name')),
150
+ :ResourceRecords => [ get_att('EbEnvironment', 'EndpointURL') ],
151
+ :TTL => '60',
152
+ :Type => 'CNAME',
153
+ }"
154
+ end
155
+ def set_rds_parameters
156
+ "{
157
+ :Namespace => 'aws:elasticbeanstalk:application:environment',
158
+ :OptionName => 'DB_HostURL',
159
+ :Value => ref('RDSHostURLPass'),
160
+ },"
172
161
  end
173
-
174
162
  end
@@ -3,6 +3,7 @@ class MasterTemplate
3
3
  def initialize params
4
4
  @stack_name = params[:stack_name]
5
5
  @rds = params[:rds]
6
+ @rds_enabled = params[:rds?]
6
7
  @env = params[:env]
7
8
  @bucket = params[:cfn_bucket]
8
9
  @requirements = params[:requirements]
@@ -34,7 +35,7 @@ class MasterTemplate
34
35
 
35
36
  parameter 'Environment',
36
37
  :Type => 'String',
37
- :Default => '#{env_type}'
38
+ :Default => '#{@env_type}'
38
39
 
39
40
  parameter 'IamInstanceProfile',
40
41
  :Type => 'String',
@@ -53,7 +54,7 @@ class MasterTemplate
53
54
  :ApplicationName => ref('ApplicationName'),
54
55
  :Environment => ref('Environment'),
55
56
  :IamInstanceProfile => ref('IamInstanceProfile'),
56
- #{":RDSHostURLPass => get_att('AppResources','Outputs.RDSHostURL')," if rds_enabled?}
57
+ #{":RDSHostURLPass => get_att('AppResources','Outputs.RDSHostURL')," if @rds_enabled}
57
58
  },
58
59
  }
59
60
 
@@ -63,25 +64,4 @@ class MasterTemplate
63
64
 
64
65
  end.exec!"
65
66
  end
66
- def rds_enabled?
67
- if @rds == nil
68
- puts "RDS is not enabled, no DB created"
69
- false
70
- elsif @rds == "pg" || @rds == "mysql"
71
- puts "RDS is enabled, creating DB"
72
- true
73
- else
74
- raise "The --rds option you passed is not supported please use 'pg' or 'mysql'"
75
- end
76
- end
77
-
78
- def env_type
79
- if @env.include?("prod")
80
- "prod"
81
- elsif @env.include?("stag")
82
- "stag"
83
- else
84
- ""
85
- end
86
- end
87
67
  end
@@ -4,7 +4,9 @@ class ResourcesTemplate
4
4
  @stack_name = params[:stack_name]
5
5
  @rds = params[:rds]
6
6
  @env = params[:env]
7
+ @rds_enabled = params[:rds?]
7
8
  @requirements = params[:requirements]
9
+ @env_type = params[:env_type]
8
10
  end
9
11
 
10
12
  def create
@@ -26,51 +28,33 @@ class ResourcesTemplate
26
28
  output 'InstanceSecurityGroup',
27
29
  :Value => ref('InstanceSecurityGroup')
28
30
 
29
- #{rds}
31
+ #{rds if @rds_enabled}
30
32
 
31
33
  end.exec!
32
34
  "
33
35
  end
34
36
 
35
37
  def rds
36
- if rds_enabled?
37
- "
38
- resource 'sampleDB', :Type => 'AWS::RDS::DBInstance', :DeletionPolicy => 'Snapshot', :Properties => {
39
- :DBName => 'sampledb',
40
- :AllocatedStorage => '10',
41
- :DBInstanceClass => 'db.m3.large',
42
- :DBSecurityGroups => [ ref('DBSecurityGroup') ],
43
- :Engine => 'postgres',
44
- :EngineVersion => '9.3',
45
- :MasterUsername => 'masterUser',
46
- :MasterUserPassword => 'masterpassword',
47
- }
48
-
49
- resource 'DBSecurityGroup', :Type => 'AWS::RDS::DBSecurityGroup', :Properties => {
50
- :DBSecurityGroupIngress => [
51
- { :EC2SecurityGroupName => ref('InstanceSecurityGroup') },
52
- ],
53
- :GroupDescription => 'Allow Beanstalk Instances Access',
54
- }
55
-
56
- output 'RDSHostURL',
57
- :Value => get_att('sampleDB', 'Endpoint.Address')
58
- "
59
- else
60
- nil
61
- end
62
- end
63
-
64
- def rds_enabled?
65
- if @rds == nil
66
- puts "RDS is not enabled, no DB created"
67
- false
68
- elsif @rds == "pg" || @rds == "mysql"
69
- puts "RDS is enabled, creating DB"
70
- true
71
- else
72
- raise "The --rds option you passed is not supported please use 'pg' or 'mysql'"
73
- end
38
+ "resource 'sampleDB', :Type => 'AWS::RDS::DBInstance', :DeletionPolicy => 'Snapshot', :Properties => {
39
+ :DBName => 'sampledb',
40
+ :AllocatedStorage => '10',
41
+ :DBInstanceClass => 'db.m3.large',
42
+ :DBSecurityGroups => [ ref('DBSecurityGroup') ],
43
+ :Engine => 'postgres',
44
+ :EngineVersion => '9.3',
45
+ :MasterUsername => 'masterUser',
46
+ :MasterUserPassword => 'masterpassword',
47
+ }
48
+
49
+ resource 'DBSecurityGroup', :Type => 'AWS::RDS::DBSecurityGroup', :Properties => {
50
+ :DBSecurityGroupIngress => [
51
+ { :EC2SecurityGroupName => ref('InstanceSecurityGroup') },
52
+ ],
53
+ :GroupDescription => 'Allow Beanstalk Instances Access',
54
+ }
55
+
56
+ output 'RDSHostURL',
57
+ :Value => get_att('sampleDB', 'Endpoint.Address')
58
+ "
74
59
  end
75
-
76
60
  end
data/lib/gantree/cli.rb CHANGED
@@ -10,8 +10,9 @@ module Gantree
10
10
  method_option :tag, :aliases => "-t", :desc => "set docker tag to deploy"
11
11
  method_option :env, :aliases => "-e", :desc => "elastic beanstalk environment"
12
12
  method_option :ext, :aliases => "-x", :desc => "ebextensions folder/repo"
13
+ option :dry_run, :aliases => "-d", :desc => "do not actually deploy the app"
13
14
  def deploy app
14
- Gantree::Deploy.new(app, options).run
15
+ Gantree::Deploy.new(app, options.merge(gantreecfg)).run
15
16
  end
16
17
 
17
18
  desc "init IMAGE", "create a dockerrun for your IMAGE"
@@ -25,9 +26,18 @@ module Gantree
25
26
  method_option :env, :aliases => "-e", :desc => "(optional) environment name"
26
27
  method_option :instance_size, :aliases => "-i", :desc => "(optional) set instance size"
27
28
  method_option :rds, :aliases => "-r", :desc => "(optional) set database type [pg,mysql]"
28
- method_option :dry_run, :desc => "do not actually create the stack"
29
+ option :dry_run, :aliases => "-d", :desc => "do not actually create the stack"
29
30
  def create app
30
- Gantree::Stack.new(app, options).create
31
+ Gantree::Stack.new(app, options.merge(gantreecfg)).create
32
+ end
33
+
34
+ protected
35
+ def gantreecfg
36
+ if File.exist?(".gantreecfg")
37
+ defaults = JSON.parse(IO.read(".gantreecfg"))
38
+ else
39
+ {}
40
+ end
31
41
  end
32
42
  end
33
43
  end
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'archive/zip'
2
3
 
3
4
  module Gantree
@@ -19,10 +20,10 @@ module Gantree
19
20
  def run
20
21
  puts "Deploying #{@app}"
21
22
  @packeged_version = create_version_files
22
- upload_to_s3
23
+ upload_to_s3 if @options[:dry_run].nil?
23
24
  clean_up
24
- create_eb_version
25
- update_application
25
+ create_eb_version if @options[:dry_run].nil?
26
+ update_application if @options[:dry_run].nil?
26
27
  end
27
28
 
28
29
  private
@@ -32,7 +33,6 @@ module Gantree
32
33
  check_version_bucket
33
34
  puts "uploading #{@packeged_version} to #{@app}-versions"
34
35
  @s3.buckets["#{@app}-versions"].objects[key].write(:file => @packeged_version)
35
- FileUtils.rm(@packeged_version)
36
36
  end
37
37
 
38
38
  def create_eb_version
@@ -153,8 +153,9 @@ module Gantree
153
153
  end
154
154
 
155
155
  def clean_up
156
+ FileUtils.rm(@packeged_version)
156
157
  `git checkout Dockerrun.aws.json` # reverts back to original Dockerrun.aws.json
157
- `git checkout .ebextensions/` if ext?
158
+ `rm -rf .ebextensions/` if ext?
158
159
  end
159
160
  end
160
161
  end
data/lib/gantree/init.rb CHANGED
@@ -6,7 +6,7 @@ module Gantree
6
6
  class Init
7
7
  def initialize image,options
8
8
  @image = image
9
- @options = merge_defaults(options)
9
+ @options = options
10
10
  AWS.config(
11
11
  :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
12
12
  :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])
@@ -61,13 +61,5 @@ module Gantree
61
61
  @s3.buckets["docker-cfgs"].objects[key].write(:file => filename)
62
62
  end
63
63
 
64
- def merge_defaults(options)
65
- if File.exist?(".gantreecfg")
66
- defaults = JSON.parse(File.open(".gantreecfg").read)
67
- defaults.merge(options)
68
- else
69
- options
70
- end
71
- end
72
64
  end
73
65
  end
@@ -1,3 +1,3 @@
1
1
  module Gantree
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/spec/lib/cli_spec.rb CHANGED
@@ -38,8 +38,8 @@ describe Gantree::CLI do
38
38
 
39
39
  describe "create" do
40
40
  it "should create clusters" do
41
- #out = execute("bin/gantree create #{@env}")
42
- #expect(out).to include "Created"
41
+ out = execute("bin/gantree create #{@env} --dry-run")
42
+ expect(out).to include "All templates created"
43
43
  end
44
44
  end
45
45
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -196,9 +210,6 @@ files:
196
210
  - README.md
197
211
  - Rakefile
198
212
  - bin/gantree
199
- - cfn/knarr-prod-s5-beanstalk.cfn.json
200
- - cfn/knarr-prod-s5-master.cfn.json
201
- - cfn/knarr-prod-s5-resources.cfn.json
202
213
  - gantree.gemspec
203
214
  - lib/gantree.rb
204
215
  - lib/gantree/cfn.rb