2023-07-26 15:44:04 +02:00

53 lines
1.5 KiB
Ruby

#
# Cookbook Name:: kosmos-mastodon
# Recipe:: nginx
#
app_dir = node["kosmos-mastodon"]["directory"]
server_name = node["kosmos-mastodon"]["domain"]
upstream_hosts = []
search(:node, "role:mastodon").each do |node|
upstream_hosts << node["knife_zero"]["host"]
end
if upstream_hosts.any?
web_root_dir = "/var/www/#{server_name}/public"
else
web_root_dir = "#{app_dir}/public"
upstream_hosts << "localhost"
end
directory "#{node['openresty']['dir']}/snippets" do
action :create
owner 'www-data'
mode 0640
end
template "#{node['openresty']['dir']}/snippets/mastodon.conf" do
source 'nginx_conf_shared.erb'
owner 'www-data'
mode 0640
variables web_root_dir: web_root_dir,
server_name: server_name
notifies :reload, 'service[openresty]', :delayed
end
tls_cert_for server_name do
auth "gandi_dns"
action :create
end
onion_address = File.read("/var/lib/tor/web/hostname").strip rescue nil rescue nil
openresty_site server_name do
template 'nginx_conf_mastodon.erb'
variables server_name: server_name,
ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem",
ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem",
shared_config_path: "#{node['openresty']['dir']}/snippets/mastodon.conf",
app_port: node["kosmos-mastodon"]["app_port"],
streaming_port: node["kosmos-mastodon"]["streaming_port"],
onion_address: onion_address,
upstream_hosts: upstream_hosts
end