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