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