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