]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
Give GHA explicit package read permission
[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   # Revision pin not possible as launch wrapper automatically updates git repo.
66   revision "main"
67   depth 1
68   user "root"
69   group "root"
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]"
73 end
74
75 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
76   source "data.yml.erb"
77   owner "root"
78   group "root"
79   mode "640"
80   variables :passwords => passwords
81   notifies :run, "notify_group[discourse_container_new_data]"
82 end
83
84 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
85   source "web_only.yml.erb"
86   owner "root"
87   group "root"
88   mode "640"
89   variables :license_keys => license_keys, :passwords => passwords,
90             :prometheus_servers => prometheus_servers
91   notifies :run, "notify_group[discourse_container_new_web_only]"
92 end
93
94 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
95   source "mail-receiver.yml.erb"
96   owner "root"
97   group "root"
98   mode "640"
99   variables :passwords => passwords
100   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
101 end
102
103 ssl_certificate "community.openstreetmap.org" do
104   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"]
105   notifies :run, "notify_group[discourse_container_new_web_only]"
106   notifies :run, "notify_group[discourse_container_new_mail_receiver]"
107 end
108
109 notify_group "discourse_container_new_web_only" do
110   notifies :run, "execute[discourse_container_data_start]", :immediately # noop if site up
111   notifies :run, "execute[discourse_container_web_only_bootstrap]", :immediately # site up but runs in parallel. Slow
112   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
113   notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
114   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
115 end
116
117 notify_group "discourse_container_new_data" do
118   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately # site down
119   notifies :run, "execute[discourse_container_data_rebuild]", :immediately # site down
120   notifies :run, "execute[discourse_container_web_only_start]", :immediately # site restore
121 end
122
123 notify_group "discourse_container_new_mail_receiver" do
124   notifies :run, "execute[discourse_container_mail_receiver_rebuild]", :immediately
125 end
126
127 # Attempt at a failsafe to ensure all containers are running
128 notify_group "discourse_container_ensure_all_running" do
129   action :run
130   notifies :run, "execute[discourse_container_data_start]", :delayed
131   notifies :run, "execute[discourse_container_web_only_start]", :delayed
132   notifies :run, "execute[discourse_container_mail_receiver_start]", :delayed
133 end
134
135 execute "discourse_container_data_start" do
136   action :nothing
137   command "./launcher start data"
138   cwd "/srv/community.openstreetmap.org/docker/"
139   user "root"
140   group "root"
141 end
142
143 execute "discourse_container_data_rebuild" do
144   action :nothing
145   command "./launcher rebuild data"
146   cwd "/srv/community.openstreetmap.org/docker/"
147   user "root"
148   group "root"
149 end
150
151 execute "discourse_container_web_only_bootstrap" do
152   action :nothing
153   command "./launcher bootstrap web_only"
154   cwd "/srv/community.openstreetmap.org/docker/"
155   user "root"
156   group "root"
157 end
158
159 execute "discourse_container_web_only_destroy" do
160   action :nothing
161   command "./launcher destroy web_only"
162   cwd "/srv/community.openstreetmap.org/docker/"
163   user "root"
164   group "root"
165 end
166
167 execute "discourse_container_web_only_start" do
168   action :nothing
169   command "./launcher start web_only"
170   cwd "/srv/community.openstreetmap.org/docker/"
171   user "root"
172   group "root"
173 end
174
175 # Rebuild: Stop Destroy Bootstap Start
176 execute "discourse_container_mail_receiver_rebuild" do
177   action :nothing
178   command "./launcher rebuild mail-receiver"
179   cwd "/srv/community.openstreetmap.org/docker/"
180   user "root"
181   group "root"
182 end
183
184 execute "discourse_container_mail_receiver_start" do
185   action :nothing
186   command "./launcher start mail-receiver"
187   cwd "/srv/community.openstreetmap.org/docker/"
188   user "root"
189   group "root"
190 end
191
192 template "/etc/cron.daily/community-backup" do
193   source "backup.cron.erb"
194   owner "root"
195   group "root"
196   mode "750"
197 end
198
199 node.default[:prometheus][:exporters][443] = {
200   :name => "community",
201   :address => "#{node[:prometheus][:address]}:443",
202   :sni => "community.openstreetmap.org"
203 }