5 # Copyright 2011, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
21 require "securerandom"
23 include_recipe "apache"
24 include_recipe "passenger"
26 include_recipe "mysql"
27 include_recipe "nodejs"
28 include_recipe "postgresql"
29 include_recipe "python"
64 python_package "geojson"
67 apache_module "expires"
68 apache_module "headers"
70 apache_module "proxy_fcgi"
71 apache_module "rewrite"
72 apache_module "suexec"
73 apache_module "userdir"
76 package "apache2-suexec-pristine"
80 gem_package "rails" do
84 service "php7.0-fpm" do
85 action [:enable, :start]
88 template "/etc/php/7.0/fpm/pool.d/default.conf" do
89 source "fpm-default.conf.erb"
93 notifies :reload, "service[php7.0-fpm]"
96 file "/etc/php/7.0/fpm/pool.d/www.conf" do
98 notifies :reload, "service[php7.0-fpm]"
101 directory "/srv/dev.openstreetmap.org" do
107 template "/srv/dev.openstreetmap.org/index.html" do
108 source "dev.html.erb"
114 ssl_certificate "dev.openstreetmap.org" do
115 domains "dev.openstreetmap.org"
116 notifies :reload, "service[apache2]"
119 apache_site "dev.openstreetmap.org" do
120 template "apache.dev.erb"
125 template "/etc/phppgadmin/config.inc.php" do
126 source "phppgadmin.conf.erb"
132 file "/etc/apache2/conf.d/phppgadmin" do
136 ssl_certificate "phppgadmin.dev.openstreetmap.org" do
137 domains "phppgadmin.dev.openstreetmap.org"
138 notifies :reload, "service[apache2]"
141 apache_site "phppgadmin.dev.openstreetmap.org" do
142 template "apache.phppgadmin.erb"
145 search(:accounts, "*:*").each do |account|
147 details = node[:accounts][:users][name] || {}
149 next unless %w[user administrator].include?(details[:status])
151 user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
153 next unless File.directory?("#{user_home}/public_html")
155 port = 7000 + account["uid"].to_i
157 template "/etc/php/7.0/fpm/pool.d/#{name}.conf" do
158 source "fpm.conf.erb"
162 variables :user => name, :port => port
163 notifies :reload, "service[php7.0-fpm]"
166 ssl_certificate "#{name}.dev.openstreetmap.org" do
167 domains ["#{name}.dev.openstreetmap.org", "#{name}.dev.osm.org"]
168 notifies :reload, "service[apache2]"
171 apache_site "#{name}.dev.openstreetmap.org" do
172 template "apache.user.erb"
173 directory "#{user_home}/public_html"
174 variables :user => name, :port => port
177 template "/etc/sudoers.d/#{name}" do
178 source "sudoers.user.erb"
182 variables :user => name
186 if node[:postgresql][:clusters][:"9.5/main"]
187 postgresql_user "apis" do
191 template "/usr/local/bin/cleanup-rails-assets" do
193 source "cleanup-assets.erb"
199 node[:dev][:rails].each do |name, details|
200 database_name = details[:database] || "apis_#{name}"
201 site_name = "#{name}.apis.dev.openstreetmap.org"
202 rails_directory = "/srv/#{name}.apis.dev.openstreetmap.org"
204 if details[:repository]
205 site_aliases = details[:aliases] || []
206 secret_key_base = details[:secret_key_base] || SecureRandom.base64(96)
208 node.normal[:dev][:rails][name][:secret_key_base] = secret_key_base
210 postgresql_database database_name do
215 postgresql_extension "#{database_name}_btree_gist" do
217 database database_name
218 extension "btree_gist"
221 rails_port site_name do
222 ruby node[:passenger][:ruby_version]
223 directory rails_directory
226 repository details[:repository]
227 revision details[:revision]
228 database_port node[:postgresql][:clusters][:"9.5/main"][:port]
229 database_name database_name
230 database_username "apis"
234 template "#{rails_directory}/config/initializers/setup.rb" do
235 source "rails.setup.rb.erb"
239 variables :site => site_name
240 notifies :restart, "rails_port[#{site_name}]"
243 ssl_certificate site_name do
244 domains [site_name] + site_aliases
245 notifies :reload, "service[apache2]"
248 apache_site site_name do
249 template "apache.rails.erb"
250 variables :name => site_name, :aliases => site_aliases, :secret_key_base => secret_key_base
253 apache_site site_name do
257 directory rails_directory do
262 file "/etc/cron.daily/rails-#{site_name.tr('.', '-')}" do
266 postgresql_database database_name do
271 node.normal[:dev][:rails].delete(name)
275 directory "/srv/apis.dev.openstreetmap.org" do
281 template "/srv/apis.dev.openstreetmap.org/index.html" do
282 source "apis.html.erb"
288 ssl_certificate "apis.dev.openstreetmap.org" do
289 domains "apis.dev.openstreetmap.org"
290 notifies :reload, "service[apache2]"
293 apache_site "apis.dev.openstreetmap.org" do
294 template "apache.apis.erb"
297 node[:postgresql][:clusters].each_key do |name|
298 postgresql_munin name do
305 directory "/srv/ooc.openstreetmap.org" do
311 remote_directory "/srv/ooc.openstreetmap.org/html" do
321 ssl_certificate "ooc.openstreetmap.org" do
322 domains ["ooc.openstreetmap.org",
323 "a.ooc.openstreetmap.org",
324 "b.ooc.openstreetmap.org",
325 "c.ooc.openstreetmap.org"]
326 notifies :reload, "service[apache2]"
329 apache_site "ooc.openstreetmap.org" do
330 template "apache.ooc.erb"