]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/rails.rb
foundation: increase php-fpm workers
[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 "nodejs"
25 include_recipe "passenger"
26 include_recipe "ruby"
27 include_recipe "tools"
28 include_recipe "web::base"
29
30 web_passwords = data_bag_item("web", "passwords")
31 db_passwords = data_bag_item("db", "passwords")
32 aws_credentials = data_bag_item("web", "aws")
33
34 ssl_certificate "www.openstreetmap.org" do
35   domains ["www.openstreetmap.org", "www.osm.org", "www.openstreetmap.com",
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", "openstreetmap.com"]
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 aws_access_key_id = aws_credentials["web_access_key_id"]
50 aws_secret_access_key = aws_credentials["web_secret_access_key"]
51
52 storage = {
53   "avatars" => {
54     "service" => "S3",
55     "access_key_id" => aws_access_key_id,
56     "secret_access_key" => aws_secret_access_key,
57     "region" => "eu-west-1",
58     "bucket" => "openstreetmap-user-avatars",
59     "public" => true,
60     "use_dualstack_endpoint" => true,
61     "upload" => {
62       "acl" => "public-read",
63       "cache_control" => "public, max-age=31536000, immutable"
64     }
65   },
66   "gps_traces" => {
67     "service" => "S3",
68     "access_key_id" => aws_access_key_id,
69     "secret_access_key" => aws_secret_access_key,
70     "region" => "eu-west-1",
71     "bucket" => "openstreetmap-gps-traces",
72     "use_dualstack_endpoint" => true,
73     "public" => true,
74     "upload" => {
75       "acl" => "public-read",
76       "cache_control" => "public, max-age=31536000, immutable"
77     }
78   },
79   "gps_images" => {
80     "service" => "S3",
81     "access_key_id" => aws_access_key_id,
82     "secret_access_key" => aws_secret_access_key,
83     "region" => "eu-west-1",
84     "bucket" => "openstreetmap-gps-images",
85     "use_dualstack_endpoint" => true,
86     "public" => true,
87     "upload" => {
88       "acl" => "public-read",
89       "cache_control" => "public, max-age=31536000, immutable"
90     }
91   }
92 }
93
94 db_host = if node[:web][:status] == "database_readonly"
95             node[:web][:readonly_database_host]
96           else
97             node[:web][:database_host]
98           end
99
100 rails_port "www.openstreetmap.org" do
101   directory rails_directory
102   user "rails"
103   group "rails"
104   repository "https://git.openstreetmap.org/public/rails.git"
105   revision "live"
106   database_host db_host
107   database_name "openstreetmap"
108   database_username "rails"
109   database_password db_passwords["rails"]
110   email_from "OpenStreetMap <web@noreply.openstreetmap.org>"
111   status node[:web][:status]
112   messages_domain "messages.openstreetmap.org"
113   log_path "#{node[:web][:log_directory]}/rails.log"
114   memcache_servers node[:web][:memcached_servers]
115   potlatch2_key web_passwords["potlatch2_key"]
116   id_key web_passwords["id_key"]
117   id_application web_passwords["id_application"]
118   oauth_key web_passwords["oauth_key"]
119   oauth_application web_passwords["oauth_application"]
120   matomo_configuration "location" => matomo[:location],
121                        "site" => matomo[:site],
122                        "visitor_cookie_timeout" => matomo[:visitor_cookie_timeout],
123                        "referral_cookie_timeout" => matomo[:referral_cookie_timeout],
124                        "session_cookie_timeout" => matomo[:session_cookie_timeout],
125                        "goals" => matomo[:goals].to_hash
126   google_auth_id "651529786092-6c5ahcu0tpp95emiec8uibg11asmk34t.apps.googleusercontent.com"
127   google_auth_secret web_passwords["google_auth_secret"]
128   google_openid_realm "https://www.openstreetmap.org"
129   apple_auth_id "org.openstreetmap.www"
130   apple_team_id "MF99FFFD4L"
131   apple_key_id "73A2H3M7J3"
132   apple_private_key web_passwords["apple_private_key"].join("\n")
133   facebook_auth_id "427915424036881"
134   facebook_auth_secret web_passwords["facebook_auth_secret"]
135   microsoft_auth_id "e34f14f1-f790-40f3-9fa4-3c5f1a027c38"
136   microsoft_auth_secret web_passwords["microsoft_auth_secret"]
137   github_auth_id "acf7da34edee99e35499"
138   github_auth_secret web_passwords["github_auth_secret"]
139   wikipedia_auth_id "e4fe0c2c5855d23ed7e1f1c0fa1f1c58"
140   wikipedia_auth_secret web_passwords["wikipedia_auth_secret"]
141   thunderforest_key web_passwords["thunderforest_key"]
142   tracestrack_key web_passwords["tracestrack_key"]
143   maptiler_key web_passwords["maptiler_key"]
144   totp_key web_passwords["totp_key"]
145   totp_domain "openstreetmap.org"
146   csp_enforce true
147   trace_use_job_queue true
148   diary_feed_delay 12
149   storage_configuration storage
150   avatar_storage "avatars"
151   trace_file_storage "gps_traces"
152   trace_image_storage "gps_images"
153   trace_icon_storage "gps_images"
154   avatar_storage_url "https://openstreetmap-user-avatars.s3.dualstack.eu-west-1.amazonaws.com"
155   trace_image_storage_url "https://openstreetmap-gps-images.s3.dualstack.eu-west-1.amazonaws.com"
156   overpass_url "https://query.openstreetmap.org/query-features"
157   overpass_credentials true
158   signup_ip_per_day 24
159   signup_ip_max_burst 48
160   signup_email_per_day 1
161   signup_email_max_burst 2
162   doorkeeper_signing_key web_passwords["openid_connect_key"].join("\n")
163   user_account_deletion_delay 7 * 24
164   turnstile_site_key "0x4AAAAAACsSjCdlK-9Cu3FO"
165   turnstile_secret_key web_passwords["cloudflare_turnstile_secret"]
166   # Requests to modify the imagery blacklist should come from the DWG only
167   imagery_blacklist [
168     # Current Google imagery URLs have google or googleapis in the domain
169     ".*\\.google(apis)?\\..*/.*",
170     # Blacklist VWorld
171     "https?://xdworld\\.vworld\\.kr[/:].*",
172     # Blacklist here
173     ".*\\.here\\.com[/:].*",
174     # Blacklist Mapy.cz
175     ".*\\.mapy\\.cz.*",
176     # Blacklist Yandex
177     ".*\\.api-maps\\.yandex\\.ru/.*",
178     ".*\\.maps\\.yandex\\.net/.*",
179     # Blacklist 2gis
180     ".*\\.maps\\.2gis\\.com/.*"
181   ]
182 end
183
184 systemd_service "rails-jobs@" do
185   description "Rails job queue runner"
186   type "simple"
187   environment "RAILS_ENV" => "production",
188               "QUEUE" => "%I",
189               "SLEEP_DELAY" => "60",
190               "SECRET_KEY_BASE" => web_passwords["secret_key_base"]
191   user "rails"
192   working_directory rails_directory
193   exec_start "#{node[:ruby][:bundle]} exec rails jobs:work"
194   restart "on-failure"
195   memory_high "2G"
196   memory_max "3G"
197   nice 10
198   sandbox :enable_network => true
199   memory_deny_write_execute false
200   read_write_paths "/var/log/web"
201 end
202
203 package "libjson-xs-perl"
204
205 template "/usr/local/bin/cleanup-rails-assets" do
206   source "cleanup-assets.erb"
207   owner "root"
208   group "root"
209   mode "755"
210 end
211
212 gem_package "apachelogregex" do
213   gem_binary node[:ruby][:gem]
214 end
215
216 gem_package "file-tail" do
217   gem_binary node[:ruby][:gem]
218 end
219
220 template "/usr/local/bin/api-statistics" do
221   source "api-statistics.erb"
222   owner "root"
223   group "root"
224   mode "755"
225 end
226
227 systemd_service "api-statistics" do
228   description "OpenStreetMap API Statistics Daemon"
229   user "rails"
230   group "adm"
231   exec_start "/usr/local/bin/api-statistics"
232   nice 10
233   sandbox true
234   read_write_paths [
235     "/srv/www.openstreetmap.org/rails/tmp",
236     "/var/lib/prometheus/node-exporter"
237   ]
238   restart "on-failure"
239 end
240
241 service "api-statistics" do
242   action [:enable, :start]
243   supports :restart => true
244   subscribes :restart, "template[/usr/local/bin/api-statistics]"
245   subscribes :restart, "systemd_service[api-statistics]"
246 end
247
248 gem_package "hpricot" do
249   gem_binary node[:ruby][:gem]
250 end