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