From 93c0c7bf990a267a430f745f47be9d6e7c487758 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Tue, 5 Nov 2013 15:00:39 +0100 Subject: [PATCH] add zypper support --- CHANGELOG.md | 4 +++ README.md | 15 +++++++- lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/zypper.rb | 36 +++++++++++++++++++ .../cap/suse/zypper_cache_dir.rb | 14 ++++++++ lib/vagrant-cachier/plugin.rb | 5 +++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 lib/vagrant-cachier/bucket/zypper.rb create mode 100644 lib/vagrant-cachier/cap/suse/zypper_cache_dir.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 740828e..f023667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [0.4.2](https://github.com/fgrehm/vagrant-cachier/compare/v0.4.1...master) (unreleased) +FEATURES: + + - Support for [zypper] [GH-54] + ## [0.4.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.4.0...v0.4.1) (Oct 27, 2013) BUG FIXES: diff --git a/README.md b/README.md index 5771af2..ef50506 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,20 @@ _Please note that to avoid re-downloading packages, you should avoid `apt-get cl as much as possible in order to make a better use of the cache, even if you are packaging a box_ -##### Yum +##### Zypper + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-suse-box' + config.cache.enable :zypper +end +``` + +Used by SuSE guests, will get configured under guest's `/var/cache/zypper/packages`. It will +also [make sure](lib/vagrant-cachier/bucket/zypper.rb#L20) that `keep-packages` is enabled +for all repositories. + +###### Yum ```ruby Vagrant.configure("2") do |config| diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index 93b067d..7f38131 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -42,3 +42,4 @@ require_relative "bucket/rvm" require_relative "bucket/apt_cacher" require_relative "bucket/composer" require_relative "bucket/npm" +require_relative "bucket/zypper" diff --git a/lib/vagrant-cachier/bucket/zypper.rb b/lib/vagrant-cachier/bucket/zypper.rb new file mode 100644 index 0000000..f556b21 --- /dev/null +++ b/lib/vagrant-cachier/bucket/zypper.rb @@ -0,0 +1,36 @@ +module VagrantPlugins + module Cachier + class Bucket + class Zypper < Bucket + def self.capability + :zypper_cache_dir + end + + def install + machine = @env[:machine] + guest = machine.guest + + if guest.capability?(:zypper_cache_dir) + guest_path = guest.capability(:zypper_cache_dir) + + @env[:cache_dirs] << guest_path + + machine.communicate.tap do |comm| + # Ensure caching is enabled + comm.sudo("zypper modifyrepo --keep-packages --all") + + comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}") + unless comm.test("test -L #{guest_path}") + comm.sudo("rm -rf #{guest_path}") + comm.sudo("mkdir -p `dirname #{guest_path}`") + comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}") + end + end + else + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Zypper') + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/suse/zypper_cache_dir.rb b/lib/vagrant-cachier/cap/suse/zypper_cache_dir.rb new file mode 100644 index 0000000..9d21047 --- /dev/null +++ b/lib/vagrant-cachier/cap/suse/zypper_cache_dir.rb @@ -0,0 +1,14 @@ +module VagrantPlugins + module Cachier + module Cap + module SuSE + module ZypperCacheDir + def self.zypper_cache_dir(machine) + # TODO: Find out if there is a config file we can read from + '/var/cache/zypp/packages' + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index ec31076..01dfe0a 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -61,6 +61,11 @@ module VagrantPlugins Cap::Arch::PacmanCacheDir end + guest_capability 'suse', 'zypper_cache_dir' do + require_relative 'cap/suse/zypper_cache_dir' + Cap::SuSE::ZypperCacheDir + end + # TODO: This should be generic, we don't want to hard code every single # possible provider action class that Vagrant might have ensure_single_cache_root = lambda do |hook|