]> git.openstreetmap.org Git - chef.git/blob - cookbooks/stateofthemap/recipes/default.rb
stateofthemap: Use multiple threads for bundle
[chef.git] / cookbooks / stateofthemap / recipes / default.rb
1 #
2 # Cookbook:: stateofthemap
3 # Recipe:: default
4 #
5 # Copyright:: 2013, 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 "wordpress"
21
22 passwords = data_bag_item("stateofthemap", "passwords")
23
24 git "/srv/stateofthemap.org" do
25   action :sync
26   repository "https://git.openstreetmap.org/public/stateofthemap.git"
27   revision "chooser"
28   depth 1
29   user "root"
30   group "root"
31 end
32
33 ssl_certificate "stateofthemap.org" do
34   domains ["stateofthemap.org", "www.stateofthemap.org",
35            "stateofthemap.com", "www.stateofthemap.com",
36            "sotm.org", "www.sotm.org"]
37   notifies :reload, "service[apache2]"
38 end
39
40 apache_site "stateofthemap.org" do
41   template "apache.erb"
42   directory "/srv/stateofthemap.org"
43 end
44
45 directory "/srv/2007.stateofthemap.org" do
46   owner "wordpress"
47   group "wordpress"
48   mode "755"
49 end
50
51 wordpress_site "2007.stateofthemap.org" do
52   aliases "2007.stateofthemap.com"
53   directory "/srv/2007.stateofthemap.org/wp"
54   database_name "sotm2007"
55   database_user "sotm2007"
56   database_password passwords["sotm2007"]
57   database_prefix "wp_sotm_"
58   fpm_prometheus_port 12007
59 end
60
61 wordpress_theme "2007.stateofthemap.org-refreshwp-11" do
62   theme "refreshwp-11"
63   site "2007.stateofthemap.org"
64   repository "https://git.openstreetmap.org/public/stateofthemap.git"
65   revision "theme-2007"
66 end
67
68 wordpress_plugin "2007.stateofthemap.org-geopress" do
69   plugin "geopress"
70   site "2007.stateofthemap.org"
71 end
72
73 directory "/srv/2008.stateofthemap.org" do
74   owner "wordpress"
75   group "wordpress"
76   mode "755"
77 end
78
79 wordpress_site "2008.stateofthemap.org" do
80   aliases "2008.stateofthemap.com"
81   directory "/srv/2008.stateofthemap.org/wp"
82   database_name "sotm2008"
83   database_user "sotm2008"
84   database_password passwords["sotm2008"]
85   database_prefix "wp_sotm08_"
86   fpm_prometheus_port 12008
87 end
88
89 wordpress_theme "2008.stateofthemap.org-refreshwp-11" do
90   theme "refreshwp-11"
91   site "2008.stateofthemap.org"
92   repository "https://git.openstreetmap.org/public/stateofthemap.git"
93   revision "theme-2008"
94 end
95
96 wordpress_plugin "2008.stateofthemap.org-geopress" do
97   plugin "geopress"
98   site "2008.stateofthemap.org"
99 end
100
101 directory "/srv/2009.stateofthemap.org" do
102   owner "wordpress"
103   group "wordpress"
104   mode "755"
105 end
106
107 git "/srv/2009.stateofthemap.org" do
108   action :sync
109   repository "https://git.openstreetmap.org/public/stateofthemap.git"
110   revision "resources-2009"
111   depth 1
112   user "wordpress"
113   group "wordpress"
114 end
115
116 wordpress_site "2009.stateofthemap.org" do
117   aliases "2009.stateofthemap.com"
118   directory "/srv/2009.stateofthemap.org/wp"
119   database_name "sotm2009"
120   database_user "sotm2009"
121   database_password passwords["sotm2009"]
122   urls "/register" => "/srv/2009.stateofthemap.org/register",
123        "/register-pro-user" => "/srv/2009.stateofthemap.org/register-pro-user",
124        "/podcasts" => "/srv/2009.stateofthemap.org/podcasts"
125   fpm_prometheus_port 12009
126 end
127
128 wordpress_theme "2009.stateofthemap.org-aerodrome" do
129   theme "aerodrome"
130   site "2009.stateofthemap.org"
131   repository "https://git.openstreetmap.org/public/stateofthemap.git"
132   revision "theme-2009"
133 end
134
135 wordpress_plugin "2009.stateofthemap.org-wp-sticky" do
136   plugin "wp-sticky"
137   site "2009.stateofthemap.org"
138 end
139
140 directory "/srv/2010.stateofthemap.org" do
141   owner "wordpress"
142   group "wordpress"
143   mode "755"
144 end
145
146 git "/srv/2010.stateofthemap.org" do
147   action :sync
148   repository "https://git.openstreetmap.org/public/stateofthemap.git"
149   revision "resources-2010"
150   depth 1
151   user "wordpress"
152   group "wordpress"
153 end
154
155 wordpress_site "2010.stateofthemap.org" do
156   aliases "2010.stateofthemap.com"
157   directory "/srv/2010.stateofthemap.org/wp"
158   database_name "sotm2010"
159   database_user "sotm2010"
160   database_password passwords["sotm2010"]
161   urls "/register" => "/srv/2010.stateofthemap.org/register"
162   fpm_prometheus_port 12010
163 end
164
165 wordpress_theme "2010.stateofthemap.org-aerodrome" do
166   theme "aerodrome"
167   site "2010.stateofthemap.org"
168   repository "https://git.openstreetmap.org/public/stateofthemap.git"
169   revision "theme-2010"
170 end
171
172 wordpress_plugin "2010.stateofthemap.org-sitepress-multilingual-cms" do
173   plugin "sitepress-multilingual-cms"
174   site "2010.stateofthemap.org"
175   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
176   not_if { ENV["TEST_KITCHEN"] }
177 end
178
179 wordpress_plugin "2010.stateofthemap.org-wp-sticky" do
180   plugin "wp-sticky"
181   site "2010.stateofthemap.org"
182 end
183
184 directory "/srv/2011.stateofthemap.org" do
185   owner "wordpress"
186   group "wordpress"
187   mode "755"
188 end
189
190 git "/srv/2011.stateofthemap.org" do
191   action :sync
192   repository "https://git.openstreetmap.org/public/stateofthemap.git"
193   revision "resources-2011"
194   depth 1
195   user "wordpress"
196   group "wordpress"
197 end
198
199 wordpress_site "2011.stateofthemap.org" do
200   aliases "2011.stateofthemap.com"
201   directory "/srv/2011.stateofthemap.org/wp"
202   database_name "sotm2011"
203   database_user "sotm2011"
204   database_password passwords["sotm2011"]
205   urls "/register" => "/srv/2011.stateofthemap.org/register"
206   fpm_prometheus_port 12011
207 end
208
209 wordpress_theme "2011.stateofthemap.org-aerodrome" do
210   theme "aerodrome"
211   site "2011.stateofthemap.org"
212   repository "https://git.openstreetmap.org/public/stateofthemap.git"
213   revision "theme-2011"
214 end
215
216 wordpress_plugin "2011.stateofthemap.org-sitepress-multilingual-cms" do
217   plugin "sitepress-multilingual-cms"
218   site "2011.stateofthemap.org"
219   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
220   not_if { ENV["TEST_KITCHEN"] }
221 end
222
223 wordpress_plugin "2011.stateofthemap.org-wp-sticky" do
224   plugin "wp-sticky"
225   site "2011.stateofthemap.org"
226 end
227
228 directory "/srv/2012.stateofthemap.org" do
229   owner "wordpress"
230   group "wordpress"
231   mode "755"
232 end
233
234 git "/srv/2012.stateofthemap.org" do
235   action :sync
236   repository "https://git.openstreetmap.org/public/stateofthemap.git"
237   revision "resources-2012"
238   depth 1
239   user "wordpress"
240   group "wordpress"
241 end
242
243 wordpress_site "2012.stateofthemap.org" do
244   aliases "2012.stateofthemap.com"
245   directory "/srv/2012.stateofthemap.org/wp"
246   database_name "sotm2012"
247   database_user "sotm2012"
248   database_password passwords["sotm2012"]
249   urls "/register" => "/srv/2012.stateofthemap.org/register"
250   fpm_prometheus_port 12012
251 end
252
253 wordpress_theme "2012.stateofthemap.org-aerodrome" do
254   theme "aerodrome"
255   site "2012.stateofthemap.org"
256   repository "https://git.openstreetmap.org/public/stateofthemap.git"
257   revision "theme-2012"
258 end
259
260 wordpress_plugin "2012.stateofthemap.org-leaflet-maps-marker" do
261   plugin "leaflet-maps-marker"
262   site "2012.stateofthemap.org"
263 end
264
265 wordpress_plugin "2012.stateofthemap.org-sitepress-multilingual-cms" do
266   plugin "sitepress-multilingual-cms"
267   site "2012.stateofthemap.org"
268   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
269   not_if { ENV["TEST_KITCHEN"] }
270 end
271
272 wordpress_plugin "2012.stateofthemap.org-wp-sticky" do
273   plugin "wp-sticky"
274   site "2012.stateofthemap.org"
275 end
276
277 %w[2013].each do |year|
278   git "/srv/#{year}.stateofthemap.org" do
279     action :sync
280     repository "https://git.openstreetmap.org/public/stateofthemap.git"
281     revision "site-#{year}"
282     depth 1
283     user "root"
284     group "root"
285   end
286
287   ssl_certificate "#{year}.stateofthemap.org" do
288     domains ["#{year}.stateofthemap.org", "#{year}.stateofthemap.com", "#{year}.sotm.org"]
289     notifies :reload, "service[apache2]"
290   end
291
292   apache_site "#{year}.stateofthemap.org" do
293     template "apache.static.erb"
294     directory "/srv/#{year}.stateofthemap.org"
295     variables :year => year
296   end
297 end
298
299 package %w[
300   gcc
301   g++
302   make
303   ruby
304   ruby-dev
305   libssl-dev
306   zlib1g-dev
307   pkg-config
308 ]
309
310 apache_module "expires"
311 apache_module "rewrite"
312
313 gem_package "bundler" do
314   version "1.17.3"
315 end
316
317 gem_package "bundler" do
318   version "2.1.4"
319 end
320
321 %w[2016 2017 2018 2019 2020 2021].each do |year|
322   git "/srv/#{year}.stateofthemap.org" do
323     action :sync
324     repository "https://github.com/openstreetmap/stateofthemap-#{year}.git"
325     depth 1
326     user "root"
327     group "root"
328     notifies :run, "execute[/srv/#{year}.stateofthemap.org/Gemfile]"
329   end
330
331   directory "/srv/#{year}.stateofthemap.org/_site" do
332     mode "755"
333     owner "nobody"
334     group "nogroup"
335   end
336
337   # Workaround https://github.com/jekyll/jekyll/issues/7804
338   # by creating a .jekyll-cache folder
339   directory "/srv/#{year}.stateofthemap.org/.jekyll-cache" do
340     mode "755"
341     owner "nobody"
342     group "nogroup"
343   end
344
345   execute "/srv/#{year}.stateofthemap.org/Gemfile" do
346     action :nothing
347     command "bundle install --deployment --jobs #{node[:cpu][:total]}"
348     cwd "/srv/#{year}.stateofthemap.org"
349     user "root"
350     group "root"
351     notifies :run, "execute[/srv/#{year}.stateofthemap.org]"
352     only_if { ::File.exist?("/srv/#{year}.stateofthemap.org/Gemfile") }
353   end
354
355   execute "/srv/#{year}.stateofthemap.org" do
356     action :nothing
357     command "bundle exec jekyll build --trace --baseurl=https://#{year}.stateofthemap.org"
358     cwd "/srv/#{year}.stateofthemap.org"
359     user "nobody"
360     group "nogroup"
361   end
362
363   ssl_certificate "#{year}.stateofthemap.org" do
364     domains ["#{year}.stateofthemap.org", "#{year}.stateofthemap.com", "#{year}.sotm.org"]
365     notifies :reload, "service[apache2]"
366   end
367
368   apache_site "#{year}.stateofthemap.org" do
369     template "apache.jekyll.erb"
370     directory "/srv/#{year}.stateofthemap.org/_site"
371     variables :year => year
372   end
373 end
374
375 template "/etc/cron.daily/sotm-backup" do
376   source "backup.cron.erb"
377   owner "root"
378   group "root"
379   mode "750"
380   variables :passwords => passwords
381 end