]> git.openstreetmap.org Git - chef.git/commitdiff
Centralise ruby installation in a new cookbook
authorTom Hughes <tom@compton.nu>
Tue, 28 Jun 2022 19:38:43 +0000 (20:38 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 28 Jun 2022 23:35:27 +0000 (00:35 +0100)
32 files changed:
cookbooks/blogs/metadata.rb
cookbooks/blogs/recipes/default.rb
cookbooks/blogs/templates/default/blogs-update.erb
cookbooks/db/metadata.rb
cookbooks/db/recipes/base.rb
cookbooks/dev/metadata.rb
cookbooks/dev/recipes/default.rb
cookbooks/foundation/metadata.rb
cookbooks/foundation/recipes/owg.rb
cookbooks/passenger/attributes/default.rb
cookbooks/passenger/metadata.rb
cookbooks/passenger/recipes/default.rb
cookbooks/passenger/templates/default/ruby.erb
cookbooks/ruby/README.md [new file with mode: 0644]
cookbooks/ruby/attributes/default.rb [new file with mode: 0644]
cookbooks/ruby/metadata.rb [new file with mode: 0644]
cookbooks/ruby/recipes/default.rb [new file with mode: 0644]
cookbooks/ruby/resources/bundle_exec.rb [new file with mode: 0644]
cookbooks/ruby/resources/bundle_install.rb [new file with mode: 0644]
cookbooks/serverinfo/metadata.rb
cookbooks/serverinfo/recipes/default.rb
cookbooks/stateofthemap/metadata.rb
cookbooks/stateofthemap/recipes/default.rb
cookbooks/switch2osm/metadata.rb
cookbooks/switch2osm/recipes/default.rb
cookbooks/taginfo/metadata.rb
cookbooks/taginfo/recipes/default.rb
cookbooks/web/metadata.rb
cookbooks/web/recipes/cleanup.rb
cookbooks/web/recipes/rails.rb
cookbooks/web/recipes/statistics.rb
cookbooks/web/resources/rails_port.rb

index 19d88bcfec8c8f80a8ed933c2e449b70d9ba62df..e63df4125a3d0be55db033d4f72203d0bb620fa7 100644 (file)
@@ -9,3 +9,4 @@ supports          "ubuntu"
 depends           "accounts"
 depends           "apache"
 depends           "git"
+depends           "ruby"
index 165befb5e6f391d0f17b40c202bfa590c97b7f79..eb13152fa3849cc13e93c8d86dd2566ab4fdfd21 100644 (file)
 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
index 0125b41badc5c16191a4a31481ac1e1374a8ee55..15cc82483678222e75d58330689511e8aa9aa99a 100644 (file)
@@ -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 \
index aadfe47dbab448723064f2f3ad42022e6004dfb5..d52927a7586ae52f5a8b96533d6b56363deef144 100644 (file)
@@ -10,4 +10,5 @@ depends           "accounts"
 depends           "git"
 depends           "postgresql"
 depends           "python"
+depends           "ruby"
 depends           "web"
index 51bfca632ebec52734affa8c6880e4d6665a78cd..520fbe2e86ab1c84a547a3fd209bcc147cf67b15 100644 (file)
@@ -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"
index 457e46dd090e4936639a5f67e5b48c6e3ad3c2ea..29e665a43dc0934fc0b1bcbb23d75f7436489cff 100644 (file)
@@ -18,5 +18,6 @@ depends           "nodejs"
 depends           "php"
 depends           "postgresql"
 depends           "python"
+depends           "ruby"
 depends           "tools"
 depends           "web"
index 4b539e9c8c4ec1c4202bf2d9c8223e1754ed83c4..679ff6b4cff2b3b82dd7b85ebcdf99254a2f3b1a 100644 (file)
@@ -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"
index 8aa8882960c6f4a9a071e6e3736f8bc07dc2a7ee..426a683c78564c570dedd5fc151ca80a2bd09861 100644 (file)
@@ -9,3 +9,4 @@ supports          "ubuntu"
 depends           "apache"
 depends           "git"
 depends           "mediawiki"
+depends           "ruby"
index fb9aca201a4a6135ebe33952ad2805e9484844df..6c637c62aa684eddc97ca014092dcebd4127c546 100644 (file)
 
 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
index 03c6b5a8d13ab44068c0a049089f4003b758b410..2ac125c126008d471d9c58576619bcc500420a0d 100644 (file)
@@ -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"
index 42fc95c2aa8b7e0acadbc8552ed6ce4f68e7556f..8cbf75fa632e040e69d331a1b8f5507e0ddaedb1 100644 (file)
@@ -10,4 +10,5 @@ depends           "apache"
 depends           "apt"
 depends           "munin"
 depends           "prometheus"
+depends           "ruby"
 depends           "systemd"
index 95abd7890847bf82a2be293460b2334364b514f8..f8ea95808c4ac38dcb21c9d85e5ee63b69d4d1fc 100644 (file)
@@ -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"
index fb7575ab0ad9e424609b8c034e7131cf6f5fc24e..f45fd210eaa6d2f11844bb75baab50b5ecd8df00 100644 (file)
@@ -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 (file)
index 0000000..d7f1641
--- /dev/null
@@ -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 (file)
index 0000000..39e975e
--- /dev/null
@@ -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 (file)
index 0000000..d8f2eac
--- /dev/null
@@ -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 (file)
index 0000000..3ec7b03
--- /dev/null
@@ -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 (file)
index 0000000..e4150f6
--- /dev/null
@@ -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 (file)
index 0000000..897bde5
--- /dev/null
@@ -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
index 73a4b3895f3cf0631d3989bcf91b254b9ca47c0a..55d69f066a86c04d0e34089187d1410f87e39fea 100644 (file)
@@ -8,3 +8,4 @@ version           "1.0.0"
 supports          "ubuntu"
 depends           "apache"
 depends           "git"
+depends           "ruby"
index 8d154c66a08ca687d0a875a9e989e79a8fcc0d28..59226a189a706f97bf6287ca18d00a463984ca34 100644 (file)
 
 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
index 63481503df6e6ee5d6e1000d77095a3b32d64e46..b872349b24f68b476c896f087c06d12e06c85e58 100644 (file)
@@ -6,4 +6,5 @@ description       "Installs and configures State of the Map services"
 
 version           "1.0.0"
 supports          "ubuntu"
+depends           "ruby"
 depends           "wordpress"
index 37217d919d14215c56f3161b6a4c5dade980521f..06d3eed879965b1136f0e5042baf7db6ed057fca 100644 (file)
@@ -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"
index c87125ac31767544ce6007a5e40d90cf06076268..2002653b7e47fdce4eaaad156fe91c6cfda32f37 100644 (file)
@@ -8,3 +8,4 @@ version           "1.0.0"
 supports          "ubuntu"
 depends           "apache"
 depends           "git"
+depends           "ruby"
index c0a3da3cbf87aa9165c268e93b7b0c876f9a6a84..a2345be08c4e837b95e87823115217cffa0985d7 100644 (file)
 
 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
index 3fdbc2f51086bf2ce992c0314cee6ad9639f2c83..dd79000ab118d2ebaa5df0199ec2d637cc80fb9d 100644 (file)
@@ -8,5 +8,6 @@ version           "1.0.0"
 supports          "ubuntu"
 depends           "accounts"
 depends           "apache"
-depends           "passenger"
 depends           "git"
+depends           "passenger"
+depends           "ruby"
index 5383415217ea5f543e05dfe7f37e2f436c0628d7..ba25e998421f73076a071e4d3f5cf9e9441fdc32 100644 (file)
@@ -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
index 714eb71c1c98c05314a50d2f06be0b4a5ab08c04..fc262fd5ea16333ca93f9dcb12b4347b65638f3e 100644 (file)
@@ -16,5 +16,6 @@ depends           "memcached"
 depends           "munin"
 depends           "nodejs"
 depends           "passenger"
+depends           "ruby"
 depends           "systemd"
 depends           "tools"
index 91780994f57f867c212eb3978b01aaa39440a878..9ce886114de825b4595793e3d3d60c23d247b879 100644 (file)
@@ -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
index 59e9abfb8f0479218fd90fcc9d53471a3d05caf4..44ce2a4cdc12ed315be2d1ab80982cffc4ac860b 100644 (file)
@@ -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
index 7f408ed79c3bd64fcc9f1cb12bcc058b6d0eabdf..29ee80e6c71af6cef064fe83651740a4e772b115 100644 (file)
@@ -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
index 565a21efe5803a0ace1a9348bd84bbca8497e878..1524964d0b6e030bd4c6a53784ad9388097c4b18 100644 (file)
@@ -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