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