From 5141e1305a91eb553fc09fdf27161390e5efab5a Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Fri, 23 Sep 2016 10:52:14 +0200 Subject: [PATCH 1/2] Add support for DNF If the folder `/car/cache/dnf` is present, the content will be cached like in the Yum plugin. A possible configuration to enable it: Vagrant.configure(2) do |config| config.vm.box = "fedora/24-cloud-base" if Vagrant.has_plugin?("vagrant-cachier") config.cache.scope = :machine config.cache.auto_detect = false config.cache.enable :dnf end end --- docs/buckets/dnf.md | 20 ++++++++++++++ docs/template.html | 1 + lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/dnf.rb | 26 +++++++++++++++++++ .../cap/redhat/dnf_cache_dir.rb | 13 ++++++++++ lib/vagrant-cachier/capabilities.rb | 5 ++++ 6 files changed, 66 insertions(+) create mode 100644 docs/buckets/dnf.md create mode 100644 lib/vagrant-cachier/bucket/dnf.rb create mode 100644 lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb diff --git a/docs/buckets/dnf.md b/docs/buckets/dnf.md new file mode 100644 index 0000000..9d897a1 --- /dev/null +++ b/docs/buckets/dnf.md @@ -0,0 +1,20 @@ +# DNF + +Used by Fedora guests, will get configured under guest's `/var/cache/dnf`. It will +also [make sure](lib/vagrant-cachier/bucket/dnf.rb#L20) that `keepcache` is set to +`1` on guest's `/etc/dnf/dnf.conf`. + +To manually enable it: + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-fedora-box' + config.cache.enable :dnf +end +``` + +### :warning: Notice about Windows hosts :warning: + +In case this bucket is enabled and a Windows host is in use, you might see an +ugly stacktrace as described on [this comment](https://github.com/fgrehm/vagrant-cachier/issues/117#issuecomment-50548393) +if some DNF repository is not available during provisioning. diff --git a/docs/template.html b/docs/template.html index 0bdbcd1..9679ad4 100644 --- a/docs/template.html +++ b/docs/template.html @@ -89,6 +89,7 @@
  • Chef
  • Chef Gems
  • Composer
  • +
  • DNF
  • Bower
  • Pacman
  • npm
  • diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index 4d392a6..576b019 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -93,6 +93,7 @@ def symlink?(path) require_relative "bucket/chef_gem" require_relative "bucket/pacman" require_relative "bucket/yum" +require_relative "bucket/dnf" require_relative "bucket/rvm" require_relative "bucket/apt_cacher" require_relative "bucket/apt_lists" diff --git a/lib/vagrant-cachier/bucket/dnf.rb b/lib/vagrant-cachier/bucket/dnf.rb new file mode 100644 index 0000000..6630555 --- /dev/null +++ b/lib/vagrant-cachier/bucket/dnf.rb @@ -0,0 +1,26 @@ +module VagrantPlugins + module Cachier + class Bucket + class Dnf < Bucket + def self.capability + :dnf_cache_dir + end + + def install + if guest.capability?(:dnf_cache_dir) + guest_path = guest.capability(:dnf_cache_dir) + return if @env[:cache_dirs].include?(guest_path) + + # Ensure caching is enabled + comm.sudo("sed -i '/keepcache=/d' /etc/dnf/dnf.conf") + comm.sudo("sed -i '/^[main]/a keepcache=1' /etc/dnf/dnf.conf") + + symlink(guest_path) + else + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'DNF') + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb b/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb new file mode 100644 index 0000000..5723a96 --- /dev/null +++ b/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb @@ -0,0 +1,13 @@ +module VagrantPlugins + module Cachier + module Cap + module RedHat + module DnfCacheDir + def self.dnf_cache_dir(machine) + '/var/cache/dnf' + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/capabilities.rb b/lib/vagrant-cachier/capabilities.rb index fab48c2..ce73499 100644 --- a/lib/vagrant-cachier/capabilities.rb +++ b/lib/vagrant-cachier/capabilities.rb @@ -61,6 +61,11 @@ class Plugin < Vagrant.plugin('2') Cap::RedHat::YumCacheDir end + guest_capability 'redhat', 'dnf_cache_dir' do + require_relative 'cap/redhat/dnf_cache_dir' + Cap::RedHat::DnfCacheDir + end + guest_capability 'suse', 'yum_cache_dir' do # Disable Yum on suse guests end From fad6bbf6a0ba080da85c4ee4076711a0bf568352 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Mon, 26 Sep 2016 13:59:40 +0200 Subject: [PATCH 2/2] Yum is replaced by DNF in newer Fedora releases Check if yum is really present on a 'redhat' machine. Only if it is, enable the Yum bucket. The same for DNF since older versions of CentOS and Fedora do not ship DNF. --- lib/vagrant-cachier/bucket/dnf.rb | 13 +++++++------ lib/vagrant-cachier/bucket/yum.rb | 11 ++++++----- lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb | 7 ++++++- lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb | 8 +++++++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/vagrant-cachier/bucket/dnf.rb b/lib/vagrant-cachier/bucket/dnf.rb index 6630555..93ca9c8 100644 --- a/lib/vagrant-cachier/bucket/dnf.rb +++ b/lib/vagrant-cachier/bucket/dnf.rb @@ -8,14 +8,15 @@ def self.capability def install if guest.capability?(:dnf_cache_dir) - guest_path = guest.capability(:dnf_cache_dir) - return if @env[:cache_dirs].include?(guest_path) + if guest_path = guest.capability(:dnf_cache_dir) + return if @env[:cache_dirs].include?(guest_path) - # Ensure caching is enabled - comm.sudo("sed -i '/keepcache=/d' /etc/dnf/dnf.conf") - comm.sudo("sed -i '/^[main]/a keepcache=1' /etc/dnf/dnf.conf") + # Ensure caching is enabled + comm.sudo("sed -i '/keepcache=/d' /etc/dnf/dnf.conf") + comm.sudo("sed -i '/^[main]/a keepcache=1' /etc/dnf/dnf.conf") - symlink(guest_path) + symlink(guest_path) + end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'DNF') end diff --git a/lib/vagrant-cachier/bucket/yum.rb b/lib/vagrant-cachier/bucket/yum.rb index b58ce19..55a6f1f 100644 --- a/lib/vagrant-cachier/bucket/yum.rb +++ b/lib/vagrant-cachier/bucket/yum.rb @@ -8,13 +8,14 @@ def self.capability def install if guest.capability?(:yum_cache_dir) - guest_path = guest.capability(:yum_cache_dir) - return if @env[:cache_dirs].include?(guest_path) + if guest_path = guest.capability(:yum_cache_dir) + return if @env[:cache_dirs].include?(guest_path) - # Ensure caching is enabled - comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf") + # Ensure caching is enabled + comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf") - symlink(guest_path) + symlink(guest_path) + end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum') end diff --git a/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb b/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb index 5723a96..e9e42d6 100644 --- a/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb +++ b/lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb @@ -4,7 +4,12 @@ module Cap module RedHat module DnfCacheDir def self.dnf_cache_dir(machine) - '/var/cache/dnf' + dnf_cache_dir = nil + machine.communicate.tap do |comm| + return unless comm.test('which dnf') + dnf_cache_dir = '/var/cache/dnf' + end + return dnf_cache_dir end end end diff --git a/lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb b/lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb index 2639ab0..0b5b0d9 100644 --- a/lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb +++ b/lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb @@ -4,7 +4,13 @@ module Cap module RedHat module YumCacheDir def self.yum_cache_dir(machine) - '/var/cache/yum' + yum_cache_dir = nil + machine.communicate.tap do |comm| + # In case yum is only forwarding to dnf do not cache + return unless not comm.test('yum --version 2>&1 | grep /usr/bin/dnf') + yum_cache_dir = '/var/cache/yum' + end + return yum_cache_dir end end end