From 817d964b8e7db705338198d363573bb975a7f993 Mon Sep 17 00:00:00 2001 From: fh Date: Mon, 21 Oct 2013 11:17:59 +0200 Subject: [PATCH] Adding support for composer cache - http://getcomposer.org/ --- lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/composer.rb | 36 +++++++++++++++++++ .../cap/linux/composer_path.rb | 14 ++++++++ lib/vagrant-cachier/plugin.rb | 5 +++ 4 files changed, 56 insertions(+) create mode 100644 lib/vagrant-cachier/bucket/composer.rb create mode 100644 lib/vagrant-cachier/cap/linux/composer_path.rb diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index 0e425a8..8b3e04f 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -40,3 +40,4 @@ require_relative "bucket/pacman" require_relative "bucket/yum" require_relative "bucket/rvm" require_relative "bucket/apt_cacher" +require_relative "bucket/composer" diff --git a/lib/vagrant-cachier/bucket/composer.rb b/lib/vagrant-cachier/bucket/composer.rb new file mode 100644 index 0000000..dff71b5 --- /dev/null +++ b/lib/vagrant-cachier/bucket/composer.rb @@ -0,0 +1,36 @@ +module VagrantPlugins + module Cachier + class Bucket + class Composer < Bucket + def self.capability + :composer_path + end + + def install + machine = @env[:machine] + guest = machine.guest + + if guest.capability?(:composer_path) + if composer_path = guest.capability(:composer_path) + bucket_path = "/tmp/vagrant-cache/#{@name}/" + #remove trailing slash, or symlink will fail + composer_path = composer_path.chomp('/') + @env[:cache_dirs] << composer_path + + machine.communicate.tap do |comm| + comm.execute("mkdir -p #{bucket_path}") + + unless comm.test("test -L #{composer_path}") + comm.sudo("rm -rf #{composer_path}") + comm.sudo("ln -s #{bucket_path} #{composer_path}") + end + end + end + else + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer') + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/linux/composer_path.rb b/lib/vagrant-cachier/cap/linux/composer_path.rb new file mode 100644 index 0000000..3e9116c --- /dev/null +++ b/lib/vagrant-cachier/cap/linux/composer_path.rb @@ -0,0 +1,14 @@ +module VagrantPlugins + module Cachier + module Cap + module Linux + module ComposerPath + def self.composer_path(machine) + composer_path = '/home/vagrant/.composer/' + return composer_path + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 29dc502..929e0f3 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -26,6 +26,11 @@ module VagrantPlugins Cap::Linux::RvmPath end + guest_capability 'linux', 'composer_path' do + require_relative 'cap/linux/composer_path' + Cap::Linux::ComposerPath + end + guest_capability 'linux', 'chef_file_cache_path' do require_relative 'cap/linux/chef_file_cache_path' Cap::Linux::ChefFileCachePath