]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/recipes/default.rb
Merge remote-tracking branch 'github/pull/587'
[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   restrict_address_families "AF_UNIX"
80   read_write_paths [
81     "/srv/%i/data",
82     "/srv/%i/download",
83     "/srv/%i/sources",
84     "/var/log/taginfo/%i"
85   ]
86 end
87
88 systemd_timer "taginfo-update@" do
89   description "Taginfo update for %i"
90   on_calendar "01:37"
91 end
92
93 node[:taginfo][:sites].each do |site|
94   site_name = site[:name]
95   site_aliases = Array(site[:aliases])
96   directory = site[:directory] || "/srv/#{site_name}"
97   description = site[:description]
98   about = site[:about]
99   icon = site[:icon]
100   contact = site[:contact]
101
102   directory "/var/log/taginfo/#{site_name}" do
103     owner "taginfo"
104     group "taginfo"
105     mode "755"
106   end
107
108   directory directory do
109     owner "taginfo"
110     group "taginfo"
111     mode "755"
112   end
113
114   git "#{directory}/taginfo-tools" do
115     action :sync
116     repository "https://github.com/taginfo/taginfo-tools.git"
117     revision "osmorg-taginfo-live"
118     depth 1
119     enable_submodules true
120     user "taginfo"
121     group "taginfo"
122   end
123
124   directory "#{directory}/build" do
125     owner "taginfo"
126     group "taginfo"
127     mode "755"
128   end
129
130   execute "compile_taginfo_tools" do
131     action :nothing
132     user "taginfo"
133     group "taginfo"
134     cwd "#{directory}/build"
135     command "cmake #{directory}/taginfo-tools -DCMAKE_BUILD_TYPE=Release && make"
136     subscribes :run, "apt_package[libprotozero-dev]"
137     subscribes :run, "apt_package[libosmium2-dev]"
138     subscribes :run, "git[#{directory}/taginfo-tools]"
139   end
140
141   git "#{directory}/taginfo" do
142     action :sync
143     repository "https://github.com/taginfo/taginfo.git"
144     revision "osmorg-taginfo-live"
145     depth 1
146     user "taginfo"
147     group "taginfo"
148   end
149
150   settings = Chef::DelayedEvaluator.new do
151     settings = JSON.parse(IO.read("#{directory}/taginfo/taginfo-config-example.json"))
152
153     settings["instance"]["url"] = "https://#{site_name}/"
154     settings["instance"]["description"] = description
155     settings["instance"]["about"] = about
156     settings["instance"]["icon"] = "/img/logo/#{icon}.png"
157     settings["instance"]["contact"] = contact
158     settings["instance"]["access_control_allow_origin"] = ""
159     settings["logging"]["directory"] = "/var/log/taginfo/#{site_name}"
160     settings["opensearch"]["shortname"] = "Taginfo"
161     settings["opensearch"]["contact"] = "webmaster@openstreetmap.org"
162     settings["paths"]["bin_dir"] = "#{directory}/build/src"
163     settings["sources"]["download"] = ""
164     settings["sources"]["create"] = "db languages projects wiki wikidata chronology"
165     settings["sources"]["db"]["planetfile"] = "/var/lib/planet/planet.osh.pbf"
166     settings["sources"]["chronology"]["osm_history_file"] = "/var/lib/planet/planet.osh.pbf"
167     settings["tagstats"]["geodistribution"] = "DenseMmapArray"
168
169     JSON.pretty_generate(settings)
170   end
171
172   file "#{directory}/taginfo-config.json" do
173     owner "taginfo"
174     group "taginfo"
175     mode "644"
176     content settings
177     notifies :restart, "service[apache2]"
178   end
179
180   bundle_install "#{directory}/taginfo" do
181     action :nothing
182     user "root"
183     group "root"
184     subscribes :run, "git[#{directory}/taginfo]"
185     notifies :restart, "passenger_application[#{directory}/taginfo/web/public]"
186   end
187
188   %w[taginfo/web/tmp bin data data/old download sources].each do |dir|
189     directory "#{directory}/#{dir}" do
190       owner "taginfo"
191       group "taginfo"
192       mode "755"
193     end
194   end
195
196   template "#{directory}/bin/update" do
197     source "update.erb"
198     owner "taginfo"
199     group "taginfo"
200     mode "755"
201     variables :name => site_name, :directory => directory
202   end
203
204   passenger_application "#{directory}/taginfo/web/public" do
205     action :nothing
206   end
207
208   ssl_certificate site_name do
209     domains [site_name] + site_aliases
210     notifies :reload, "service[apache2]"
211   end
212
213   apache_site site_name do
214     template "apache.erb"
215     directory "#{directory}/taginfo/web/public"
216     variables :aliases => site_aliases
217   end
218
219   service "taginfo-update@#{site_name}.timer" do
220     action [:enable, :start]
221   end
222 end