]> git.openstreetmap.org Git - chef.git/blob - cookbooks/serverinfo/recipes/default.rb
9a9e1b5a7c2d0d405675b0996e9b9c70bcc395af
[chef.git] / cookbooks / serverinfo / recipes / default.rb
1 #
2 # Cookbook:: serverinfo
3 # Recipe:: default
4 #
5 # Copyright:: 2015, 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 "apache"
21 include_recipe "git"
22
23 package %w[
24   gcc
25   g++
26   make
27   ruby
28   ruby-dev
29   libssl-dev
30   zlib1g-dev
31   pkg-config
32 ]
33
34 gem_package "bundler" do
35   version "1.17.3"
36 end
37
38 git "/srv/hardware.openstreetmap.org" do
39   action :sync
40   repository "https://github.com/gravitystorm/osmf-server-info.git"
41   depth 1
42   user "root"
43   group "root"
44   notifies :run, "execute[/srv/hardware.openstreetmap.org/Gemfile]"
45 end
46
47 nodes = { :rows => search(:node, "*:*") }
48 roles = { :rows => search(:role, "*:*") }
49
50 file "/srv/hardware.openstreetmap.org/_data/nodes.json" do
51   content nodes.to_json
52   mode 0o644
53   owner "root"
54   group "root"
55   notifies :run, "execute[/srv/hardware.openstreetmap.org]"
56 end
57
58 file "/srv/hardware.openstreetmap.org/_data/roles.json" do
59   content roles.to_json
60   mode 0o644
61   owner "root"
62   group "root"
63   notifies :run, "execute[/srv/hardware.openstreetmap.org]"
64 end
65
66 directory "/srv/hardware.openstreetmap.org/_site" do
67   mode 0o755
68   owner "nobody"
69   group "nogroup"
70 end
71
72 # Workaround https://github.com/jekyll/jekyll/issues/7804
73 # by creating a .jekyll-cache folder
74 directory "/srv/hardware.openstreetmap.org/.jekyll-cache" do
75   mode 0o755
76   owner "nobody"
77   group "nogroup"
78 end
79
80 execute "/srv/hardware.openstreetmap.org/Gemfile" do
81   action :nothing
82   command "bundle install --deployment"
83   cwd "/srv/hardware.openstreetmap.org"
84   user "root"
85   group "root"
86   notifies :run, "execute[/srv/hardware.openstreetmap.org]"
87 end
88
89 execute "/srv/hardware.openstreetmap.org" do
90   action :nothing
91   command "bundle exec jekyll build --trace --baseurl=https://hardware.openstreetmap.org"
92   cwd "/srv/hardware.openstreetmap.org"
93   user "nobody"
94   group "nogroup"
95 end
96
97 ssl_certificate "hardware.openstreetmap.org" do
98   domains ["hardware.openstreetmap.org", "hardware.osm.org"]
99   notifies :reload, "service[apache2]"
100 end
101
102 apache_site "hardware.openstreetmap.org" do
103   template "apache.erb"
104   directory "/srv/hardware.openstreetmap.org/_site"
105   variables :aliases => ["hardware.osm.org"]
106 end