Skip to content

Commit

Permalink
Merge pull request #269 from test-kitchen/the-prodigal-cachier
Browse files Browse the repository at this point in the history
Fix #186 (mostly) and make it easy to use vagrant-cachier
  • Loading branch information
Seth Thomas authored Jan 5, 2017
2 parents af42406 + 984fda8 commit be4a245
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ Many host wide defaults for Vagrant can be set using `$HOME/.vagrant.d/Vagrantfi

## <a name="config"></a> Configuration

### <a name="config-cachier"></a> cachier

Enable and configure scope for [vagrant-cachier][vagrant_cachier] plugin.
Valid options are `:box` or `:machine`, setting to a truthy value yields `:box`

For example:

```yaml
---
driver:
cachier: true
```

will generate a Vagrantfile configuration similar to:

```ruby
config.cache.scope = :box
```

The default is `nil`, indicating unset.


### <a name="config-box"></a> box

**Required** This determines which Vagrant box will be used. For more
Expand Down Expand Up @@ -536,3 +558,4 @@ Apache 2.0 (see [LICENSE][license])
[atlas]: https://atlas.hashicorp.com/
[parallels_dl]: http://www.parallels.com/products/desktop/download/
[vagrant_parallels]: https://github.com/Parallels/vagrant-parallels
[vagrant_cachier]: https://github.com/fgrehm/vagrant-cachier
2 changes: 2 additions & 0 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Vagrant < Kitchen::Driver::Base
driver.windows_os? ? "/omnibus/cache" : "/tmp/omnibus/cache"
end

default_config :cachier, nil

no_parallel_for :create, :destroy

# Creates a Vagrant VM instance.
Expand Down
21 changes: 21 additions & 0 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,27 @@ def run_command(_cmd, options = {})
))
end

it "sets no cache.scope if missing" do
config[:cachier] = nil
cmd

expect(vagrantfile).to_not match(regexify(%{c.cache.scope}, :partial))
end

it "sets cache.scope to :box if :cachier is set" do
config[:cachier] = true
cmd

expect(vagrantfile).to match(regexify(%{c.cache.scope = :box}))
end

it "sets cache.scope if :cachier is set to a custom value" do
config[:cachier] = ":machine"
cmd

expect(vagrantfile).to match(regexify(%{c.cache.scope = :machine}))
end

it "sets the vm.box" do
cmd

Expand Down
6 changes: 6 additions & 0 deletions templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ require "<%= vagrantfile %>"

Vagrant.configure("2") do |c|
c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
<% if config[:cachier] %>
if Vagrant.has_plugin?("vagrant-cachier")
c.cache.scope = <%= [':box', ':machine'].include?(config[:cachier]) ? config[:cachier] : ':box' %>
end
<% end %>

c.vm.box = "<%= config[:box] %>"

<% if config[:box_url] %>
Expand Down

0 comments on commit be4a245

Please sign in to comment.