Allow explicit disabling of auto detected buckets

Add config option to identify buckets that should not be automatically
enabled with using `config.cache.auto_detect = true`.

After turning on the auto_detect behaviour, with this change you can
now explicitly disable any bucket type through your Vagrantfile e.g.
`config.cache.disable = :chef_gem`.

Fixes #115
This commit is contained in:
Darragh Bailey 2015-02-09 13:31:35 +00:00 committed by Darragh Bailey
parent 2bb7f21273
commit 7807d2bbaa
7 changed files with 69 additions and 2 deletions

View file

@ -95,6 +95,22 @@ end
_Please refer to the "Available Buckets" menu above to find out which buckets _Please refer to the "Available Buckets" menu above to find out which buckets
are supported._ are supported._
## Disable buckets in auto-detect mode
If for some reason you need to disable certain buckets but want the remaining
buckets to be configured you can do so by disabling on an individual basis in
your `Vagrantfile`:
```ruby
Vagrant.configure("2") do |config|
config.cache.auto_detect = true
config.cache.disable = :chef_gem
end
```
_Please refer to the "Available Buckets" menu above to find out which buckets
are supported._
## Custom cache buckets synced folders options ## Custom cache buckets synced folders options
For fine grained control over the cache bucket synced folder options you can use For fine grained control over the cache bucket synced folder options you can use

View file

@ -39,6 +39,7 @@ module VagrantPlugins
env[:ui].info 'Configuring cache buckets...' env[:ui].info 'Configuring cache buckets...'
cache_config = env[:machine].config.cache cache_config = env[:machine].config.cache
cache_config.buckets.each do |bucket_name, configs| cache_config.buckets.each do |bucket_name, configs|
next if configs[:disabled]
@logger.info "Installing #{bucket_name} with configs #{configs.inspect}" @logger.info "Installing #{bucket_name} with configs #{configs.inspect}"
Bucket.install(bucket_name, env, configs) Bucket.install(bucket_name, env, configs)
end end

View file

@ -9,6 +9,10 @@ module VagrantPlugins
def self.auto_detect(env) def self.auto_detect(env)
@buckets.each do |bucket| @buckets.each do |bucket|
if bucket.respond_to?(:capability) && env[:machine].guest.capability?(bucket.capability) if bucket.respond_to?(:capability) && env[:machine].guest.capability?(bucket.capability)
if env[:machine].config.cache.buckets.fetch(bucket.bucket_name, {})[:disabled]
env[:machine].ui.warn("Ignoring bucket `#{bucket.bucket_name}` disabled by config")
next
end
env[:machine].config.cache.enable bucket.bucket_name env[:machine].config.cache.enable bucket.bucket_name
end end
end end

View file

@ -11,10 +11,15 @@ module VagrantPlugins
@auto_detect = UNSET_VALUE @auto_detect = UNSET_VALUE
@synced_folder_opts = UNSET_VALUE @synced_folder_opts = UNSET_VALUE
@ui = Vagrant::UI::Colored.new @ui = Vagrant::UI::Colored.new
@buckets = {}
end end
def enable(bucket, opts = {}) def enable(bucket, opts = {})
(@buckets ||= {})[bucket] = opts bucket_set(bucket.to_s, opts)
end
def disable=(bucket)
bucket_set(bucket.to_s, {:disabled => true})
end end
def validate(machine) def validate(machine)
@ -32,6 +37,10 @@ module VagrantPlugins
cache_scope: @scope) cache_scope: @scope)
end end
if !@auto_detect && @buckets.values.each.any? { |x| x[:disabled] }
errors << I18n.t('vagrant_cachier.disable_requires_auto')
end
{ "vagrant cachier" => errors } { "vagrant cachier" => errors }
end end
@ -50,7 +59,6 @@ module VagrantPlugins
@auto_detect = true if @auto_detect == UNSET_VALUE @auto_detect = true if @auto_detect == UNSET_VALUE
@synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
@buckets = @buckets ? @buckets.dup : {}
end end
private private
@ -58,6 +66,10 @@ module VagrantPlugins
def backed_by_cloud_provider?(machine) def backed_by_cloud_provider?(machine)
CLOUD_PROVIDERS.include?(machine.provider_name.to_s) CLOUD_PROVIDERS.include?(machine.provider_name.to_s)
end end
def bucket_set(bucket, opts = {})
@buckets[bucket] = opts
end
end end
end end
end end

View file

@ -6,6 +6,9 @@ en:
Skipping %{bucket} cache bucket as the guest machine does not support it Skipping %{bucket} cache bucket as the guest machine does not support it
unknown_cache_scope: |- unknown_cache_scope: |-
Unknown cache scope '%{cache_scope}' (allowed scopes: %{allowed}) Unknown cache scope '%{cache_scope}' (allowed scopes: %{allowed})
disable_requires_auto: |-
`config.cache.disable <bucket>` only works if `config.cache.auto_detect`
is set to 'true'.
nfs_required: |- nfs_required: |-
The '%{bucket}' cache bucket requires NFS to be enabled, please add The '%{bucket}' cache bucket requires NFS to be enabled, please add
`config.cache.synced_folder_opts = {type: :nfs}` to your Vagrantfile. `config.cache.synced_folder_opts = {type: :nfs}` to your Vagrantfile.

View file

@ -0,0 +1,15 @@
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |_, override|
override.vm.box = "chef/ubuntu-14.04"
end
config.vm.provider :lxc do |_, override|
override.vm.box = "fgrehm/trusty64-lxc"
end
config.cache.auto_detect = true
config.cache.disable = :apt
config.cache.scope = :machine
config.vm.provision :shell, inline: 'apt-get update && apt-get install -y git'
end

View file

@ -43,3 +43,19 @@ load test_helper
empty_cache empty_cache
} }
@test "APT cache bucket disabled skips the cache dir properly" {
configure_env "auto-detect-disable-apt.rb"
test ! -d tmp/.vagrant/machines/default/cache/apt
vagrant_up
[ "$status" -eq 0 ]
# Make sure cache dir does not exist
test ! -d tmp/.vagrant/machines/default/cache/apt
vagrant_destroy
empty_cache
}