From: Tom Hughes Date: Tue, 28 Jun 2022 19:38:43 +0000 (+0100) Subject: Centralise ruby installation in a new cookbook X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/99e00a34031960fa05d332ce803fd095dc9dfcd9 Centralise ruby installation in a new cookbook --- diff --git a/cookbooks/blogs/metadata.rb b/cookbooks/blogs/metadata.rb index 19d88bcfe..e63df4125 100644 --- a/cookbooks/blogs/metadata.rb +++ b/cookbooks/blogs/metadata.rb @@ -9,3 +9,4 @@ supports "ubuntu" depends "accounts" depends "apache" depends "git" +depends "ruby" diff --git a/cookbooks/blogs/recipes/default.rb b/cookbooks/blogs/recipes/default.rb index 165befb5e..eb13152fa 100644 --- a/cookbooks/blogs/recipes/default.rb +++ b/cookbooks/blogs/recipes/default.rb @@ -20,29 +20,15 @@ include_recipe "accounts" include_recipe "apache" include_recipe "git" - -ruby_version = if node[:lsb][:release].to_f < 20.04 - "2.5" - else - "2.7" - end +include_recipe "ruby" package %W[ - ruby#{ruby_version} - ruby#{ruby_version}-dev make gcc g++ libsqlite3-dev ] -gem_package "bundler#{ruby_version}" do - package_name "bundler" - version "~> 2.1.4" - gem_binary "gem#{ruby_version}" - options "--format-executable" -end - directory "/srv/blogs.openstreetmap.org" do owner "blogs" group "blogs" @@ -55,22 +41,20 @@ git "/srv/blogs.openstreetmap.org" do depth 1 user "blogs" group "blogs" - notifies :run, "execute[/srv/blogs.openstreetmap.org/Gemfile]", :immediately + notifies :run, "bundle_install[/srv/blogs.openstreetmap.org]", :immediately end -execute "/srv/blogs.openstreetmap.org/Gemfile" do +bundle_install "/srv/blogs.openstreetmap.org" do action :nothing - command "bundle#{ruby_version} install --deployment" - cwd "/srv/blogs.openstreetmap.org" + options "--deployment" user "blogs" group "blogs" - notifies :run, "execute[/srv/blogs.openstreetmap.org]", :immediately + notifies :run, "bundle_exec[/srv/blogs.openstreetmap.org]", :immediately end -execute "/srv/blogs.openstreetmap.org" do +bundle_exec "/srv/blogs.openstreetmap.org" do action :nothing - command "bundle#{ruby_version} exec pluto build -t osm -o build" - cwd "/srv/blogs.openstreetmap.org" + command "pluto build -t osm -o build" user "blogs" group "blogs" end @@ -91,7 +75,6 @@ template "/usr/local/bin/blogs-update" do owner "root" group "root" mode "0755" - variables :ruby_version => ruby_version end cron_d "blogs" do diff --git a/cookbooks/blogs/templates/default/blogs-update.erb b/cookbooks/blogs/templates/default/blogs-update.erb index 0125b41ba..15cc82483 100644 --- a/cookbooks/blogs/templates/default/blogs-update.erb +++ b/cookbooks/blogs/templates/default/blogs-update.erb @@ -2,7 +2,7 @@ cd /srv/blogs.openstreetmap.org -/usr/bin/bundle<%= @ruby_version %> exec pluto \ +<%= node[:ruby][:bundle] %> exec pluto \ --quieter \ --config=/srv/blogs.openstreetmap.org build \ --dbpath=/srv/blogs.openstreetmap.org \ diff --git a/cookbooks/db/metadata.rb b/cookbooks/db/metadata.rb index aadfe47db..d52927a75 100644 --- a/cookbooks/db/metadata.rb +++ b/cookbooks/db/metadata.rb @@ -10,4 +10,5 @@ depends "accounts" depends "git" depends "postgresql" depends "python" +depends "ruby" depends "web" diff --git a/cookbooks/db/recipes/base.rb b/cookbooks/db/recipes/base.rb index 51bfca632..520fbe2e8 100644 --- a/cookbooks/db/recipes/base.rb +++ b/cookbooks/db/recipes/base.rb @@ -21,12 +21,11 @@ include_recipe "accounts" include_recipe "git" include_recipe "postgresql" include_recipe "python" +include_recipe "ruby" passwords = data_bag_item("db", "passwords") wal_secrets = data_bag_item("db", "wal-secrets") -ruby_version = node[:passenger][:ruby_version] - postgresql_munin "openstreetmap" do cluster node[:db][:cluster] database "openstreetmap" @@ -38,7 +37,6 @@ directory "/srv/www.openstreetmap.org" do end rails_port "www.openstreetmap.org" do - ruby ruby_version directory "/srv/www.openstreetmap.org/rails" user "rails" group "rails" @@ -85,7 +83,7 @@ node[:postgresql][:versions].each do |db_version| execute function_directory do action :nothing - command "make BUNDLE=bundle#{ruby_version} PG_CONFIG=#{pg_config} DESTDIR=#{function_directory}" + command "make BUNDLE=#{node[:ruby][:bundle]} PG_CONFIG=#{pg_config} DESTDIR=#{function_directory}" cwd "/srv/www.openstreetmap.org/rails/db/functions" user "rails" group "rails" diff --git a/cookbooks/dev/metadata.rb b/cookbooks/dev/metadata.rb index 457e46dd0..29e665a43 100644 --- a/cookbooks/dev/metadata.rb +++ b/cookbooks/dev/metadata.rb @@ -18,5 +18,6 @@ depends "nodejs" depends "php" depends "postgresql" depends "python" +depends "ruby" depends "tools" depends "web" diff --git a/cookbooks/dev/recipes/default.rb b/cookbooks/dev/recipes/default.rb index 4b539e9c8..679ff6b4c 100644 --- a/cookbooks/dev/recipes/default.rb +++ b/cookbooks/dev/recipes/default.rb @@ -31,6 +31,7 @@ include_recipe "nodejs" include_recipe "php::fpm" include_recipe "postgresql" include_recipe "python" +include_recipe "ruby" package %w[ php-cgi @@ -215,14 +216,12 @@ if node[:postgresql][:clusters][:"14/main"] mode "755" end - ruby_version = node[:passenger][:ruby_version] - systemd_service "rails-jobs@" do description "Rails job queue runner" type "simple" user "apis" working_directory "/srv/%i.apis.dev.openstreetmap.org/rails" - exec_start "/usr/local/bin/bundle#{ruby_version} exec rake jobs:work" + exec_start "#{node[:ruby][:bundle]} exec rake jobs:work" restart "on-failure" private_tmp true private_devices true @@ -307,7 +306,6 @@ if node[:postgresql][:clusters][:"14/main"] end rails_port site_name do - ruby ruby_version directory rails_directory user "apis" group "apis" diff --git a/cookbooks/foundation/metadata.rb b/cookbooks/foundation/metadata.rb index 8aa888296..426a683c7 100644 --- a/cookbooks/foundation/metadata.rb +++ b/cookbooks/foundation/metadata.rb @@ -9,3 +9,4 @@ supports "ubuntu" depends "apache" depends "git" depends "mediawiki" +depends "ruby" diff --git a/cookbooks/foundation/recipes/owg.rb b/cookbooks/foundation/recipes/owg.rb index fb9aca201..6c637c62a 100644 --- a/cookbooks/foundation/recipes/owg.rb +++ b/cookbooks/foundation/recipes/owg.rb @@ -19,32 +19,24 @@ include_recipe "apache" include_recipe "git" +include_recipe "ruby" -package %w[ +package %W[ gcc g++ make - ruby2.7 - ruby2.7-dev libssl-dev zlib1g-dev pkg-config ] -gem_package "bundler" do - package_name "bundler" - version "~> 2.2.22" - gem_binary "gem2.7" - options "--format-executable" -end - git "/srv/operations.osmfoundation.org" do action :sync repository "https://github.com/openstreetmap/owg-website.git" depth 1 user "root" group "root" - notifies :run, "execute[/srv/operations.osmfoundation.org/Gemfile]" + notifies :run, "bundle_install[/srv/operations.osmfoundation.org]" end directory "/srv/operations.osmfoundation.org/_site" do @@ -61,18 +53,17 @@ directory "/srv/operations.osmfoundation.org/.jekyll-cache" do group "nogroup" end -execute "/srv/operations.osmfoundation.org/Gemfile" do +bundle_install "/srv/operations.osmfoundation.org" do action :nothing - command "bundle2.7 install --deployment" - cwd "/srv/operations.osmfoundation.org" + options "--deployment" user "root" group "root" - notifies :run, "execute[/srv/operations.osmfoundation.org]" + notifies :run, "bundle_exec[/srv/operations.osmfoundation.org]" end -execute "/srv/operations.osmfoundation.org" do - command "bundle2.7 exec jekyll build --trace" - cwd "/srv/operations.osmfoundation.org" +bundle_exec "/srv/operations.osmfoundation.org" do + action :nothing + command "jekyll build --trace" user "nobody" group "nogroup" end diff --git a/cookbooks/passenger/attributes/default.rb b/cookbooks/passenger/attributes/default.rb index 03c6b5a8d..2ac125c12 100644 --- a/cookbooks/passenger/attributes/default.rb +++ b/cookbooks/passenger/attributes/default.rb @@ -1,9 +1,3 @@ -default[:passenger][:ruby_version] = if node[:lsb][:release].to_f < 20.04 - "2.5" - else - "2.7" - end - default[:passenger][:max_pool_size] = 6 default[:passenger][:pool_idle_time] = 300 default[:passenger][:instance_registry_dir] = "/run/passenger" diff --git a/cookbooks/passenger/metadata.rb b/cookbooks/passenger/metadata.rb index 42fc95c2a..8cbf75fa6 100644 --- a/cookbooks/passenger/metadata.rb +++ b/cookbooks/passenger/metadata.rb @@ -10,4 +10,5 @@ depends "apache" depends "apt" depends "munin" depends "prometheus" +depends "ruby" depends "systemd" diff --git a/cookbooks/passenger/recipes/default.rb b/cookbooks/passenger/recipes/default.rb index 95abd7890..f8ea95808 100644 --- a/cookbooks/passenger/recipes/default.rb +++ b/cookbooks/passenger/recipes/default.rb @@ -21,14 +21,7 @@ include_recipe "apache" include_recipe "apt" include_recipe "munin" include_recipe "prometheus" - -package "ruby#{node[:passenger][:ruby_version]}" -package "ruby#{node[:passenger][:ruby_version]}-dev" - -if node[:passenger][:ruby_version].to_f < 1.9 - package "rubygems#{node[:passenger][:ruby_version]}" - package "irb#{node[:passenger][:ruby_version]}" -end +include_recipe "ruby" template "/usr/local/bin/passenger-ruby" do source "ruby.erb" diff --git a/cookbooks/passenger/templates/default/ruby.erb b/cookbooks/passenger/templates/default/ruby.erb index fb7575ab0..f45fd210e 100644 --- a/cookbooks/passenger/templates/default/ruby.erb +++ b/cookbooks/passenger/templates/default/ruby.erb @@ -1,12 +1,7 @@ #!/bin/sh -<% if node[:passenger][:ruby_version].to_f < 2.1 -%> -export RUBY_HEAP_MIN_SLOTS=500000 -export RUBY_HEAP_FREE_MIN=100000 -<% else -%> export RUBY_GC_HEAP_INIT_SLOTS=500000 export RUBY_GC_HEAP_FREE_SLOTS=100000 -<% end -%> export RUBY_GC_MALLOC_LIMIT=50000000 -exec /usr/bin/ruby<%= node[:passenger][:ruby_version] %> "$@" +exec /usr/bin/ruby<%= node[:ruby][:version] %> "$@" diff --git a/cookbooks/ruby/README.md b/cookbooks/ruby/README.md new file mode 100644 index 000000000..d7f1641ab --- /dev/null +++ b/cookbooks/ruby/README.md @@ -0,0 +1,3 @@ +# Ruby Cookbook + +Installs and configures ruby. diff --git a/cookbooks/ruby/attributes/default.rb b/cookbooks/ruby/attributes/default.rb new file mode 100644 index 000000000..39e975e06 --- /dev/null +++ b/cookbooks/ruby/attributes/default.rb @@ -0,0 +1,6 @@ +default[:ruby][:version] = if node[:lsb][:release].to_f < 20.04 + "2.5" + else + "2.7" + end +default[:ruby][:bundle] = "/usr/bin/bundle#{node[:ruby][:version]}" diff --git a/cookbooks/ruby/metadata.rb b/cookbooks/ruby/metadata.rb new file mode 100644 index 000000000..d8f2eac0e --- /dev/null +++ b/cookbooks/ruby/metadata.rb @@ -0,0 +1,8 @@ +name "ruby" +maintainer "OpenStreetMap Administrators" +maintainer_email "admins@openstreetmap.org" +license "Apache-2.0" +description "Installs and configures ruby" + +version "1.0.0" +supports "ubuntu" diff --git a/cookbooks/ruby/recipes/default.rb b/cookbooks/ruby/recipes/default.rb new file mode 100644 index 000000000..3ec7b0329 --- /dev/null +++ b/cookbooks/ruby/recipes/default.rb @@ -0,0 +1,41 @@ +# +# Cookbook:: ruby +# Recipe:: default +# +# Copyright:: 2022, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ruby_version = node[:ruby][:version] + +package %W[ + ruby + ruby#{ruby_version} + ruby + ruby#{ruby_version}-dev +] + +gem_package "bundler#{ruby_version}-1" do + package_name "bundler" + version "~> 1.17.3" + gem_binary "gem#{ruby_version}" + options "--format-executable" +end + +gem_package "bundler#{ruby_version}-2" do + package_name "bundler" + version "~> 2.3.16" + gem_binary "gem#{ruby_version}" + options "--format-executable" +end diff --git a/cookbooks/ruby/resources/bundle_exec.rb b/cookbooks/ruby/resources/bundle_exec.rb new file mode 100644 index 000000000..e4150f631 --- /dev/null +++ b/cookbooks/ruby/resources/bundle_exec.rb @@ -0,0 +1,47 @@ +# +# Cookbook:: ruby +# Resource:: bundle_exec +# +# Copyright:: 2022, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +resource_name :bundle_exec +provides :bundle_exec + +unified_mode true + +default_action :run + +property :directory, :kind_of => String, :name_property => true +property :command, :kind_of => String +property :user, :kind_of => String +property :group, :kind_of => String +property :environment, :kind_of => Hash + +action :run do + execute "#{new_resource.directory}/Gemfile" do + command "#{bundle_command} exec #{new_resource.command}" + cwd new_resource.directory + user new_resource.user + group new_resource.group + environment new_resource.environment + end +end + +action_class do + def bundle_command + node[:ruby][:bundle] + end +end diff --git a/cookbooks/ruby/resources/bundle_install.rb b/cookbooks/ruby/resources/bundle_install.rb new file mode 100644 index 000000000..897bde5fe --- /dev/null +++ b/cookbooks/ruby/resources/bundle_install.rb @@ -0,0 +1,52 @@ +# +# Cookbook:: ruby +# Resource:: bundle_install +# +# Copyright:: 2022, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +resource_name :bundle_install +provides :bundle_install + +unified_mode true + +default_action :run + +property :directory, :kind_of => String, :name_property => true +property :options, :kind_of => String +property :user, :kind_of => String +property :group, :kind_of => String +property :environment, :kind_of => Hash + +action :run do + execute "#{new_resource.directory}/Gemfile" do + command "#{bundle_command} install #{new_resource.options}" + cwd new_resource.directory + user new_resource.user + group new_resource.group + environment new_resource.environment + end +end + +action_class do + def bundle_command + node[:ruby][:bundle] + end +end + +def after_created + subscribes :run, "gem_package[bundler#{node[:ruby][:version]}-1]" + subscribes :run, "gem_package[bundler#{node[:ruby][:version]}-2]" +end diff --git a/cookbooks/serverinfo/metadata.rb b/cookbooks/serverinfo/metadata.rb index 73a4b3895..55d69f066 100644 --- a/cookbooks/serverinfo/metadata.rb +++ b/cookbooks/serverinfo/metadata.rb @@ -8,3 +8,4 @@ version "1.0.0" supports "ubuntu" depends "apache" depends "git" +depends "ruby" diff --git a/cookbooks/serverinfo/recipes/default.rb b/cookbooks/serverinfo/recipes/default.rb index 8d154c66a..59226a189 100644 --- a/cookbooks/serverinfo/recipes/default.rb +++ b/cookbooks/serverinfo/recipes/default.rb @@ -19,29 +19,24 @@ include_recipe "apache" include_recipe "git" +include_recipe "ruby" package %w[ gcc g++ make - ruby - ruby-dev libssl-dev zlib1g-dev pkg-config ] -gem_package "bundler" do - version "1.17.3" -end - git "/srv/hardware.openstreetmap.org" do action :sync repository "https://github.com/gravitystorm/osmf-server-info.git" depth 1 user "root" group "root" - notifies :run, "execute[/srv/hardware.openstreetmap.org/Gemfile]" + notifies :run, "bundle_install[/srv/hardware.openstreetmap.org]" end nodes = { :rows => search(:node, "*:*") } @@ -52,7 +47,7 @@ file "/srv/hardware.openstreetmap.org/_data/nodes.json" do mode "644" owner "root" group "root" - notifies :run, "execute[/srv/hardware.openstreetmap.org]" + notifies :run, "bundle_exec[/srv/hardware.openstreetmap.org]" end file "/srv/hardware.openstreetmap.org/_data/roles.json" do @@ -60,7 +55,7 @@ file "/srv/hardware.openstreetmap.org/_data/roles.json" do mode "644" owner "root" group "root" - notifies :run, "execute[/srv/hardware.openstreetmap.org]" + notifies :run, "bundle_exec[/srv/hardware.openstreetmap.org]" end directory "/srv/hardware.openstreetmap.org/_site" do @@ -77,19 +72,17 @@ directory "/srv/hardware.openstreetmap.org/.jekyll-cache" do group "nogroup" end -execute "/srv/hardware.openstreetmap.org/Gemfile" do +bundle_install "/srv/hardware.openstreetmap.org" do action :nothing - command "bundle install --deployment" - cwd "/srv/hardware.openstreetmap.org" + options "--deployment" user "root" group "root" - notifies :run, "execute[/srv/hardware.openstreetmap.org]" + notifies :run, "bundle_exec[/srv/hardware.openstreetmap.org]" end -execute "/srv/hardware.openstreetmap.org" do +bundle_exec "/srv/hardware.openstreetmap.org" do action :nothing - command "bundle exec jekyll build --trace --baseurl=https://hardware.openstreetmap.org" - cwd "/srv/hardware.openstreetmap.org" + command "jekyll build --trace --baseurl=https://hardware.openstreetmap.org" user "nobody" group "nogroup" end diff --git a/cookbooks/stateofthemap/metadata.rb b/cookbooks/stateofthemap/metadata.rb index 63481503d..b872349b2 100644 --- a/cookbooks/stateofthemap/metadata.rb +++ b/cookbooks/stateofthemap/metadata.rb @@ -6,4 +6,5 @@ description "Installs and configures State of the Map services" version "1.0.0" supports "ubuntu" +depends "ruby" depends "wordpress" diff --git a/cookbooks/stateofthemap/recipes/default.rb b/cookbooks/stateofthemap/recipes/default.rb index 37217d919..06d3eed87 100644 --- a/cookbooks/stateofthemap/recipes/default.rb +++ b/cookbooks/stateofthemap/recipes/default.rb @@ -17,6 +17,7 @@ # limitations under the License. # +include_recipe "ruby" include_recipe "wordpress" passwords = data_bag_item("stateofthemap", "passwords") @@ -303,8 +304,6 @@ package %w[ gcc g++ make - ruby - ruby-dev libssl-dev zlib1g-dev pkg-config @@ -313,14 +312,6 @@ package %w[ apache_module "expires" apache_module "rewrite" -gem_package "bundler" do - version "1.17.3" -end - -gem_package "bundler" do - version "2.1.4" -end - %w[2016 2017 2018 2019 2020 2021 2022].each do |year| git "/srv/#{year}.stateofthemap.org" do action :sync @@ -328,7 +319,7 @@ end depth 1 user "root" group "root" - notifies :run, "execute[/srv/#{year}.stateofthemap.org/Gemfile]" + notifies :run, "bundle_install[/srv/#{year}.stateofthemap.org]" end directory "/srv/#{year}.stateofthemap.org/_site" do @@ -345,20 +336,18 @@ end group "nogroup" end - execute "/srv/#{year}.stateofthemap.org/Gemfile" do + bundle_install "/srv/#{year}.stateofthemap.org" do action :nothing - command "bundle install --deployment --jobs #{node[:cpu][:total]}" - cwd "/srv/#{year}.stateofthemap.org" + options "--deployment --jobs #{node[:cpu][:total]}" user "root" group "root" - notifies :run, "execute[/srv/#{year}.stateofthemap.org]" + notifies :run, "bundle_exec[/srv/#{year}.stateofthemap.org]" only_if { ::File.exist?("/srv/#{year}.stateofthemap.org/Gemfile") } end - execute "/srv/#{year}.stateofthemap.org" do + bundle_exec "/srv/#{year}.stateofthemap.org" do action :nothing - command "bundle exec jekyll build --trace --baseurl=https://#{year}.stateofthemap.org" - cwd "/srv/#{year}.stateofthemap.org" + command "jekyll build --trace --baseurl=https://#{year}.stateofthemap.org" user "nobody" group "nogroup" environment "LANG" => "C.UTF-8" diff --git a/cookbooks/switch2osm/metadata.rb b/cookbooks/switch2osm/metadata.rb index c87125ac3..2002653b7 100644 --- a/cookbooks/switch2osm/metadata.rb +++ b/cookbooks/switch2osm/metadata.rb @@ -8,3 +8,4 @@ version "1.0.0" supports "ubuntu" depends "apache" depends "git" +depends "ruby" diff --git a/cookbooks/switch2osm/recipes/default.rb b/cookbooks/switch2osm/recipes/default.rb index c0a3da3cb..a2345be08 100644 --- a/cookbooks/switch2osm/recipes/default.rb +++ b/cookbooks/switch2osm/recipes/default.rb @@ -19,13 +19,12 @@ include_recipe "apache" include_recipe "git" +include_recipe "ruby" package %w[ gcc g++ make - ruby - ruby-dev libssl-dev zlib1g-dev pkg-config @@ -34,17 +33,13 @@ package %w[ apache_module "expires" apache_module "rewrite" -gem_package "bundler" do - version "1.17.3" -end - git "/srv/switch2osm.org" do action :sync repository "https://github.com/switch2osm/switch2osm.github.io.git" depth 1 user "root" group "root" - notifies :run, "execute[/srv/switch2osm.org/Gemfile]" + notifies :run, "bundle_install[/srv/switch2osm.org]" end directory "/srv/switch2osm.org/_site" do @@ -61,19 +56,17 @@ directory "/srv/switch2osm.org/.jekyll-cache" do group "nogroup" end -execute "/srv/switch2osm.org/Gemfile" do +bundle_install "/srv/switch2osm.org" do action :nothing - command "bundle install --deployment" - cwd "/srv/switch2osm.org" + options "--deployment" user "root" group "root" - notifies :run, "execute[/srv/switch2osm.org]" + notifies :run, "bundle_exec[/srv/switch2osm.org]" end -execute "/srv/switch2osm.org" do +bundle_exec "/srv/switch2osm.org" do action :nothing - command "bundle exec jekyll build --trace --config _config.yml,_config_osm.yml" - cwd "/srv/switch2osm.org" + command "jekyll build --trace --config _config.yml,_config_osm.yml" user "nobody" group "nogroup" end diff --git a/cookbooks/taginfo/metadata.rb b/cookbooks/taginfo/metadata.rb index 3fdbc2f51..dd79000ab 100644 --- a/cookbooks/taginfo/metadata.rb +++ b/cookbooks/taginfo/metadata.rb @@ -8,5 +8,6 @@ version "1.0.0" supports "ubuntu" depends "accounts" depends "apache" -depends "passenger" depends "git" +depends "passenger" +depends "ruby" diff --git a/cookbooks/taginfo/recipes/default.rb b/cookbooks/taginfo/recipes/default.rb index 538341521..ba25e9984 100644 --- a/cookbooks/taginfo/recipes/default.rb +++ b/cookbooks/taginfo/recipes/default.rb @@ -21,8 +21,9 @@ require "json" include_recipe "accounts" include_recipe "apache" -include_recipe "passenger" include_recipe "git" +include_recipe "passenger" +include_recipe "ruby" package %w[ libsqlite3-dev @@ -50,17 +51,6 @@ package %w[ pbzip2 ] -ruby_version = node[:passenger][:ruby_version] - -package "ruby#{ruby_version}" - -gem_package "bundler#{ruby_version}" do - package_name "bundler" - version "~> 1.16.2" - gem_binary "gem#{ruby_version}" - options "--format-executable" -end - apache_module "cache" apache_module "cache_disk" apache_module "headers" @@ -165,13 +155,10 @@ node[:taginfo][:sites].each do |site| notifies :restart, "service[apache2]" end - execute "#{directory}/taginfo/Gemfile" do + bundle_install "#{directory}/taginfo" do action :nothing - command "bundle#{ruby_version} install" - cwd "#{directory}/taginfo" user "root" group "root" - subscribes :run, "gem_package[bundler#{ruby_version}]" subscribes :run, "git[#{directory}/taginfo]" notifies :restart, "passenger_application[#{directory}/taginfo/web/public]" end diff --git a/cookbooks/web/metadata.rb b/cookbooks/web/metadata.rb index 714eb71c1..fc262fd5e 100644 --- a/cookbooks/web/metadata.rb +++ b/cookbooks/web/metadata.rb @@ -16,5 +16,6 @@ depends "memcached" depends "munin" depends "nodejs" depends "passenger" +depends "ruby" depends "systemd" depends "tools" diff --git a/cookbooks/web/recipes/cleanup.rb b/cookbooks/web/recipes/cleanup.rb index 91780994f..9ce886114 100644 --- a/cookbooks/web/recipes/cleanup.rb +++ b/cookbooks/web/recipes/cleanup.rb @@ -19,7 +19,7 @@ include_recipe "web::base" -ruby = "ruby#{node[:passenger][:ruby_version]}" +ruby = "ruby#{node[:ruby][:version]}" rails_directory = "#{node[:web][:base_directory]}/rails" template "/etc/cron.daily/web-cleanup" do diff --git a/cookbooks/web/recipes/rails.rb b/cookbooks/web/recipes/rails.rb index 59e9abfb8..44ce2a4cd 100644 --- a/cookbooks/web/recipes/rails.rb +++ b/cookbooks/web/recipes/rails.rb @@ -24,6 +24,7 @@ include_recipe "geoipupdate" include_recipe "munin" include_recipe "nodejs" include_recipe "passenger" +include_recipe "ruby" include_recipe "tools" include_recipe "web::base" @@ -49,7 +50,6 @@ template "/etc/cron.hourly/passenger" do mode "755" end -ruby_version = node[:passenger][:ruby_version] rails_directory = "#{node[:web][:base_directory]}/rails" piwik = data_bag_item("web", "piwik") @@ -100,7 +100,6 @@ db_host = if node[:web][:status] == "database_readonly" end rails_port "www.openstreetmap.org" do - ruby ruby_version directory rails_directory user "rails" group "rails" @@ -150,25 +149,13 @@ rails_port "www.openstreetmap.org" do overpass_url "https://query.openstreetmap.org/query-features" end -gem_package "bundler#{ruby_version}" do - package_name "bundler" - gem_binary "gem#{ruby_version}" - options "--format-executable" -end - -bundle = if File.exist?("/usr/bin/bundle#{ruby_version}") - "/usr/bin/bundle#{ruby_version}" - else - "/usr/local/bin/bundle#{ruby_version}" - end - systemd_service "rails-jobs@" do description "Rails job queue runner" type "simple" environment "RAILS_ENV" => "production", "QUEUE" => "%I" user "rails" working_directory rails_directory - exec_start "#{bundle} exec rake jobs:work" + exec_start "#{node[:ruby][:bundle]} exec rake jobs:work" restart "on-failure" private_tmp true private_devices true diff --git a/cookbooks/web/recipes/statistics.rb b/cookbooks/web/recipes/statistics.rb index 7f408ed79..29ee80e6c 100644 --- a/cookbooks/web/recipes/statistics.rb +++ b/cookbooks/web/recipes/statistics.rb @@ -19,7 +19,7 @@ include_recipe "web::base" -ruby = "ruby#{node[:passenger][:ruby_version]}" +ruby = "ruby#{node[:ruby][:version]}" rails_directory = "#{node[:web][:base_directory]}/rails" template "/usr/local/bin/statistics" do diff --git a/cookbooks/web/resources/rails_port.rb b/cookbooks/web/resources/rails_port.rb index 565a21efe..1524964d0 100644 --- a/cookbooks/web/resources/rails_port.rb +++ b/cookbooks/web/resources/rails_port.rb @@ -27,7 +27,6 @@ unified_mode true default_action :create property :site, String, :name_property => true -property :ruby, String, :default => "2.3" property :directory, String property :user, String property :group, String @@ -88,8 +87,6 @@ property :tile_cdn_url, String action :create do package %W[ - ruby#{new_resource.ruby} - ruby#{new_resource.ruby}-dev imagemagick nodejs tzdata @@ -121,18 +118,6 @@ action :create do libjpeg-turbo-progs ] - gem_package "bundler#{new_resource.ruby}" do - package_name "bundler" - version "2.1.4" - gem_binary "gem#{new_resource.ruby}" - options "--format-executable" - end - - gem_package "bundler#{new_resource.ruby}" do - package_name "pkg-config" - gem_binary "gem#{new_resource.ruby}" - end - declare_resource :directory, rails_directory do owner new_resource.user group new_resource.group @@ -404,21 +389,18 @@ action :create do end end - execute "#{rails_directory}/Gemfile" do + bundle_install "#{rails_directory}" do action :nothing - command "bundle#{new_resource.ruby} install" - cwd rails_directory user "root" group "root" environment "NOKOGIRI_USE_SYSTEM_LIBRARIES" => "yes" - subscribes :run, "gem_package[bundler#{new_resource.ruby}]" subscribes :run, "git[#{rails_directory}]" end - execute "#{rails_directory}/db/migrate" do + bundle_exec "#{rails_directory}/db/migrate" do action :nothing - command "bundle#{new_resource.ruby} exec rake db:migrate" - cwd rails_directory + directory rails_directory + command "rails db:migrate" user new_resource.user group new_resource.group subscribes :run, "git[#{rails_directory}]" @@ -429,36 +411,36 @@ action :create do only_if { new_resource.build_assets } end - execute "#{rails_directory}/package.json" do + bundle_exec "#{rails_directory}/package.json" do action :nothing - command "bundle#{new_resource.ruby} exec rake yarn:install" + directory rails_directory + command "rails yarn:install" environment "HOME" => rails_directory, "RAILS_ENV" => "production" - cwd rails_directory user new_resource.user group new_resource.group subscribes :run, "git[#{rails_directory}]" only_if { new_resource.build_assets } end - execute "#{rails_directory}/app/assets/javascripts/i18n" do + bundle_exec "#{rails_directory}/app/assets/javascripts/i18n" do action :nothing - command "bundle#{new_resource.ruby} exec rake i18n:js:export" + directory rails_directory + command "rails i18n:js:export" environment "HOME" => rails_directory, "RAILS_ENV" => "production" - cwd rails_directory user new_resource.user group new_resource.group subscribes :run, "git[#{rails_directory}]" only_if { new_resource.build_assets } end - execute "#{rails_directory}/public/assets" do + bundle_exec "#{rails_directory}/public/assets" do action :nothing - command "bundle#{new_resource.ruby} exec rake assets:precompile" + directory rails_directory + command "rails assets:precompile" environment "HOME" => rails_directory, "RAILS_ENV" => "production" - cwd rails_directory user new_resource.user group new_resource.group subscribes :run, "git[#{rails_directory}]" @@ -466,8 +448,8 @@ action :create do subscribes :run, "file[#{rails_directory}/config/settings.local.yml]" subscribes :run, "file[#{rails_directory}/config/storage.yml]" subscribes :run, "file[#{rails_directory}/config/piwik.yml]" - subscribes :run, "execute[#{rails_directory}/package.json]" - subscribes :run, "execute[#{rails_directory}/app/assets/javascripts/i18n]" + subscribes :run, "bundle_exec[#{rails_directory}/package.json]" + subscribes :run, "bundle_exec[#{rails_directory}/app/assets/javascripts/i18n]" only_if { new_resource.build_assets } end @@ -485,11 +467,11 @@ action :create do subscribes :restart, "file[#{rails_directory}/config/settings.local.yml]" subscribes :restart, "file[#{rails_directory}/config/storage.yml]" subscribes :restart, "file[#{rails_directory}/config/piwik.yml]" - subscribes :restart, "execute[#{rails_directory}/Gemfile]" - subscribes :restart, "execute[#{rails_directory}/db/migrate]" - subscribes :restart, "execute[#{rails_directory}/package.json]" - subscribes :restart, "execute[#{rails_directory}/app/assets/javascripts/i18n]" - subscribes :restart, "execute[#{rails_directory}/public/assets]" + subscribes :restart, "bundle_installl[#{rails_directory}]" + subscribes :restart, "bundle_exec[#{rails_directory}/db/migrate]" + subscribes :restart, "bundle_exec[#{rails_directory}/package.json]" + subscribes :restart, "bundle_exec[#{rails_directory}/app/assets/javascripts/i18n]" + subscribes :restart, "bundle_exec[#{rails_directory}/public/assets]" only_if { ::File.exist?("/usr/bin/passenger-config") } end