]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/rails.rb
892da9597f1836702aa9ad63141a525c1237c111
[chef.git] / cookbooks / web / recipes / rails.rb
1 #
2 # Cookbook:: web
3 # Recipe:: rails
4 #
5 # Copyright:: 2011, 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 include_recipe "apache"
21 include_recipe "apt"
22 include_recipe "git"
23 include_recipe "geoipupdate"
24 include_recipe "munin"
25 include_recipe "nodejs"
26 include_recipe "passenger"
27 include_recipe "ruby"
28 include_recipe "tools"
29 include_recipe "web::base"
30
31 web_passwords = data_bag_item("web", "passwords")
32 db_passwords = data_bag_item("db", "passwords")
33
34 ssl_certificate "www.openstreetmap.org" do
35   domains ["www.openstreetmap.org", "www.osm.org",
36            "api.openstreetmap.org", "api.osm.org",
37            "maps.openstreetmap.org", "maps.osm.org",
38            "mapz.openstreetmap.org", "mapz.osm.org",
39            "openstreetmap.org", "osm.org"]
40   notifies :reload, "service[apache2]"
41 end
42
43 nodejs_package "svgo"
44
45 rails_directory = "#{node[:web][:base_directory]}/rails"
46
47 matomo = data_bag_item("web", "matomo")
48
49 storage = {
50   "avatars" => {
51     "service" => "S3",
52     "access_key_id" => "AKIASQUXHPE7AMJQRFOS",
53     "secret_access_key" => web_passwords["aws_key"],
54     "region" => "eu-west-1",
55     "bucket" => "openstreetmap-user-avatars",
56     "use_dualstack_endpoint" => true,
57     "upload" => {
58       "acl" => "public-read",
59       "cache_control" => "public, max-age=31536000, immutable"
60     }
61   },
62   "gps_traces" => {
63     "service" => "S3",
64     "access_key_id" => "AKIASQUXHPE7AMJQRFOS",
65     "secret_access_key" => web_passwords["aws_key"],
66     "region" => "eu-west-1",
67     "bucket" => "openstreetmap-gps-traces",
68     "use_dualstack_endpoint" => true,
69     "upload" => {
70       "acl" => "public-read",
71       "cache_control" => "public, max-age=31536000, immutable"
72     }
73   },
74   "gps_images" => {
75     "service" => "S3",
76     "access_key_id" => "AKIASQUXHPE7AMJQRFOS",
77     "secret_access_key" => web_passwords["aws_key"],
78     "region" => "eu-west-1",
79     "bucket" => "openstreetmap-gps-images",
80     "use_dualstack_endpoint" => true,
81     "upload" => {
82       "acl" => "public-read",
83       "cache_control" => "public, max-age=31536000, immutable"
84     }
85   }
86 }
87
88 db_host = if node[:web][:status] == "database_readonly"
89             node[:web][:readonly_database_host]
90           else
91             node[:web][:database_host]
92           end
93
94 rails_port "www.openstreetmap.org" do
95   directory rails_directory
96   user "rails"
97   group "rails"
98   repository "https://git.openstreetmap.org/public/rails.git"
99   revision "live"
100   database_host db_host
101   database_name "openstreetmap"
102   database_username "rails"
103   database_password db_passwords["rails"]
104   email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
105   status node[:web][:status]
106   messages_domain "messages.openstreetmap.org"
107   log_path "#{node[:web][:log_directory]}/rails.log"
108   logstash_path "#{node[:web][:log_directory]}/rails-logstash.log"
109   memcache_servers node[:web][:memcached_servers]
110   potlatch2_key web_passwords["potlatch2_key"]
111   id_key web_passwords["id_key"]
112   id_application web_passwords["id_application"]
113   oauth_key web_passwords["oauth_key"]
114   oauth_application web_passwords["oauth_application"]
115   matomo_configuration "location" => matomo[:location],
116                        "site" => matomo[:site],
117                        "goals" => matomo[:goals].to_hash
118   google_auth_id "651529786092-6c5ahcu0tpp95emiec8uibg11asmk34t.apps.googleusercontent.com"
119   google_auth_secret web_passwords["google_auth_secret"]
120   google_openid_realm "https://www.openstreetmap.org"
121   facebook_auth_id "427915424036881"
122   facebook_auth_secret web_passwords["facebook_auth_secret"]
123   windowslive_auth_id "0000000040153C51"
124   windowslive_auth_secret web_passwords["windowslive_auth_secret"]
125   github_auth_id "acf7da34edee99e35499"
126   github_auth_secret web_passwords["github_auth_secret"]
127   wikipedia_auth_id "e4fe0c2c5855d23ed7e1f1c0fa1f1c58"
128   wikipedia_auth_secret web_passwords["wikipedia_auth_secret"]
129   thunderforest_key web_passwords["thunderforest_key"]
130   totp_key web_passwords["totp_key"]
131   csp_enforce true
132   trace_use_job_queue true
133   diary_feed_delay 12
134   storage_configuration storage
135   avatar_storage "avatars"
136   trace_file_storage "gps_traces"
137   trace_image_storage "gps_images"
138   trace_icon_storage "gps_images"
139   avatar_storage_url "https://openstreetmap-user-avatars.s3.dualstack.eu-west-1.amazonaws.com"
140   trace_image_storage_url "https://openstreetmap-gps-images.s3.dualstack.eu-west-1.amazonaws.com"
141   overpass_url "https://query.openstreetmap.org/query-features"
142   overpass_credentials true
143 end
144
145 systemd_service "rails-jobs@" do
146   description "Rails job queue runner"
147   type "simple"
148   environment "RAILS_ENV" => "production", "QUEUE" => "%I", "SLEEP_DELAY" => "60"
149   user "rails"
150   working_directory rails_directory
151   exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
152   restart "on-failure"
153   nice 10
154   sandbox :enable_network => true
155   memory_deny_write_execute false
156   read_write_paths "/var/log/web"
157 end
158
159 package "libjson-xs-perl"
160
161 template "/usr/local/bin/cleanup-rails-assets" do
162   source "cleanup-assets.erb"
163   owner "root"
164   group "root"
165   mode "755"
166 end
167
168 gem_package "apachelogregex" do
169   gem_binary node[:ruby][:gem]
170 end
171
172 gem_package "file-tail" do
173   gem_binary node[:ruby][:gem]
174 end
175
176 template "/usr/local/bin/api-statistics" do
177   source "api-statistics.erb"
178   owner "root"
179   group "root"
180   mode "755"
181 end
182
183 systemd_service "api-statistics" do
184   description "OpenStreetMap API Statistics Daemon"
185   user "rails"
186   group "adm"
187   exec_start "/usr/local/bin/api-statistics"
188   nice 10
189   sandbox true
190   read_write_paths [
191     "/srv/www.openstreetmap.org/rails/tmp",
192     "/var/lib/prometheus/node-exporter"
193   ]
194   restart "on-failure"
195 end
196
197 service "api-statistics" do
198   action [:enable, :start]
199   supports :restart => true
200   subscribes :restart, "template[/usr/local/bin/api-statistics]"
201   subscribes :restart, "systemd_service[api-statistics]"
202 end
203
204 gem_package "hpricot" do
205   gem_binary node[:ruby][:gem]
206 end
207
208 munin_plugin "api_calls_status"
209 munin_plugin "api_calls_num"
210
211 munin_plugin "api_calls_#{node[:hostname]}" do
212   target "api_calls_"
213 end
214
215 munin_plugin "api_waits_#{node[:hostname]}" do
216   target "api_waits_"
217 end