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 "docker"
24 passwords = data_bag_item("community", "passwords")
25 license_keys = data_bag_item("geoipupdate", "license-keys") unless kitchen?
27 prometheus_servers = search(:node, "recipes:prometheus\\:\\:server").map do |server|
28 server.ipaddresses(:role => :external)
39 comment "community.openstreetmap.org"
40 home "/srv/community.openstreetmap.org"
41 shell "/usr/sbin/nologin"
45 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
47 action [:disable, :stop]
50 directory "/srv/community.openstreetmap.org" do
56 directory "/srv/community.openstreetmap.org/shared" do
62 directory "/srv/community.openstreetmap.org/files" do
68 template "/srv/community.openstreetmap.org/files/update-feeds.atom" do
69 source "update-feeds.atom.erb"
75 git "/srv/community.openstreetmap.org/docker" do
77 repository "https://github.com/discourse/discourse_docker.git"
78 # DANGER launch wrapper automatically updates git repo if rebuild method used: https://github.com/discourse/discourse_docker/blob/107ffb40fe8b1ea40e00814468db974a4f3f8e8f/launcher#L799
79 revision "9384b129e5031370c4a26935a6987bd3b5b416de"
82 notifies :run, "notify_group[discourse_container_new_data]"
83 notifies :run, "notify_group[discourse_container_new_web_only]"
84 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
87 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
92 variables :passwords => passwords
93 notifies :run, "notify_group[discourse_container_new_data]"
96 resolvers = node[:networking][:nameservers].map do |resolver|
97 resolver =~ /:/ ? "[#{resolver}]" : resolver
100 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
101 source "web_only.yml.erb"
105 variables :license_keys => license_keys, :passwords => passwords,
106 :prometheus_servers => prometheus_servers, :resolvers => resolvers
107 notifies :run, "notify_group[discourse_container_new_web_only]"
110 template "/srv/community.openstreetmap.org/files/policyd-spf.conf" do
111 source "policyd-spf.conf.erb"
115 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
118 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
119 source "mail-receiver.yml.erb"
123 variables :passwords => passwords
124 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
127 ssl_certificate "community.openstreetmap.org" do
128 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"]
129 notifies :run, "notify_group[discourse_container_new_web_only]"
130 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
133 notify_group "discourse_container_new_web_only" do
134 notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
135 notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
136 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
137 notifies :run, "execute[discourse_container_data_destroy]", :immediately # site down
138 notifies :run, "execute[discourse_container_data_bootstrap]", :immediately # site down
139 notifies :run, "execute[discourse_container_data_start]", :immediately # site down
140 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
143 notify_group "discourse_container_new_data" do
144 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
145 notifies :run, "execute[discourse_container_data_destroy]", :immediately # site down
146 notifies :run, "execute[discourse_container_data_bootstrap]", :immediately # site down
147 notifies :run, "execute[discourse_container_data_start]", :immediately # site down
148 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
151 notify_group "discourse_container_new_mail_receiver" do
152 notifies :run, "execute[discourse_container_mail_receiver_destroy]", :immediately
153 notifies :run, "execute[discourse_container_mail_receiver_bootstrap]", :immediately
154 notifies :run, "execute[discourse_container_mail_receiver_start]", :immediately
157 # Attempt at a failsafe to ensure all containers are running
158 notify_group "discourse_container_ensure_all_running" do
160 notifies :run, "execute[discourse_container_data_start]", :delayed
161 notifies :run, "execute[discourse_container_web_only_start]", :delayed
162 notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
165 execute "discourse_container_data_bootstrap" do
167 command "./launcher bootstrap data"
168 cwd "/srv/community.openstreetmap.org/docker/"
171 retries 2 # Postgres upgrades required a second run
174 execute "discourse_container_data_destroy" do
176 command "./launcher destroy data"
177 cwd "/srv/community.openstreetmap.org/docker/"
182 execute "discourse_container_data_start" do
184 command "./launcher start data"
185 cwd "/srv/community.openstreetmap.org/docker/"
190 execute "discourse_container_web_only_bootstrap" do
192 command "./launcher bootstrap web_only"
193 cwd "/srv/community.openstreetmap.org/docker/"
198 execute "discourse_container_web_only_destroy" do
200 command "./launcher destroy web_only"
201 cwd "/srv/community.openstreetmap.org/docker/"
206 execute "discourse_container_web_only_start" do
208 command "./launcher start web_only"
209 cwd "/srv/community.openstreetmap.org/docker/"
214 execute "discourse_container_mail_receiver_bootstrap" do
216 command "./launcher bootstrap mail-receiver"
217 cwd "/srv/community.openstreetmap.org/docker/"
220 not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
223 execute "discourse_container_mail_receiver_destroy" do
225 command "./launcher destroy mail-receiver"
226 cwd "/srv/community.openstreetmap.org/docker/"
229 not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
232 execute "discourse_container_mail_receiver_start" do
234 command "./launcher start mail-receiver"
235 cwd "/srv/community.openstreetmap.org/docker/"
238 not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
241 template "/etc/cron.daily/community-backup" do
242 source "backup.cron.erb"
248 node.default[:prometheus][:exporters][443] = {
249 :name => "community",
250 :address => "#{node[:prometheus][:address]}:443",
251 :sni => "community.openstreetmap.org"