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