]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/recipes/default.rb
227da7d7edc79ad2fdc88ed23ffc0e0685d75285
[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 #     http://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::ssl"
23 include_recipe "passenger"
24 include_recipe "git"
25
26 package "libsqlite3-dev"
27 package "zlib1g-dev"
28 package "libosmpbf-dev"
29 package "libprotobuf-dev"
30 package "libboost-dev"
31 package "libexpat1-dev"
32 package "libsparsehash-dev"
33 package "libgd2-xpm-dev"
34 package "make"
35 package "g++"
36
37 package "sqlite3"
38
39 package "ruby"
40 package "rubygems"
41 gem_package "json"
42 gem_package "sqlite3"
43 gem_package "sinatra"
44 gem_package "sinatra-r18n"
45 gem_package "rack-contrib"
46
47 node[:taginfo][:sites].each do |site|
48   name = site[:name]
49   directory = site[:directory] || "/srv/#{name}"
50   description = site[:description]
51   icon = site[:icon]
52   contact = site[:contact]
53
54   directory directory do
55     owner "taginfo"
56     group "taginfo"
57     mode 0755
58   end
59
60   git "#{directory}/osmium" do
61     action :sync
62     repository "git://github.com/joto/osmium.git"
63     revision "master"
64     user "taginfo"
65     group "taginfo"
66   end
67
68   git "#{directory}/taginfo" do
69     action :sync
70     repository "git://github.com/joto/taginfo.git"
71     revision "master"
72     user "taginfo"
73     group "taginfo"
74   end
75
76   settings = JSON.parse(IO.read("#{directory}/taginfo/taginfo-config-example.json"))
77
78   settings["instance"]["url"] = "http://#{name}/"
79   settings["instance"]["description"] = description
80   settings["instance"]["icon"] = "/img/logo/#{icon}.png"
81   settings["instance"]["contact"] = contact
82   settings["opensearch"]["shortname"] = "Taginfo"
83   settings["opensearch"]["contact"] = "webmaster@openstreetmap.org"
84   settings["tagstats"]["cxxflags"] = "-I../../osmium/include"
85
86   file "#{directory}/taginfo-config.json" do
87     owner "taginfo"
88     group "taginfo"
89     mode 0644
90     content JSON.pretty_generate(settings)
91   end
92
93   execute "#{directory}/taginfo/tagstats/Makefile" do
94     action :nothing
95     command "make"
96     cwd "#{directory}/taginfo/tagstats"
97     user "taginfo"
98     group "taginfo"
99     subscribes :run, "git[#{directory}/osmium]"
100     subscribes :run, "git[#{directory}/taginfo]"
101     notifies :restart, "service[apache2]"
102   end
103
104   directory "#{directory}/data" do
105     owner "taginfo"
106     group "taginfo"
107     mode 0755
108   end
109
110   apache_site name do
111     template "apache.erb"
112     directory "#{directory}/taginfo/web/public"
113   end
114 end