Class: Veronic::Deployer
- Inherits:
-
Object
- Object
- Veronic::Deployer
- Defined in:
- lib/veronic.rb
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #cloudprovider ⇒ Object
- #config(options = {}) ⇒ Object
- #config_hash ⇒ Object
- #configprovider ⇒ Object
- #create ⇒ Object
- #create_image ⇒ Object
- #deploy ⇒ Object
- #deploy_apps ⇒ Object
- #deploy_stacks ⇒ Object
- #destroy ⇒ Object
- #dnsprovider ⇒ Object
- #get_availability_zone ⇒ Object
- #get_image ⇒ Object
-
#initialize(options = {}) ⇒ Deployer
constructor
A new instance of Deployer.
- #instances_list ⇒ Object
- #logger ⇒ Object
- #run_tests ⇒ Object
- #search_and_deploy ⇒ Object
- #set_node ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
- #update_instance_dns ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Deployer
Returns a new instance of Deployer.
11 12 13 14 |
# File 'lib/veronic.rb', line 11 def initialize(={}) @config = config() @logger = logger end |
Instance Method Details
#bootstrap ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/veronic.rb', line 153 def bootstrap status = false if cloudprovider.instance.status == :running @logger.info "#{@config.name} is running" elsif cloudprovider.instance.status == :stopped start elsif cloudprovider.instance.exists? == false @config.availability_zone = get_availability_zone get_image configprovider.instance.client.destroy configprovider.instance.bootstrap status = true else abort('Error during connecting instance') end set_node return status end |
#cloudprovider ⇒ Object
41 42 43 |
# File 'lib/veronic.rb', line 41 def cloudprovider CloudProvider.new(config_hash) end |
#config(options = {}) ⇒ Object
21 22 23 |
# File 'lib/veronic.rb', line 21 def config @config || Veronic::Config.new end |
#config_hash ⇒ Object
29 30 31 |
# File 'lib/veronic.rb', line 29 def config_hash @config.to_hash end |
#configprovider ⇒ Object
33 34 35 |
# File 'lib/veronic.rb', line 33 def configprovider ConfigProvider.new(config_hash) end |
#create ⇒ Object
45 46 47 48 49 |
# File 'lib/veronic.rb', line 45 def create unless bootstrap configprovider.instance.create end end |
#create_image ⇒ Object
172 173 174 175 176 177 |
# File 'lib/veronic.rb', line 172 def create_image configprovider.instance.delete_client_key(cloudprovider.instance.dns_name) configprovider.instance.client.destroy cloudprovider.image.detroy cloudprovider.instance.create_image end |
#deploy ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/veronic.rb', line 97 def deploy unless @config.deploy_cmd abort('Arguments --deploy_cmd is missing') end bootstrap query = cloudprovider.instance.dns_name manual = true configprovider.ssh(query, @config.deploy_cmd, manual) end |
#deploy_apps ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/veronic.rb', line 59 def deploy_apps if bootstrap deploy_stacks end query = cloudprovider.instance.dns_name deploy_cmd = "sudo chef-client -o 'recipe[lift_envs::app_deploy]' #{@config.verbose ? '-l ' + @config.verbose : ''}" manual = true configprovider.ssh(query, deploy_cmd, manual) end |
#deploy_stacks ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/veronic.rb', line 51 def deploy_stacks bootstrap query = cloudprovider.instance.dns_name deploy_cmd = "sudo chef-client #{@config.verbose ? '-l ' + @config.verbose : ''}" manual = true configprovider.ssh(query, deploy_cmd, manual) end |
#destroy ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/veronic.rb', line 80 def destroy @config.dnsprovider_zones.each do |z| @config.zone_name = z['zone_name'] @config.zone_url = z['zone_url'] dns = "#{@config.name}.#{z['zone_name']}" @logger.info "Setting DNS #{dns} ..." record = dnsprovider.zone.record(dns, [], "A", "1").delete @logger.info "DNS #{dns} deleted" end if cloudprovider.instance.exists? configprovider.instance.destroy([cloudprovider.instance.id]) else configprovider.instance.destroy([]) end end |
#dnsprovider ⇒ Object
37 38 39 |
# File 'lib/veronic.rb', line 37 def dnsprovider DnsProvider.new(config_hash) end |
#get_availability_zone ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/veronic.rb', line 198 def get_availability_zone @logger.info "Getting availability zone ..." environments = {} if @config.availability_zone.nil? || @config.availability_zone == 'auto' cloudprovider.regions.each do |region| region.instances.each do |instance| if instance.[:environment] && instance.[:role] && instance.status != :shutting_down && instance.status != :terminated environments[instance.[:environment]] = {} unless environments[instance.[:environment]] environments[instance.[:environment]][instance.[:role]] = {} unless environments[instance.[:environment]][instance.[:role]] environments[instance.[:environment]][instance.[:role]][region.name] = {} unless environments[instance.[:environment]][instance.[:role]][region.name] region.availability_zones.each do |availability_zone| environments[instance.[:environment]][instance.[:role]][region.name][availability_zone.name] = [] unless environments[instance.[:environment]][instance.[:role]][region.name][availability_zone.name] end environments[instance.[:environment]][instance.[:role]][region.name][instance.availability_zone] << instance.id end end end end if environments[@config.environment] && environments[@config.environment][@config.role] && environments[@config.environment][@config.role][@config.region] availability_zones = environments[@config.environment][@config.role][@config.region].sort_by { |availability_zone| availability_zone[1].count } @logger.info "Zones: " + availability_zones.to_s availability_zone = availability_zones.first @logger.info "Zone selected: " + availability_zone[0] availability_zone[0] end end |
#get_image ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/veronic.rb', line 190 def get_image if @config.image.nil? abort('Arguments --ami_image is missing') else @config.image = cloudprovider.image.id end end |
#instances_list ⇒ Object
131 132 133 |
# File 'lib/veronic.rb', line 131 def instances_list cloudprovider.instances_list end |
#logger ⇒ Object
16 17 18 19 |
# File 'lib/veronic.rb', line 16 def logger $stderr.sync = true Logger.new($stderr) end |
#run_tests ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/veronic.rb', line 69 def run_tests if bootstrap deploy_stacks deploy_apps end query = cloudprovider.instance.dns_name deploy_cmd = "sudo chef-client -o 'recipe[lift_envs::app_testing]' #{@config.verbose ? '-l ' + @config.verbose : ''}" manual = true configprovider.ssh(query, deploy_cmd, manual) end |
#search_and_deploy ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/veronic.rb', line 107 def search_and_deploy unless @config.deploy_cmd || @config.query abort('Arguments --deploy_cmd or --query is missing') end query = @config.query manual = false configprovider.ssh(query, @config.deploy_cmd, manual) end |
#set_node ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/veronic.rb', line 179 def set_node update_instance_dns if @config.role && @config.environment configprovider.instance.set_environment configprovider.instance.set_role cloudprovider.instance.({'role' => @config.role, 'environment' => @config.environment}) else @logger.info 'Unable to set_node arguments --role or --environment is missing' end end |
#start ⇒ Object
139 140 141 142 143 |
# File 'lib/veronic.rb', line 139 def start unless cloudprovider.instance.start == false exit 1 end end |
#status ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/veronic.rb', line 145 def status if @config.name return cloudprovider.instance.status else return "Arguments --name is missing" end end |
#stop ⇒ Object
135 136 137 |
# File 'lib/veronic.rb', line 135 def stop cloudprovider.instance.stop end |
#update_instance_dns ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/veronic.rb', line 116 def update_instance_dns if @config.dnsprovider_zones @config.dnsprovider_zones.each do |z| @config.zone_name = z['zone_name'] @config.zone_url = z['zone_url'] dns = "#{@config.name}.#{z['zone_name']}" @logger.info "Setting DNS #{dns} ..." record = dnsprovider.zone.record(dns, [cloudprovider.instance.dns_name], "CNAME", "1").wait_set @logger.info "DNS #{dns} updated" end else @logger.info "Unabled to update DNS" end end |