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