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 # Revision pin not possible as launch wrapper automatically updates git repo.
70 notifies :run, "notify_group[discourse_container_new_data]"
71 notifies :run, "notify_group[discourse_container_new_web_only]"
72 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
75 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
80 variables :passwords => passwords
81 notifies :run, "notify_group[discourse_container_new_data]"
84 resolvers = node[:networking][:nameservers].map do |resolver|
85 resolver =~ /:/ ? "[#{resolver}]" : resolver
88 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
89 source "web_only.yml.erb"
93 variables :license_keys => license_keys, :passwords => passwords,
94 :prometheus_servers => prometheus_servers, :resolvers => resolvers
95 notifies :run, "notify_group[discourse_container_new_web_only]"
98 template "/srv/community.openstreetmap.org/files/policyd-spf.conf" do
99 source "policyd-spf.conf.erb"
103 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
106 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
107 source "mail-receiver.yml.erb"
111 variables :passwords => passwords
112 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
115 ssl_certificate "community.openstreetmap.org" do
116 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"]
117 notifies :run, "notify_group[discourse_container_new_web_only]"
118 notifies :run, "notify_group[discourse_container_new_mail_receiver]"
121 notify_group "discourse_container_new_web_only" do
122 notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
123 notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
124 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
125 notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
126 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
129 notify_group "discourse_container_new_data" do
130 notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
131 notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
132 notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
135 notify_group "discourse_container_new_mail_receiver" do
136 notifies :run, "execute[discourse_container_mail_receiver_rebuild]", :immediately
139 # Attempt at a failsafe to ensure all containers are running
140 notify_group "discourse_container_ensure_all_running" do
142 notifies :run, "execute[discourse_container_data_start]", :delayed
143 notifies :run, "execute[discourse_container_web_only_start]", :delayed
144 notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
147 execute "discourse_container_data_start" do
149 command "./launcher start data"
150 cwd "/srv/community.openstreetmap.org/docker/"
155 execute "discourse_container_data_rebuild" do
157 command "./launcher rebuild data"
158 cwd "/srv/community.openstreetmap.org/docker/"
163 execute "discourse_container_web_only_bootstrap" do
165 command "./launcher bootstrap web_only"
166 cwd "/srv/community.openstreetmap.org/docker/"
171 execute "discourse_container_web_only_destroy" do
173 command "./launcher destroy web_only"
174 cwd "/srv/community.openstreetmap.org/docker/"
179 execute "discourse_container_web_only_start" do
181 command "./launcher start web_only"
182 cwd "/srv/community.openstreetmap.org/docker/"
187 # Rebuild: Stop Destroy Bootstap Start
188 execute "discourse_container_mail_receiver_rebuild" do
190 command "./launcher rebuild mail-receiver"
191 cwd "/srv/community.openstreetmap.org/docker/"
196 execute "discourse_container_mail_receiver_start" do
198 command "./launcher start mail-receiver"
199 cwd "/srv/community.openstreetmap.org/docker/"
204 template "/etc/cron.daily/community-backup" do
205 source "backup.cron.erb"
211 node.default[:prometheus][:exporters][443] = {
212 :name => "community",
213 :address => "#{node[:prometheus][:address]}:443",
214 :sni => "community.openstreetmap.org"