]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
Use volume for nested podman container storage
[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 "docker"
21 include_recipe "git"
22 include_recipe "ssl"
23
24 passwords = data_bag_item("community", "passwords")
25 license_keys = data_bag_item("geoipupdate", "license-keys") unless kitchen?
26
27 prometheus_servers = search(:node, "recipes:prometheus\\:\\:server").map do |server|
28   server.ipaddresses(:role => :external)
29 end.flatten
30
31 group "community" do
32   gid 527
33   append true
34 end
35
36 user "community" do
37   uid 527
38   gid 527
39   comment "community.openstreetmap.org"
40   home "/srv/community.openstreetmap.org"
41   shell "/usr/sbin/nologin"
42   manage_home false
43 end
44
45 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
46 service "apache2" do
47   action [:disable, :stop]
48 end
49
50 directory "/srv/community.openstreetmap.org" do
51   owner "root"
52   group "root"
53   mode "755"
54 end
55
56 directory "/srv/community.openstreetmap.org/shared" do
57   owner "community"
58   group "community"
59   mode "755"
60 end
61
62 directory "/srv/community.openstreetmap.org/files" do
63   owner "community"
64   group "community"
65   mode "755"
66 end
67
68 template "/srv/community.openstreetmap.org/files/update-feeds.atom" do
69   source "update-feeds.atom.erb"
70   owner "community"
71   group "community"
72   mode "644"
73 end
74
75 git "/srv/community.openstreetmap.org/docker" do
76   action :sync
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"
80   user "root"
81   group "root"
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]"
85 end
86
87 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
88   source "data.yml.erb"
89   owner "root"
90   group "root"
91   mode "640"
92   variables :passwords => passwords
93   notifies :run, "notify_group[discourse_container_new_data]"
94 end
95
96 resolvers = node[:networking][:nameservers].map do |resolver|
97   resolver =~ /:/ ? "[#{resolver}]" : resolver
98 end
99
100 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
101   source "web_only.yml.erb"
102   owner "root"
103   group "root"
104   mode "640"
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]"
108 end
109
110 template "/srv/community.openstreetmap.org/files/policyd-spf.conf" do
111   source "policyd-spf.conf.erb"
112   owner "community"
113   group "community"
114   mode "644"
115   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
116 end
117
118 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
119   source "mail-receiver.yml.erb"
120   owner "root"
121   group "root"
122   mode "640"
123   variables :passwords => passwords
124   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
125 end
126
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]"
131 end
132
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
141 end
142
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
149 end
150
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
155 end
156
157 # Attempt at a failsafe to ensure all containers are running
158 notify_group "discourse_container_ensure_all_running" do
159   action :run
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
163 end
164
165 execute "discourse_container_data_bootstrap" do
166   action :nothing
167   command "./launcher bootstrap data"
168   cwd "/srv/community.openstreetmap.org/docker/"
169   user "root"
170   group "root"
171   retries 2 # Postgres upgrades required a second run
172 end
173
174 execute "discourse_container_data_destroy" do
175   action :nothing
176   command "./launcher destroy data"
177   cwd "/srv/community.openstreetmap.org/docker/"
178   user "root"
179   group "root"
180 end
181
182 execute "discourse_container_data_start" do
183   action :nothing
184   command "./launcher start data"
185   cwd "/srv/community.openstreetmap.org/docker/"
186   user "root"
187   group "root"
188 end
189
190 execute "discourse_container_web_only_bootstrap" do
191   action :nothing
192   command "./launcher bootstrap web_only"
193   cwd "/srv/community.openstreetmap.org/docker/"
194   user "root"
195   group "root"
196 end
197
198 execute "discourse_container_web_only_destroy" do
199   action :nothing
200   command "./launcher destroy web_only"
201   cwd "/srv/community.openstreetmap.org/docker/"
202   user "root"
203   group "root"
204 end
205
206 execute "discourse_container_web_only_start" do
207   action :nothing
208   command "./launcher start web_only"
209   cwd "/srv/community.openstreetmap.org/docker/"
210   user "root"
211   group "root"
212 end
213
214 execute "discourse_container_mail_receiver_bootstrap" do
215   action :nothing
216   command "./launcher bootstrap mail-receiver"
217   cwd "/srv/community.openstreetmap.org/docker/"
218   user "root"
219   group "root"
220   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
221 end
222
223 execute "discourse_container_mail_receiver_destroy" do
224   action :nothing
225   command "./launcher destroy mail-receiver"
226   cwd "/srv/community.openstreetmap.org/docker/"
227   user "root"
228   group "root"
229   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
230 end
231
232 execute "discourse_container_mail_receiver_start" do
233   action :nothing
234   command "./launcher start mail-receiver"
235   cwd "/srv/community.openstreetmap.org/docker/"
236   user "root"
237   group "root"
238   not_if { arm? } # Not yet supported on ARM https://github.com/discourse/mail-receiver/pull/28
239 end
240
241 template "/etc/cron.daily/community-backup" do
242   source "backup.cron.erb"
243   owner "root"
244   group "root"
245   mode "750"
246 end
247
248 node.default[:prometheus][:exporters][443] = {
249   :name => "community",
250   :address => "#{node[:prometheus][:address]}:443",
251   :sni => "community.openstreetmap.org"
252 }