]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
7c4d374a8bae437679c7f74fc2c377620f7d8a83
[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 # Disable any default installed apache2 service. Web server is embedded within the discourse docker container
29 service "apache2" do
30   action [:disable, :stop]
31 end
32
33 directory "/srv/community.openstreetmap.org" do
34   owner "root"
35   group "root"
36   mode "755"
37 end
38
39 directory "/srv/community.openstreetmap.org/shared" do
40   owner "community"
41   group "community"
42   mode "755"
43 end
44
45 git "/srv/community.openstreetmap.org/docker" do
46   action :sync
47   repository "https://github.com/discourse/discourse_docker.git"
48   # Revision pin not possible as launch wrapper automatically updates git repo.
49   revision "main"
50   depth 1
51   user "root"
52   group "root"
53   notifies :run, "notify_group[discourse_container_new_data]"
54   notifies :run, "notify_group[discourse_container_new_web_only]"
55   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
56 end
57
58 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
59   source "data.yml.erb"
60   owner "root"
61   group "root"
62   mode "640"
63   variables :passwords => passwords
64   notifies :run, "notify_group[discourse_container_new_data]"
65 end
66
67 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
68   source "web_only.yml.erb"
69   owner "root"
70   group "root"
71   mode "640"
72   variables :license_keys => license_keys, :passwords => passwords
73   notifies :run, "notify_group[discourse_container_new_web_only]"
74 end
75
76 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
77   source "mail-receiver.yml.erb"
78   owner "root"
79   group "root"
80   mode "640"
81   variables :passwords => passwords
82   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
83 end
84
85 ssl_certificate "community.openstreetmap.org" do
86   domains ["community.openstreetmap.org", "community.osm.org", "communities.openstreetmap.org", "communities.osm.org", "c.openstreetmap.org", "c.osm.org"]
87   notifies :run, "notify_group[discourse_container_new_web_only]"
88   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
89 end
90
91 notify_group "discourse_container_new_web_only" do
92   notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
93   notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
94   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
95   notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
96   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
97 end
98
99 notify_group "discourse_container_new_data" do
100   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
101   notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
102   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
103 end
104
105 notify_group "discourse_container_new_mail_receiver" do
106   notifies :run, "execute[discourse_container_mail_receiver_rebuild]", :immediately
107 end
108
109 # Attempt at a failsafe to ensure all containers are running
110 notify_group "discourse_container_ensure_all_running" do
111   action :run
112   notifies :run, "execute[discourse_container_data_start]", :delayed
113   notifies :run, "execute[discourse_container_web_only_start]", :delayed
114   notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
115 end
116
117 execute "discourse_container_data_start" do
118   action :nothing
119   command "./launcher start data"
120   cwd "/srv/community.openstreetmap.org/docker/"
121   user "root"
122   group "root"
123 end
124
125 execute "discourse_container_data_rebuild" do
126   action :nothing
127   command "./launcher rebuild data"
128   cwd "/srv/community.openstreetmap.org/docker/"
129   user "root"
130   group "root"
131 end
132
133 execute "discourse_container_web_only_bootstrap" do
134   action :nothing
135   command "./launcher bootstrap web_only"
136   cwd "/srv/community.openstreetmap.org/docker/"
137   user "root"
138   group "root"
139 end
140
141 execute "discourse_container_web_only_destroy" do
142   action :nothing
143   command "./launcher destroy web_only"
144   cwd "/srv/community.openstreetmap.org/docker/"
145   user "root"
146   group "root"
147 end
148
149 execute "discourse_container_web_only_start" do
150   action :nothing
151   command "./launcher start web_only"
152   cwd "/srv/community.openstreetmap.org/docker/"
153   user "root"
154   group "root"
155 end
156
157 # Rebuild: Stop Destroy Bootstap Start
158 execute "discourse_container_mail_receiver_rebuild" do
159   action :nothing
160   command "./launcher rebuild mail-receiver"
161   cwd "/srv/community.openstreetmap.org/docker/"
162   user "root"
163   group "root"
164 end
165
166 execute "discourse_container_mail_receiver_start" do
167   action :nothing
168   command "./launcher start mail-receiver"
169   cwd "/srv/community.openstreetmap.org/docker/"
170   user "root"
171   group "root"
172 end
173
174 template "/etc/cron.daily/community-backup" do
175   source "backup.cron.erb"
176   owner "root"
177   group "root"
178   mode "750"
179 end
180
181 node.default[:prometheus][:exporters][443] = {
182   :name => "community",
183   :address => "#{node[:prometheus][:address]}:443",
184   :sni => "community.openstreetmap.org"
185 }