]> git.openstreetmap.org Git - chef.git/blob - cookbooks/imagery/resources/site.rb
6478faa52b1549266ed642757cb94bca69ddc6ae
[chef.git] / cookbooks / imagery / resources / site.rb
1 #
2 # Cookbook Name:: imagery
3 # Resource:: imagery_site
4 #
5 # Copyright 2016, 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 "yaml"
21
22 default_action :create
23
24 property :name, String
25 property :aliases, [String, Array], :default => []
26 property :bbox, Array, :required => true
27
28 action :create do
29   directory "/srv/#{name}" do
30     user "root"
31     group "root"
32     mode 0755
33   end
34
35   directory "/srv/imagery/layers/#{name}" do
36     user "root"
37     group "root"
38     mode 0755
39     recursive true
40   end
41
42   directory "/srv/imagery/overlays/#{name}" do
43     user "root"
44     group "root"
45     mode 0755
46     recursive true
47   end
48
49   template "/srv/#{name}/index.html" do
50     source "index.html.erb"
51     user "root"
52     group "root"
53     mode 0644
54     variables :title => name
55   end
56
57   cookbook_file "/srv/#{name}/imagery.css" do
58     source "imagery.css"
59     user "root"
60     group "root"
61     mode 0644
62   end
63
64   layers = Dir.glob("/srv/imagery/layers/#{name}/*.yml").collect do |path|
65     YAML.load(::File.read(path))
66   end
67
68   overlays = Dir.glob("/srv/imagery/overlays/#{name}/*.yml").collect do |path|
69     YAML.load(::File.read(path))
70   end
71
72   template "/srv/#{name}/imagery.js" do
73     source "imagery.js.erb"
74     user "root"
75     group "root"
76     mode 0644
77     variables :bbox => bbox, :layers => layers, :overlays => overlays
78   end
79
80   nginx_site name do
81     template "nginx_imagery.conf.erb"
82     directory "/srv/imagery/#{name}"
83     restart_nginx false
84     variables new_resource.to_hash
85   end
86 end
87
88 def after_created
89   notifies :restart, "service[nginx]"
90 end