5 # Copyright:: 2021, OpenStreetMap Foundation
 
   7 # Licensed under the Apache License, Version 2.0 (the "License");
 
   8 # you may not use this file except in compliance with the License.
 
   9 # You may obtain a copy of the License at
 
  11 #     https://www.apache.org/licenses/LICENSE-2.0
 
  13 # Unless required by applicable law or agreed to in writing, software
 
  14 # distributed under the License is distributed on an "AS IS" BASIS,
 
  15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16 # See the License for the specific language governing permissions and
 
  17 # limitations under the License.
 
  20 include_recipe "accounts"
 
  21 include_recipe "docker"
 
  25 passwords = data_bag_item("community", "passwords")
 
  26 license_keys = data_bag_item("geoipupdate", "license-keys") unless kitchen?
 
  28 prometheus_servers = search(:node, "recipes:prometheus\\:\\:server").map do |server|
 
  29   server.ipaddresses(:role => :external)
 
  32 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
 
  34   action [:disable, :stop]
 
  37 directory "/srv/community.openstreetmap.org" do
 
  43 directory "/srv/community.openstreetmap.org/shared" do
 
  49 directory "/srv/community.openstreetmap.org/files" do
 
  55 template "/srv/community.openstreetmap.org/files/update-feeds.atom" do
 
  56   source "update-feeds.atom.erb"
 
  62 git "/srv/community.openstreetmap.org/docker" do
 
  64   repository "https://github.com/discourse/discourse_docker.git"
 
  65   # DANGER launch wrapper automatically updates git repo if rebuild method used: https://github.com/discourse/discourse_docker/blob/107ffb40fe8b1ea40e00814468db974a4f3f8e8f/launcher#L799
 
  66   revision "b81256c5f1fc1b43ffc52f492cb2935ba9825a2c"
 
  69   notifies :run, "notify_group[discourse_container_new_data]"
 
  70   notifies :run, "notify_group[discourse_container_new_web_only]"
 
  71   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
 
  74 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
 
  79   variables :passwords => passwords
 
  80   notifies :run, "notify_group[discourse_container_new_data]"
 
  83 resolvers = node[:networking][:nameservers].map do |resolver|
 
  84   resolver =~ /:/ ? "[#{resolver}]" : resolver
 
  87 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
 
  88   source "web_only.yml.erb"
 
  92   variables :license_keys => license_keys, :passwords => passwords,
 
  93             :prometheus_servers => prometheus_servers, :resolvers => resolvers
 
  94   notifies :run, "notify_group[discourse_container_new_web_only]"
 
  97 template "/srv/community.openstreetmap.org/files/policyd-spf.conf" do
 
  98   source "policyd-spf.conf.erb"
 
 102   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
 
 105 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
 
 106   source "mail-receiver.yml.erb"
 
 110   variables :passwords => passwords
 
 111   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
 
 114 ssl_certificate "community.openstreetmap.org" do
 
 115   domains ["community.openstreetmap.org", "community.osm.org", "communities.openstreetmap.org", "communities.osm.org", "c.openstreetmap.org", "c.osm.org", "forum.openstreetmap.org", "forum.osm.org"]
 
 116   notifies :run, "notify_group[discourse_container_new_web_only]"
 
 117   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
 
 120 notify_group "discourse_container_new_web_only" do
 
 121   notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
 
 122   notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
 
 123   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
 
 124   notifies :run, "execute[discourse_container_data_destroy]", :immediately # site down
 
 125   notifies :run, "execute[discourse_container_data_bootstrap]", :immediately # site down
 
 126   notifies :run, "execute[discourse_container_data_start]", :immediately # site down
 
 127   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
 
 130 notify_group "discourse_container_new_data" do
 
 131   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
 
 132   notifies :run, "execute[discourse_container_data_destroy]", :immediately # site down
 
 133   notifies :run, "execute[discourse_container_data_bootstrap]", :immediately # site down
 
 134   notifies :run, "execute[discourse_container_data_start]", :immediately # site down
 
 135   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
 
 138 notify_group "discourse_container_new_mail_receiver" do
 
 139   notifies :run, "execute[discourse_container_mail_receiver_destroy]", :immediately
 
 140   notifies :run, "execute[discourse_container_mail_receiver_bootstrap]", :immediately
 
 141   notifies :run, "execute[discourse_container_mail_receiver_start]", :immediately
 
 144 # Attempt at a failsafe to ensure all containers are running
 
 145 notify_group "discourse_container_ensure_all_running" do
 
 147   notifies :run, "execute[discourse_container_data_start]", :delayed
 
 148   notifies :run, "execute[discourse_container_web_only_start]", :delayed
 
 149   notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
 
 152 execute "discourse_container_data_bootstrap" do
 
 154   command "./launcher bootstrap data"
 
 155   cwd "/srv/community.openstreetmap.org/docker/"
 
 158   retries 2 # Postgres upgrades required a second run
 
 161 execute "discourse_container_data_destroy" do
 
 163   command "./launcher destroy data"
 
 164   cwd "/srv/community.openstreetmap.org/docker/"
 
 169 execute "discourse_container_data_start" do
 
 171   command "./launcher start data"
 
 172   cwd "/srv/community.openstreetmap.org/docker/"
 
 177 execute "discourse_container_web_only_bootstrap" do
 
 179   command "./launcher bootstrap web_only"
 
 180   cwd "/srv/community.openstreetmap.org/docker/"
 
 185 execute "discourse_container_web_only_destroy" do
 
 187   command "./launcher destroy web_only"
 
 188   cwd "/srv/community.openstreetmap.org/docker/"
 
 193 execute "discourse_container_web_only_start" do
 
 195   command "./launcher start web_only"
 
 196   cwd "/srv/community.openstreetmap.org/docker/"
 
 201 execute "discourse_container_mail_receiver_bootstrap" do
 
 203   command "./launcher bootstrap mail-receiver"
 
 204   cwd "/srv/community.openstreetmap.org/docker/"
 
 207   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
 
 210 execute "discourse_container_mail_receiver_destroy" do
 
 212   command "./launcher destroy mail-receiver"
 
 213   cwd "/srv/community.openstreetmap.org/docker/"
 
 216   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
 
 219 execute "discourse_container_mail_receiver_start" do
 
 221   command "./launcher start mail-receiver"
 
 222   cwd "/srv/community.openstreetmap.org/docker/"
 
 225   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
 
 228 template "/etc/cron.daily/community-backup" do
 
 229   source "backup.cron.erb"
 
 235 node.default[:prometheus][:exporters][443] = {
 
 236   :name => "community",
 
 237   :address => "#{node[:prometheus][:address]}:443",
 
 238   :sni => "community.openstreetmap.org"