]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/recipes/default.rb
Disable unreliable DNSSEC in test-kitchen
[chef.git] / cookbooks / taginfo / recipes / default.rb
1 #
2 # Cookbook:: taginfo
3 # Recipe:: default
4 #
5 # Copyright:: 2014, 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 require "json"
21
22 include_recipe "accounts"
23 include_recipe "apache"
24 include_recipe "git"
25 include_recipe "passenger"
26 include_recipe "planet::current"
27 include_recipe "prometheus"
28 include_recipe "ruby"
29
30 package %w[
31   libsqlite3-dev
32   zlib1g-dev
33   libbz2-dev
34   libboost-dev
35   libexpat1-dev
36   libsparsehash-dev
37   libgd-dev
38   libicu-dev
39   libboost-program-options-dev
40   libosmium2-dev
41   libprotozero-dev
42   cmake
43   make
44   g++
45 ]
46
47 package %w[
48   sqlite3
49   sqlite3-pcre
50   osmium-tool
51   pyosmium
52   curl
53   pbzip2
54 ]
55
56 apache_module "cache"
57 apache_module "cache_disk"
58 apache_module "headers"
59
60 directory "/var/log/taginfo" do
61   owner "taginfo"
62   group "taginfo"
63   mode "755"
64 end
65
66 template "/etc/sudoers.d/taginfo" do
67   source "sudoers.erb"
68   owner "root"
69   group "root"
70   mode "440"
71 end
72
73 systemd_service "taginfo-update@" do
74   description "Taginfo update for %i"
75   wants "planet-update.service"
76   after "planet-update.service"
77   exec_start "/srv/%i/bin/update"
78   user "taginfo"
79   sandbox :enable_network => true
80   restrict_address_families "AF_UNIX"
81   read_write_paths [
82     "/srv/%i/data",
83     "/srv/%i/download",
84     "/srv/%i/sources",
85     "/var/log/taginfo/%i"
86   ]
87 end
88
89 systemd_timer "taginfo-update@" do
90   description "Taginfo update for %i"
91   on_calendar "01:37"
92 end
93
94 node[:taginfo][:sites].each do |site|
95   site_name = site[:name]
96   site_aliases = Array(site[:aliases])
97   directory = site[:directory] || "/srv/#{site_name}"
98   description = site[:description]
99   about = site[:about]
100   icon = site[:icon]
101   contact = site[:contact]
102
103   directory "/var/log/taginfo/#{site_name}" do
104     owner "taginfo"
105     group "taginfo"
106     mode "755"
107   end
108
109   directory directory do
110     owner "taginfo"
111     group "taginfo"
112     mode "755"
113   end
114
115   git "#{directory}/taginfo-tools" do
116     action :sync
117     repository "https://github.com/taginfo/taginfo-tools.git"
118     revision "osmorg-taginfo-live"
119     depth 1
120     enable_submodules true
121     user "taginfo"
122     group "taginfo"
123   end
124
125   directory "#{directory}/build" do
126     owner "taginfo"
127     group "taginfo"
128     mode "755"
129   end
130
131   execute "compile_taginfo_tools" do
132     action :nothing
133     user "taginfo"
134     group "taginfo"
135     cwd "#{directory}/build"
136     command "cmake #{directory}/taginfo-tools -DCMAKE_BUILD_TYPE=Release && make"
137     subscribes :run, "apt_package[libprotozero-dev]"
138     subscribes :run, "apt_package[libosmium2-dev]"
139     subscribes :run, "git[#{directory}/taginfo-tools]"
140   end
141
142   git "#{directory}/taginfo" do
143     action :sync
144     repository "https://github.com/taginfo/taginfo.git"
145     revision "osmorg-taginfo-live"
146     depth 1
147     user "taginfo"
148     group "taginfo"
149   end
150
151   settings = Chef::DelayedEvaluator.new do
152     settings = JSON.parse(IO.read("#{directory}/taginfo/taginfo-config-example.json"))
153
154     settings["instance"]["url"] = "https://#{site_name}/"
155     settings["instance"]["description"] = description
156     settings["instance"]["about"] = about
157     settings["instance"]["icon"] = "/img/logo/#{icon}.png"
158     settings["instance"]["contact"] = contact
159     settings["instance"]["access_control_allow_origin"] = ""
160     settings["logging"]["directory"] = "/var/log/taginfo/#{site_name}"
161     settings["opensearch"]["shortname"] = "Taginfo"
162     settings["opensearch"]["contact"] = "webmaster@openstreetmap.org"
163     settings["paths"]["bin_dir"] = "#{directory}/build/src"
164     settings["sources"]["download"] = ""
165     settings["sources"]["create"] = "db languages projects wiki wikidata chronology"
166     settings["sources"]["db"]["planetfile"] = "/var/lib/planet/planet.osh.pbf"
167     settings["sources"]["chronology"]["osm_history_file"] = "/var/lib/planet/planet.osh.pbf"
168     settings["tagstats"]["geodistribution"] = "DenseMmapArray"
169
170     JSON.pretty_generate(settings)
171   end
172
173   file "#{directory}/taginfo-config.json" do
174     owner "taginfo"
175     group "taginfo"
176     mode "644"
177     content settings
178     notifies :restart, "service[apache2]"
179   end
180
181   bundle_install "#{directory}/taginfo" do
182     action :nothing
183     user "root"
184     group "root"
185     subscribes :run, "git[#{directory}/taginfo]"
186     notifies :restart, "passenger_application[#{directory}/taginfo/web/public]"
187   end
188
189   %w[taginfo/web/tmp bin data data/old download sources].each do |dir|
190     directory "#{directory}/#{dir}" do
191       owner "taginfo"
192       group "taginfo"
193       mode "755"
194     end
195   end
196
197   template "#{directory}/bin/update" do
198     source "update.erb"
199     owner "taginfo"
200     group "taginfo"
201     mode "755"
202     variables :name => site_name, :directory => directory
203   end
204
205   passenger_application "#{directory}/taginfo/web/public" do
206     action :nothing
207   end
208
209   ssl_certificate site_name do
210     domains [site_name] + site_aliases
211     notifies :reload, "service[apache2]"
212   end
213
214   apache_site site_name do
215     template "apache.erb"
216     directory "#{directory}/taginfo/web/public"
217     variables :aliases => site_aliases
218   end
219
220   service "taginfo-update@#{site_name}.timer" do
221     action [:enable, :start]
222   end
223
224   prometheus_collector "taginfo-#{site_name}" do
225     interval "15m"
226     user "taginfo"
227     path "#{directory}/taginfo/sources/metrics.rb"
228     options "#{directory}/data"
229   end
230 end