Skip to content

Commit f90720d

Browse files
committed
Add support for RDS and Network options file
1 parent 98499e8 commit f90720d

1 file changed

Lines changed: 119 additions & 2 deletions

File tree

lib/tasks/eb_fast_deploy.rb

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,80 @@
33
require 'dotenv/environment'
44
require 'fog'
55

6+
module EbFastDeploy
7+
8+
OPTIONS = {
9+
"AvailabilityZones" => {:namespace => "aws:autoscaling:asg", :option_name => "Availability Zones"},
10+
"Cooldown" => {:namespace => "aws:autoscaling:asg", :option_name => "Cooldown"},
11+
"CustomAvailabilityZones" => {:namespace => "aws:autoscaling:asg", :option_name => "Custom Availability Zones"},
12+
"MinSize" => {:namespace => "aws:autoscaling:asg", :option_name => "MinSize"},
13+
"MaxSize" => {:namespace => "aws:autoscaling:asg", :option_name => "MaxSize"},
14+
15+
"EC2KeyName" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "EC2KeyName"},
16+
"IamInstanceProfile" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "IamInstanceProfile"},
17+
"ImageId" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "ImageId"},
18+
"InstanceType" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "InstanceType"},
19+
"MonitoringInterval" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "MonitoringInterval"},
20+
"SecurityGroups" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "SecurityGroups"},
21+
"SSHSourceRestriction" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "SSHSourceRestriction"},
22+
"BlockDeviceMappings" => {:namespace => "aws:autoscaling:launchconfiguration", :option_name => "BlockDeviceMappings"},
23+
"LogPublicationControl" => {:namespace => "aws:elasticbeanstalk:hostmanager", :option_name => "LogPublicationControl"},
24+
25+
"BreachDuration" => {:namespace => "aws:autoscaling:trigger", :option_name => "BreachDuration"},
26+
"LowerBreachScaleIncrement" => {:namespace => "aws:autoscaling:trigger", :option_name => "LowerBreachScaleIncrement"},
27+
"LowerThreshold" => {:namespace => "aws:autoscaling:trigger", :option_name => "LowerThreshold"},
28+
"MeasureName" => {:namespace => "aws:autoscaling:trigger", :option_name => "MeasureName"},
29+
"Period" => {:namespace => "aws:autoscaling:trigger", :option_name => "Period"},
30+
"Statistic" => {:namespace => "aws:autoscaling:trigger", :option_name => "Statistic"},
31+
"Unit" => {:namespace => "aws:autoscaling:trigger", :option_name => "Unit"},
32+
"UpperBreachScaleIncrement" => {:namespace => "aws:autoscaling:trigger", :option_name => "UpperBreachScaleIncrement"},
33+
"UpperThreshold" => {:namespace => "aws:autoscaling:trigger", :option_name => "UpperThreshold"},
34+
35+
"VPCId" => {:namespace => "aws:ec2:vpc", :option_name => "VPCId"},
36+
"Subnets" => {:namespace => "aws:ec2:vpc", :option_name => "Subnets"},
37+
"ELBSubnets" => {:namespace => "aws:ec2:vpc", :option_name => "ELBSubnets"},
38+
"ELBScheme" => {:namespace => "aws:ec2:vpc", :option_name => "ELBScheme"},
39+
"DBSubnets" => {:namespace => "aws:ec2:vpc", :option_name => "DBSubnets"},
40+
41+
"ApplicationHealthcheckURL" => {:namespace => "aws:elasticbeanstalk:application", :option_name => "Application Healthcheck URL"},
42+
43+
"EnvironmentType" => {:namespace => "aws:elasticbeanstalk:environment", :option_name => "EnvironmentType"},
44+
45+
"AutomaticallyTerminateUnhealthyInstances" => {:namespace => "aws:elasticbeanstalk:monitoring", :option_name => "Automatically Terminate Unhealthy Instances"},
46+
47+
"NotificationEndpoint" => {:namespace => "aws:elasticbeanstalk:sns:topics", :option_name => "Notification Endpoint"},
48+
"NotificationProtocol" => {:namespace => "aws:elasticbeanstalk:sns:topics", :option_name => "Notification Protocol"},
49+
"NotificationTopicARN" => {:namespace => "aws:elasticbeanstalk:sns:topics", :option_name => "Notification Topic ARN"},
50+
"NotificationTopicName" => {:namespace => "aws:elasticbeanstalk:sns:topics", :option_name => "Notification Topic Name"},
51+
52+
"HealthyThreshold" => {:namespace => "aws:elb:healthcheck", :option_name => "HealthyThreshold"},
53+
"Interval" => {:namespace => "aws:elb:healthcheck", :option_name => "Interval"},
54+
"Timeout" => {:namespace => "aws:elb:healthcheck", :option_name => "Timeout"},
55+
"UnhealthyThreshold" => {:namespace => "aws:elb:healthcheck", :option_name => "UnhealthyThreshold"},
56+
57+
"LoadBalancerHTTPPort" => {:namespace => "aws:elb:loadbalancer", :option_name => "LoadBalancerHTTPPort"},
58+
"LoadBalancerPortProtocol" => {:namespace => "aws:elb:loadbalancer", :option_name => "LoadBalancerPortProtocol"},
59+
"LoadBalancerHTTPSPort" => {:namespace => "aws:elb:loadbalancer", :option_name => "LoadBalancerHTTPSPort"},
60+
"LoadBalancerSSLPortProtocol" => {:namespace => "aws:elb:loadbalancer", :option_name => "LoadBalancerSSLPortProtocol"},
61+
"SSLCertificateId" => {:namespace => "aws:elb:loadbalancer", :option_name => "SSLCertificateId"},
62+
63+
64+
"StickinessCookieExpiration" => {:namespace => "aws:elb:policies", :option_name => "Stickiness Cookie Expiration"},
65+
"StickinessPolicy" => {:namespace => "aws:elb:policies", :option_name => "Stickiness Policy"},
66+
67+
"DBAllocatedStorage" => {:namespace => "aws:rds:dbinstance", :option_name => "DBAllocatedStorage"},
68+
"DBDeletionPolicy" => {:namespace => "aws:rds:dbinstance", :option_name => "DBDeletionPolicy"},
69+
"DBEngine" => {:namespace => "aws:rds:dbinstance", :option_name => "DBEngine"},
70+
"DBEngineVersion" => {:namespace => "aws:rds:dbinstance", :option_name => "DBEngineVersion"},
71+
"DBInstanceClass" => {:namespace => "aws:rds:dbinstance", :option_name => "DBInstanceClass"},
72+
"DBPassword" => {:namespace => "aws:rds:dbinstance", :option_name => "DBPassword"},
73+
"DBSnapshotIdentifier" => {:namespace => "aws:rds:dbinstance", :option_name => "DBSnapshotIdentifier"},
74+
"DBUser" => {:namespace => "aws:rds:dbinstance", :option_name => "DBUser"},
75+
"MultiAZDatabase" => {:namespace => "aws:rds:dbinstance", :option_name => "MultiAZDatabase"},
76+
}.freeze
77+
78+
end
79+
680
def do_cmd(cmd)
781
print "- - - cmd: #{cmd}\n"
882
result = `#{cmd}`
@@ -33,6 +107,15 @@ def set_vars
33107
@env_file_path = Rails.root.to_s+"/config/eb_environments/#{ENV['ENVIRONMENT']}/ruby_container_options"
34108
if File.exists?(@env_file_path)
35109
@eb_ruby_container_options = Dotenv::Environment.new(@env_file_path)
110+
else
111+
puts "(Warning) ruby_container_options doesn't exists"
112+
end
113+
114+
@rdb_network_options_path = Rails.root.to_s+"/config/eb_environments/#{ENV['ENVIRONMENT']}/rdb_network_options"
115+
if File.exists?(@env_file_path)
116+
@rdb_network_options = Dotenv::Environment.new(@rdb_network_options_path);
117+
else
118+
puts "(Warning) rdb_network_options doesn't exists"
36119
end
37120

