Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

dnf plugin #180

Merged
merged 2 commits into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/buckets/dnf.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions docs/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<li><a tabindex="-1" href="buckets/chef">Chef</a></li>
<li><a tabindex="-1" href="buckets/chef_rubygems">Chef Gems</a></li>
<li><a tabindex="-1" href="buckets/composer">Composer</a></li>
<li><a tabindex="-1" href="buckets/dnf">DNF</a></li>
<li><a tabindex="-1" href="buckets/bower">Bower</a></li>
<li><a tabindex="-1" href="buckets/pacman">Pacman</a></li>
<li><a tabindex="-1" href="buckets/npm">npm</a></li>
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-cachier/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions lib/vagrant-cachier/bucket/dnf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module VagrantPlugins
module Cachier
class Bucket
class Dnf < Bucket
def self.capability
:dnf_cache_dir
end

def install
if guest.capability?(:dnf_cache_dir)
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")

symlink(guest_path)
end
else
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'DNF')
end
end
end
end
end
end
11 changes: 6 additions & 5 deletions lib/vagrant-cachier/bucket/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions lib/vagrant-cachier/cap/redhat/dnf_cache_dir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module VagrantPlugins
module Cachier
module Cap
module RedHat
module DnfCacheDir
def self.dnf_cache_dir(machine)
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
end
end
end
8 changes: 7 additions & 1 deletion lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-cachier/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down