]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
Add a test for the community cookbook
[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 "geoipupdate"
23 include_recipe "git"
24 include_recipe "ssl"
25
26 passwords = data_bag_item("community", "passwords")
27 license_keys = data_bag_item("geoipupdate", "license-keys") unless kitchen?
28
29 directory "/srv/community.openstreetmap.org" do
30   owner "root"
31   group "root"
32   mode "755"
33 end
34
35 directory "/srv/community.openstreetmap.org/shared" do
36   owner "community"
37   group "community"
38   mode "755"
39 end
40
41 git "/srv/community.openstreetmap.org/docker" do
42   action :sync
43   repository "https://github.com/discourse/discourse_docker.git"
44   revision "main"
45   depth 1
46   user "root"
47   group "root"
48   notifies :run, "execute[discourse_container_data_rebuild]"
49   notifies :run, "execute[discourse_container_web_only_bootstrap]"
50   notifies :run, "execute[discourse_container_mail_receiver_rebuild]"
51 end
52
53 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
54   source "data.yml.erb"
55   owner "root"
56   group "root"
57   mode "644"
58   variables :passwords => passwords
59   notifies :run, "execute[discourse_container_data_rebuild]"
60 end
61
62 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
63   source "web_only.yml.erb"
64   owner "root"
65   group "root"
66   mode "644"
67   variables :license_keys => license_keys, :passwords => passwords
68   notifies :run, "execute[discourse_container_web_only_bootstrap]"
69 end
70
71 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
72   source "mail-receiver.yml.erb"
73   owner "root"
74   group "root"
75   mode "644"
76   variables :passwords => passwords
77   notifies :run, "execute[discourse_container_mail_receiver_rebuild]"
78 end
79
80 # Destroy Bootstap Start
81 execute "discourse_container_data_rebuild" do
82   action :nothing
83   command "./launcher rebuild data"
84   cwd "/srv/community.openstreetmap.org/docker/"
85   user "root"
86   group "root"
87 end
88
89 ssl_certificate "community.openstreetmap.org" do
90   domains ["community.openstreetmap.org", "community.osm.org", "communities.openstreetmap.org", "communities.osm.org"]
91   notifies :run, "execute[discourse_container_web_only_bootstrap]"
92 end
93
94 execute "discourse_container_data_start" do
95   action :run
96   command "./launcher start data"
97   cwd "/srv/community.openstreetmap.org/docker/"
98   user "root"
99   group "root"
100 end
101
102 execute "discourse_container_web_only_bootstrap" do
103   action :nothing
104   command "./launcher bootstrap web_only"
105   cwd "/srv/community.openstreetmap.org/docker/"
106   user "root"
107   group "root"
108   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately
109 end
110
111 execute "discourse_container_web_only_destroy" do
112   action :nothing
113   command "./launcher destroy web_only"
114   cwd "/srv/community.openstreetmap.org/docker/"
115   user "root"
116   group "root"
117   notifies :run, "execute[discourse_container_web_only_start]", :immediately
118 end
119
120 execute "discourse_container_web_only_start" do
121   action :run
122   command "./launcher start web_only"
123   cwd "/srv/community.openstreetmap.org/docker/"
124   user "root"
125   group "root"
126   notifies :run, "execute[discourse_container_data_start]", :before
127 end
128
129 # Destroy Bootstap Start
130 execute "discourse_container_mail_receiver_rebuild" do
131   action :nothing
132   command "./launcher rebuild mail-receiver"
133   cwd "/srv/community.openstreetmap.org/docker/"
134   user "root"
135   group "root"
136 end
137
138 template "/etc/cron.daily/community-backup" do
139   source "backup.cron.erb"
140   owner "root"
141   group "root"
142   mode "750"
143 end
144
145 node.default[:prometheus][:exporters][443] = {
146   :name => "community",
147   :address => "#{node[:prometheus][:address]}:443",
148   :sni => "community.openstreetmap.org"
149 }