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