]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
community: Upgrade discourse to v3.3.4 with pg15 upgrade
[chef.git] / cookbooks / community / recipes / default.rb
1 #
2 # Cookbook:: community
3 # Recipe:: default
4 #
5 # Copyright:: 2021, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "accounts"
21 include_recipe "docker"
22 include_recipe "git"
23 include_recipe "ssl"
24
25 passwords = data_bag_item("community", "passwords")
26 license_keys = data_bag_item("geoipupdate", "license-keys") unless kitchen?
27
28 prometheus_servers = search(:node, "recipes:prometheus\\:\\:server").map do |server|
29   server.ipaddresses(:role => :external)
30 end.flatten
31
32 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
33 service "apache2" do
34   action [:disable, :stop]
35 end
36
37 directory "/srv/community.openstreetmap.org" do
38   owner "root"
39   group "root"
40   mode "755"
41 end
42
43 directory "/srv/community.openstreetmap.org/shared" do
44   owner "community"
45   group "community"
46   mode "755"
47 end
48
49 directory "/srv/community.openstreetmap.org/files" do
50   owner "community"
51   group "community"
52   mode "755"
53 end
54
55 template "/srv/community.openstreetmap.org/files/update-feeds.atom" do
56   source "update-feeds.atom.erb"
57   owner "community"
58   group "community"
59   mode "644"
60 end
61
62 git "/srv/community.openstreetmap.org/docker" do
63   action :sync
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 "efd6bc8ccbd9057c04d909ff48ecf8b704cae3ff"
67   user "root"
68   group "root"
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]"
72 end
73
74 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
75   source "data.yml.erb"
76   owner "root"
77   group "root"
78   mode "640"
79   variables :passwords => passwords
80   notifies :run, "notify_group[discourse_container_new_data]"
81 end
82
83 resolvers = node[:networking][:nameservers].map do |resolver|
84   resolver =~ /:/ ? "[#{resolver}]" : resolver
85 end
86
87 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
88   source "web_only.yml.erb"
89   owner "root"
90   group "root"
91   mode "640"
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]"
95 end
96
97 template "/srv/community.openstreetmap.org/files/policyd-spf.conf" do
98   source "policyd-spf.conf.erb"
99   owner "community"
100   group "community"
101   mode "644"
102   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
103 end
104
105 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
106   source "mail-receiver.yml.erb"
107   owner "root"
108   group "root"
109   mode "640"
110   variables :passwords => passwords
111   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
112 end
113
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]"
118 end
119
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
128 end
129
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
136 end
137
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
142 end
143
144 # Attempt at a failsafe to ensure all containers are running
145 notify_group "discourse_container_ensure_all_running" do
146   action :run
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
150 end
151
152 execute "discourse_container_data_bootstrap" do
153   action :nothing
154   command "./launcher bootstrap data"
155   cwd "/srv/community.openstreetmap.org/docker/"
156   user "root"
157   group "root"
158 end
159
160 execute "discourse_container_data_destroy" do
161   action :nothing
162   command "./launcher destroy data"
163   cwd "/srv/community.openstreetmap.org/docker/"
164   user "root"
165   group "root"
166 end
167
168 execute "discourse_container_data_start" do
169   action :nothing
170   command "./launcher start data"
171   cwd "/srv/community.openstreetmap.org/docker/"
172   user "root"
173   group "root"
174 end
175
176 execute "discourse_container_web_only_bootstrap" do
177   action :nothing
178   command "./launcher bootstrap web_only"
179   cwd "/srv/community.openstreetmap.org/docker/"
180   user "root"
181   group "root"
182 end
183
184 execute "discourse_container_web_only_destroy" do
185   action :nothing
186   command "./launcher destroy web_only"
187   cwd "/srv/community.openstreetmap.org/docker/"
188   user "root"
189   group "root"
190 end
191
192 execute "discourse_container_web_only_start" do
193   action :nothing
194   command "./launcher start web_only"
195   cwd "/srv/community.openstreetmap.org/docker/"
196   user "root"
197   group "root"
198 end
199
200 execute "discourse_container_mail_receiver_bootstrap" do
201   action :nothing
202   command "./launcher bootstrap mail-receiver"
203   cwd "/srv/community.openstreetmap.org/docker/"
204   user "root"
205   group "root"
206 end
207
208 execute "discourse_container_mail_receiver_destroy" do
209   action :nothing
210   command "./launcher destroy mail-receiver"
211   cwd "/srv/community.openstreetmap.org/docker/"
212   user "root"
213   group "root"
214 end
215
216 execute "discourse_container_mail_receiver_start" do
217   action :nothing
218   command "./launcher start mail-receiver"
219   cwd "/srv/community.openstreetmap.org/docker/"
220   user "root"
221   group "root"
222 end
223
224 template "/etc/cron.daily/community-backup" do
225   source "backup.cron.erb"
226   owner "root"
227   group "root"
228   mode "750"
229 end
230
231 node.default[:prometheus][:exporters][443] = {
232   :name => "community",
233   :address => "#{node[:prometheus][:address]}:443",
234   :sni => "community.openstreetmap.org"
235 }