Class: Nginx::Builder::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_infrastructure/nginx/builder.rb

Direct Known Subclasses

ReverseProxyHttp, ReverseProxyHttps, Site

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*server_blocks, domain: nil) ⇒ Base

Returns a new instance of Base.



37
38
39
40
41
42
# File 'lib/shared_infrastructure/nginx/builder.rb', line 37

def initialize(*server_blocks, domain: nil)
  # puts "Base#initialize domain_name: #{domain_name}"
  # puts "Base#initialize server_blocks.inspect: #{server_blocks.inspect}"
  @server_blocks = server_blocks
  @domain = domain
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



57
58
59
# File 'lib/shared_infrastructure/nginx/builder.rb', line 57

def domain
  @domain
end

#server_blocksObject (readonly)

Returns the value of attribute server_blocks.



57
58
59
# File 'lib/shared_infrastructure/nginx/builder.rb', line 57

def server_blocks
  @server_blocks
end

Instance Method Details

#https_reminder_messageObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shared_infrastructure/nginx/builder.rb', line 19

def https_reminder_message
  puts %(You have to obtain a certificate and enable TLS for the site.
To do so, reload the Nginx configuration:

sudo nginx -s reload

Then run the following command:

sudo certbot certonly --webroot -w #{Nginx.root_directory(domain.domain_name)} #{domain.certbot_domain_names}

You can test renewal with:

sudo certbot renew --dry-run

Finally, re-run this script to configure nginx for TLS.
)
end

#saveObject



44
45
46
47
48
49
50
51
# File 'lib/shared_infrastructure/nginx/builder.rb', line 44

def save
  puts "writing server block: #{Nginx.server_block_location(domain.domain_name)}" if Runner.debug
  File.open(Nginx.server_block_location(domain.domain_name), "w") do |f|
    f << to_s
  end
  puts "enabling site" if Runner.debug
  `ln -fs ../sites-available/#{domain.domain_name} #{Nginx.enabled_server_block_location(domain.domain_name)}`
end

#to_sObject



53
54
55
# File 'lib/shared_infrastructure/nginx/builder.rb', line 53

def to_s
  server_blocks.map(&:to_s).join("\n")
end