]> git.openstreetmap.org Git - chef.git/blob - cookbooks/stateofthemap/recipes/jekyll.rb
Split stateofthemap cookbook to allow parallel testing
[chef.git] / cookbooks / stateofthemap / recipes / jekyll.rb
1 #
2 # Cookbook:: stateofthemap
3 # Recipe:: jekyll
4 #
5 # Copyright:: 2022, 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
22 package %w[
23   gcc
24   g++
25   make
26   libssl-dev
27   zlib1g-dev
28   pkg-config
29 ]
30
31 apache_module "expires"
32 apache_module "rewrite"
33
34 %w[2016 2017 2018 2019 2020 2021 2022].each do |year|
35   git "/srv/#{year}.stateofthemap.org" do
36     action :sync
37     repository "https://github.com/openstreetmap/stateofthemap-#{year}.git"
38     depth 1
39     user "root"
40     group "root"
41     notifies :run, "bundle_install[/srv/#{year}.stateofthemap.org]"
42   end
43
44   directory "/srv/#{year}.stateofthemap.org/_site" do
45     mode "755"
46     owner "nobody"
47     group "nogroup"
48   end
49
50   # Workaround https://github.com/jekyll/jekyll/issues/7804
51   # by creating a .jekyll-cache folder
52   directory "/srv/#{year}.stateofthemap.org/.jekyll-cache" do
53     mode "755"
54     owner "nobody"
55     group "nogroup"
56   end
57
58   bundle_install "/srv/#{year}.stateofthemap.org" do
59     action :nothing
60     options "--deployment --jobs #{node[:cpu][:total]}"
61     user "root"
62     group "root"
63     notifies :run, "bundle_exec[/srv/#{year}.stateofthemap.org]"
64     only_if { ::File.exist?("/srv/#{year}.stateofthemap.org/Gemfile") }
65   end
66
67   bundle_exec "/srv/#{year}.stateofthemap.org" do
68     action :nothing
69     command "jekyll build --trace --baseurl=https://#{year}.stateofthemap.org"
70     user "nobody"
71     group "nogroup"
72     environment "LANG" => "C.UTF-8"
73   end
74
75   ssl_certificate "#{year}.stateofthemap.org" do
76     domains ["#{year}.stateofthemap.org", "#{year}.stateofthemap.com", "#{year}.sotm.org"]
77     notifies :reload, "service[apache2]"
78   end
79
80   apache_site "#{year}.stateofthemap.org" do
81     template "apache.jekyll.erb"
82     directory "/srv/#{year}.stateofthemap.org/_site"
83     variables :year => year
84   end
85 end