]> git.openstreetmap.org Git - chef.git/blob - cookbooks/community/recipes/default.rb
kitchen: pre-cache frequent apt packages in container
[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 "main"
49   depth 1
50   user "root"
51   group "root"
52   notifies :run, "execute[discourse_container_data_rebuild]"
53   notifies :run, "execute[discourse_container_web_only_bootstrap]"
54   notifies :run, "execute[discourse_container_mail_receiver_rebuild]"
55 end
56
57 template "/srv/community.openstreetmap.org/docker/containers/data.yml" do
58   source "data.yml.erb"
59   owner "root"
60   group "root"
61   mode "644"
62   variables :passwords => passwords
63   notifies :run, "execute[discourse_container_data_rebuild]"
64 end
65
66 template "/srv/community.openstreetmap.org/docker/containers/web_only.yml" do
67   source "web_only.yml.erb"
68   owner "root"
69   group "root"
70   mode "644"
71   variables :license_keys => license_keys, :passwords => passwords
72   notifies :run, "execute[discourse_container_web_only_bootstrap]"
73 end
74
75 template "/srv/community.openstreetmap.org/docker/containers/mail-receiver.yml" do
76   source "mail-receiver.yml.erb"
77   owner "root"
78   group "root"
79   mode "644"
80   variables :passwords => passwords
81   notifies :run, "execute[discourse_container_mail_receiver_rebuild]"
82 end
83
84 # Destroy Bootstap Start
85 execute "discourse_container_data_rebuild" do
86   action :nothing
87   command "./launcher rebuild data"
88   cwd "/srv/community.openstreetmap.org/docker/"
89   user "root"
90   group "root"
91 end
92
93 ssl_certificate "community.openstreetmap.org" do
94   domains ["community.openstreetmap.org", "community.osm.org", "communities.openstreetmap.org", "communities.osm.org"]
95   notifies :run, "execute[discourse_container_web_only_bootstrap]"
96 end
97
98 execute "discourse_container_data_start" do
99   action :run
100   command "./launcher start data"
101   cwd "/srv/community.openstreetmap.org/docker/"
102   user "root"
103   group "root"
104 end
105
106 execute "discourse_container_web_only_bootstrap" do
107   action :nothing
108   command "./launcher bootstrap web_only"
109   cwd "/srv/community.openstreetmap.org/docker/"
110   user "root"
111   group "root"
112   notifies :run, "execute[discourse_container_web_only_destroy]", :immediately
113 end
114
115 execute "discourse_container_web_only_destroy" do
116   action :nothing
117   command "./launcher destroy web_only"
118   cwd "/srv/community.openstreetmap.org/docker/"
119   user "root"
120   group "root"
121   notifies :run, "execute[discourse_container_web_only_start]", :immediately
122 end
123
124 execute "discourse_container_web_only_start" do
125   action :run
126   command "./launcher start web_only"
127   cwd "/srv/community.openstreetmap.org/docker/"
128   user "root"
129   group "root"
130   notifies :run, "execute[discourse_container_data_start]", :before
131 end
132
133 # Destroy Bootstap Start
134 execute "discourse_container_mail_receiver_rebuild" do
135   action :nothing
136   command "./launcher rebuild mail-receiver"
137   cwd "/srv/community.openstreetmap.org/docker/"
138   user "root"
139   group "root"
140 end
141
142 template "/etc/cron.daily/community-backup" do
143   source "backup.cron.erb"
144   owner "root"
145   group "root"
146   mode "750"
147 end
148
149 node.default[:prometheus][:exporters][443] = {
150   :name => "community",
151   :address => "#{node[:prometheus][:address]}:443",
152   :sni => "community.openstreetmap.org"
153 }