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 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
30 action [:disable, :stop]
33 directory "/srv/community.openstreetmap.org" do
39 directory "/srv/community.openstreetmap.org/shared" do
45 git "/srv/community.openstreetmap.org/docker" do
47 repository "https://github.com/discourse/discourse_docker.git"
52 notifies :run, "notify_group[discourse_container_new_data]"
53 notifies :run, "notify_group[discourse_container_new_web_only]"
54 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
57 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
62 variables :passwords => passwords
63 notifies :run, "notify_group[discourse_container_new_data]"
66 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
67 source "web_only.yml.erb"
71 variables :license_keys => license_keys, :passwords => passwords
72 notifies :run, "notify_group[discourse_container_new_web_only]"
75 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
76 source "mail-receiver.yml.erb"
80 variables :passwords => passwords
81 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
84 ssl_certificate "community.openstreetmap.org" do
85 domains ["community.openstreetmap.org", "community.osm.org", "communities.openstreetmap.org", "communities.osm.org"]
86 notifies :run, "notify_group[discourse_container_new_web_only]"
87 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
90 notify_group "discourse_container_new_web_only" do
91 notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
92 notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
93 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
94 notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
95 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
98 notify_group "discourse_container_new_data" do
99 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
100 notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
101 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
104 notify_group "discourse_container_new_mail_receiver" do
105 notifies :run, "execute[discourse_container_mail_receiver_rebuild]", :immediately
108 # Attempt at a failsafe to ensure all containers are running
109 notify_group "discourse_container_ensure_all_running" do
111 notifies :run, "execute[discourse_container_data_start]", :delayed
112 notifies :run, "execute[discourse_container_web_only_start]", :delayed
113 notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
116 execute "discourse_container_data_start" do
118 command "./launcher start data"
119 cwd "/srv/community.openstreetmap.org/docker/"
124 execute "discourse_container_data_rebuild" do
126 command "./launcher rebuild data"
127 cwd "/srv/community.openstreetmap.org/docker/"
132 execute "discourse_container_web_only_bootstrap" do
134 command "./launcher bootstrap web_only"
135 cwd "/srv/community.openstreetmap.org/docker/"
140 execute "discourse_container_web_only_destroy" do
142 command "./launcher destroy web_only"
143 cwd "/srv/community.openstreetmap.org/docker/"
148 execute "discourse_container_web_only_start" do
150 command "./launcher start web_only"
151 cwd "/srv/community.openstreetmap.org/docker/"
156 # Rebuild: Stop Destroy Bootstap Start
157 execute "discourse_container_mail_receiver_rebuild" do
159 command "./launcher rebuild mail-receiver"
160 cwd "/srv/community.openstreetmap.org/docker/"
165 execute "discourse_container_mail_receiver_start" do
167 command "./launcher start mail-receiver"
168 cwd "/srv/community.openstreetmap.org/docker/"
173 template "/etc/cron.daily/community-backup" do
174 source "backup.cron.erb"
180 node.default[:prometheus][:exporters][443] = {
181 :name => "community",
182 :address => "#{node[:prometheus][:address]}:443",
183 :sni => "community.openstreetmap.org"