From 9949b7666e55675ff8e962fc7c44140b80b21125 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 19 Jan 2020 16:33:03 +0000 Subject: [PATCH] Use chef cache directory instead of creating our own --- cookbooks/chef/recipes/default.rb | 15 ++++++++------- cookbooks/chef/recipes/server.rb | 16 ++++++---------- cookbooks/civicrm/recipes/default.rb | 22 ++++++++++++---------- cookbooks/forum/recipes/default.rb | 10 ++++++---- cookbooks/osmosis/recipes/default.rb | 26 ++++++++++++++------------ 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/cookbooks/chef/recipes/default.rb b/cookbooks/chef/recipes/default.rb index f2f0101c0..e6979bb4b 100644 --- a/cookbooks/chef/recipes/default.rb +++ b/cookbooks/chef/recipes/default.rb @@ -17,17 +17,18 @@ # limitations under the License. # +cache_dir = Chef::Config[:file_cache_path] + chef_version = node[:chef][:client][:version] chef_package = "chef_#{chef_version}-1_amd64.deb" directory "/var/cache/chef" do - owner "root" - group "root" - mode 0o755 + action :delete + recursive true end -Dir.glob("/var/cache/chef/chef_*.deb").each do |deb| - next if deb == "/var/cache/chef/#{chef_package}" +Dir.glob("#{cache_dir}/chef_*.deb").each do |deb| + next if deb == "#{cache_dir}/#{chef_package}" file deb do action :delete @@ -35,7 +36,7 @@ Dir.glob("/var/cache/chef/chef_*.deb").each do |deb| end end -remote_file "/var/cache/chef/#{chef_package}" do +remote_file "#{cache_dir}/#{chef_package}" do source "https://packages.chef.io/files/stable/chef/#{chef_version}/ubuntu/#{node[:lsb][:release]}/#{chef_package}" owner "root" group "root" @@ -45,7 +46,7 @@ remote_file "/var/cache/chef/#{chef_package}" do end dpkg_package "chef" do - source "/var/cache/chef/#{chef_package}" + source "#{cache_dir}/#{chef_package}" version "#{chef_version}-1" end diff --git a/cookbooks/chef/recipes/server.rb b/cookbooks/chef/recipes/server.rb index eb2a33ae4..5eb30d0b6 100644 --- a/cookbooks/chef/recipes/server.rb +++ b/cookbooks/chef/recipes/server.rb @@ -19,25 +19,21 @@ include_recipe "apache" +# cache_dir = Chef::Config[:file_cache_path] +# # chef_version = node[:chef][:server][:version] # chef_package = "chef-server-core_#{chef_version}-1_amd64.deb" # -# directory "/var/cache/chef" do -# owner "root" -# group "root" -# mode 0755 -# end +# Dir.glob("#{cache_dir}/chef-server-core_*.deb").each do |deb| +# next if deb == "#{cache_dir}/#{chef_package}" # -# Dir.glob("/var/cache/chef/chef-server-core_*.deb").each do |deb| -# next if deb == "/var/cache/chef/#{chef_package}" - # file deb do # action :delete # backup false # end # end # -# remote_file "/var/cache/chef/#{chef_package}" do +# remote_file "#{cache_dir}/#{chef_package}" do # source "https://packages.chef.io/files/stable/chef-server/#{chef_version}/ubuntu/16.04/#{chef_package}" # owner "root" # group "root" @@ -46,7 +42,7 @@ include_recipe "apache" # end # # dpkg_package "chef-server-core" do -# source "/var/cache/chef/#{chef_package}" +# source "#{cache_dir}/#{chef_package}" # version "#{chef_version}-1" # notifies :run, "execute[chef-server-reconfigure]" # end diff --git a/cookbooks/civicrm/recipes/default.rb b/cookbooks/civicrm/recipes/default.rb index 46c17d504..cadc73212 100644 --- a/cookbooks/civicrm/recipes/default.rb +++ b/cookbooks/civicrm/recipes/default.rb @@ -22,6 +22,8 @@ include_recipe "mysql" package "wkhtmltopdf" +cache_dir = Chef::Config[:file_cache_path] + passwords = data_bag_item("civicrm", "passwords") database_password = passwords["database"] @@ -69,7 +71,7 @@ directory "/opt/civicrm-#{civicrm_version}" do mode 0o755 end -remote_file "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do +remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do action :create_if_missing source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip" owner "wordpress" @@ -78,7 +80,7 @@ remote_file "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do backup false end -remote_file "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do +remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do action :create_if_missing source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz" owner "wordpress" @@ -87,22 +89,22 @@ remote_file "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do backup false end -execute "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do +execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do action :nothing - command "unzip -qq /var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" + command "unzip -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" cwd "/opt/civicrm-#{civicrm_version}" user "wordpress" group "wordpress" - subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately + subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately end -execute "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do +execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do action :nothing - command "tar -zxf /var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" + command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" cwd "/opt/civicrm-#{civicrm_version}/civicrm" user "wordpress" group "wordpress" - subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately + subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately end execute "/opt/civicrm-#{civicrm_version}/civicrm" do @@ -110,8 +112,8 @@ execute "/opt/civicrm-#{civicrm_version}/civicrm" do command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}" user "wordpress" group "wordpress" - subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately - subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately + subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately + subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately end directory "/srv/join.osmfoundation.org/wp-content/plugins/files" do diff --git a/cookbooks/forum/recipes/default.rb b/cookbooks/forum/recipes/default.rb index 682a2bfa2..0f0001940 100644 --- a/cookbooks/forum/recipes/default.rb +++ b/cookbooks/forum/recipes/default.rb @@ -20,6 +20,8 @@ include_recipe "apache" include_recipe "git" include_recipe "mysql" +cache_dir = Chef::Config[:file_cache_path] + passwords = data_bag_item("forum", "passwords") package %w[ @@ -59,7 +61,7 @@ git "/srv/forum.openstreetmap.org/html/" do notifies :reload, "service[apache2]" end -remote_file "/var/cache/chef/air3_v0.8.zip" do +remote_file "#{cache_dir}/air3_v0.8.zip" do action :create_if_missing source "https://fluxbb.org/resources/styles/air3/releases/0.8/air3_v0.8.zip" owner "root" @@ -68,13 +70,13 @@ remote_file "/var/cache/chef/air3_v0.8.zip" do backup false end -execute "/var/cache/chef/air3_v0.8.zip" do +execute "#{cache_dir}/air3_v0.8.zip" do action :nothing - command "unzip -o -qq /var/cache/chef/air3_v0.8.zip Air3.css Air3/*" + command "unzip -o -qq #{cache_dir}/air3_v0.8.zip Air3.css Air3/*" cwd "/srv/forum.openstreetmap.org/html/style" user "forum" group "forum" - subscribes :run, "remote_file[/var/cache/chef/air3_v0.8.zip]", :immediately + subscribes :run, "remote_file[#{cache_dir}/air3_v0.8.zip]", :immediately end directory "/srv/forum.openstreetmap.org/html/cache/" do diff --git a/cookbooks/osmosis/recipes/default.rb b/cookbooks/osmosis/recipes/default.rb index 8de53eb37..6896fcd20 100644 --- a/cookbooks/osmosis/recipes/default.rb +++ b/cookbooks/osmosis/recipes/default.rb @@ -22,11 +22,13 @@ include_recipe "chef" package "unzip" package "default-jre" +cache_dir = Chef::Config[:file_cache_path] + osmosis_package = "osmosis-#{node[:osmosis][:version]}.zip" osmosis_directory = "/opt/osmosis-#{node[:osmosis][:version]}" -Dir.glob("/var/cache/chef/osmosis-*.zip").each do |zip| - next if zip == "/var/cache/chef/#{osmosis_package}" +Dir.glob("#{cache_dir}/osmosis-*.zip").each do |zip| + next if zip == "#{cache_dir}/#{osmosis_package}" file zip do action :delete @@ -40,22 +42,22 @@ directory osmosis_directory do mode 0o755 end -execute "/var/cache/chef/#{osmosis_package}" do - action :nothing - command "unzip -q /var/cache/chef/#{osmosis_package}" - cwd osmosis_directory - user "root" - group "root" -end - -remote_file "/var/cache/chef/#{osmosis_package}" do +remote_file "#{cache_dir}/#{osmosis_package}" do action :create_if_missing source "https://bretth.dev.openstreetmap.org/osmosis-build/#{osmosis_package}" owner "root" group "root" mode 0o644 backup false - notifies :run, "execute[/var/cache/chef/#{osmosis_package}]" +end + +execute "#{cache_dir}/#{osmosis_package}" do + action :nothing + command "unzip -q #{cache_dir}/#{osmosis_package}" + cwd osmosis_directory + user "root" + group "root" + subscribes :run, "execute[#{cache_dir}/#{osmosis_package}]" end link "/usr/local/bin/osmosis" do -- 2.39.5