38121
AWS.config(
@@ -50,12 +133,46 @@ def rails_options
50133
opts
51134
end
52135

136+
def rdb_network_options
137+
opts = []
138+
@rdb_network_options.each do |k,v|
139+
raise "(Error) Unknown option \"#{k}\"=#{v} in #{@rdb_network_options_path}, please check Elastic Beanstalk documentation and EbFastDeploy::OPTIONS" unless EbFastDeploy::OPTIONS.include?(k)
140+
opts << {:namespace => EbFastDeploy::OPTIONS[k][:namespace], :option_name =>EbFastDeploy::OPTIONS[k][:option_name], :value=>v}
141+
end
142+
opts
143+
end
144+
145+
def all_options
146+
rdb_network_options + rails_options
147+
end
148+
149+
53150
namespace :eb do
54151
desc "setvars"
55152
task :setvars do
56153
set_vars
57154
end
58155

156+
desc "setvars"
157+
task :print_env do
158+
set_vars
159+
#EbFastDeploy::OPTIONS.each do |k,v|
160+
# puts "#{v[:namespace]} #{v[:option_name]}=#{ENV[k]}"
161+
#end
162+
163+
puts "--------------- RDS AND NETWORK --------------\n"
164+
rdb_network_options
165+
rdb_network_options.each do |opt|
166+
puts "#{opt[:namespace]} #{opt[:option_name]}=#{opt[:value]}"
167+
end
168+
169+
puts "--------------- RUBY CONTAINER --------------\n"
170+
rails_options.each do |opt|
171+
puts "#{opt[:namespace]} #{opt[:option_name]}=#{opt[:value]}"
172+
end
173+
puts all_options
174+
end
175+
59176
desc "assets compile and upload to S3"
60177
task :assets do
61178
set_vars
@@ -188,7 +305,7 @@ def app_exists?
188305
AWS.elastic_beanstalk.client.create_environment(:application_name => ENV['APP_NAME'],
189306
:environment_name => ENV['ENVIRONMENT'],
190307
:solution_stack_name => ENV['STACK'],
191-
:option_settings => rails_options)
308+
:option_settings => all_options)
192309
puts "(Info) Environment \"#{ ENV['ENVIRONMENT'] }\" created"
193310
else
194311
puts "(Warning) Environment \"#{ ENV['ENVIRONMENT'] }\" already exists"
@@ -212,7 +329,7 @@ def app_exists?
212329
options_to_remove.each{|opt| opt.delete(:value) }
213330

214331
AWS.elastic_beanstalk.client.update_environment(:environment_name => ENV['ENVIRONMENT'],
215-
:option_settings => rails_options,
332+
:option_settings => all_options,
216333
:options_to_remove => options_to_remove )
217334

218335
new_env_config = AWS.elastic_beanstalk.client.describe_configuration_settings(:application_name=>ENV['APP_NAME'], :environment_name => ENV['ENVIRONMENT'])

0 commit comments

Comments
 (0)