Class: ChatopsDeployer::NginxConfig
- Inherits:
-
Object
- Object
- ChatopsDeployer::NginxConfig
- Includes:
- Logger
- Defined in:
- lib/chatops_deployer/nginx_config.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
-
#add_urls(service_urls) ⇒ Object
service_urls is an array in the format: {“web” => [[“10.1.1.2”, “3000”],[“10.1.1.2”, “4000”]] }.
- #exists? ⇒ Boolean
-
#initialize(project) ⇒ NginxConfig
constructor
A new instance of NginxConfig.
- #prepare_urls ⇒ Object
- #readable_urls ⇒ Object
- #remove ⇒ Object
Methods included from Logger
Constructor Details
#initialize(project) ⇒ NginxConfig
Returns a new instance of NginxConfig.
15 16 17 18 19 20 21 |
# File 'lib/chatops_deployer/nginx_config.rb', line 15 def initialize(project) @sha1 = project.sha1 @project = project check_sites_enabled_dir_exists! @config_path = File.join NGINX_SITES_ENABLED_DIR, @sha1 @urls = {} end |
Instance Attribute Details
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
11 12 13 |
# File 'lib/chatops_deployer/nginx_config.rb', line 11 def urls @urls end |
Instance Method Details
#add_urls(service_urls) ⇒ Object
service_urls is an array in the format: {“web” => [[“10.1.1.2”, “3000”],[“10.1.1.2”, “4000”]] }
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chatops_deployer/nginx_config.rb', line 29 def add_urls(service_urls) return if service_urls.nil? remove if exists? service_urls.each do |service, internal_urls| Array(internal_urls).each do |internal_url| expose(service, internal_url) end end logger.info "Reloading nginx" nginx_reload = Command.run(command: 'service nginx reload', logger: logger) unless nginx_reload.success? raise_error("Cannot reload nginx after adding config. Check #{NGINX_SITES_ENABLED_DIR}/#{@sha1} for errors") end end |
#exists? ⇒ Boolean
23 24 25 |
# File 'lib/chatops_deployer/nginx_config.rb', line 23 def exists? File.exists? @config_path end |
#prepare_urls ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chatops_deployer/nginx_config.rb', line 61 def prepare_urls @project.env['urls'] = {} service_ports_from_config.each do |service, ports| @urls[service] = {} @project.env['urls'][service] = {} ports.each do |port| @urls[service][port.to_s] = generate_haikunated_url @project.env['urls'][service][port.to_s] = "http://#{@urls[service][port.to_s]}" end end end |
#readable_urls ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/chatops_deployer/nginx_config.rb', line 51 def readable_urls urls = {} @urls.each do |service, port_exposed_urls| urls[service] = port_exposed_urls.collect do |port, exposed_url| "http://#{exposed_url}" end end urls.to_json end |
#remove ⇒ Object
45 46 47 48 49 |
# File 'lib/chatops_deployer/nginx_config.rb', line 45 def remove logger.info "Removing nginx config" FileUtils.rm @config_path system('service nginx reload') end |