vagrant-cachier 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +22 -0
- data/README.md +203 -0
- data/Rakefile +5 -0
- data/development/Vagrantfile +52 -0
- data/lib/vagrant-cachier.rb +4 -0
- data/lib/vagrant-cachier/action.rb +89 -0
- data/lib/vagrant-cachier/bucket.rb +39 -0
- data/lib/vagrant-cachier/bucket/apt.rb +34 -0
- data/lib/vagrant-cachier/bucket/gem.rb +39 -0
- data/lib/vagrant-cachier/bucket/pacman.rb +34 -0
- data/lib/vagrant-cachier/bucket/yum.rb +37 -0
- data/lib/vagrant-cachier/cap/arch/pacman_cache_dir.rb +14 -0
- data/lib/vagrant-cachier/cap/debian/apt_cache_dir.rb +14 -0
- data/lib/vagrant-cachier/cap/linux/gemdir.rb +20 -0
- data/lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb +14 -0
- data/lib/vagrant-cachier/config.rb +30 -0
- data/lib/vagrant-cachier/plugin.rb +46 -0
- data/lib/vagrant-cachier/version.rb +5 -0
- data/vagrant-cachier.gemspec +20 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df8fb55ad9b787ce99c4543993b6d7cdb03a3412
|
4
|
+
data.tar.gz: 0a41b1a5c5ceef8c08d4a04223ccc7756f5d6d48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cc837c37d634312062dd8926161e32b30fb015f868c284a7563aea58a55b98428056192d74f815a7df587bb8d67b5d080197eea7466f7407a2259ea448f1ba1
|
7
|
+
data.tar.gz: b0c8281f23510fc9ee19883f448a79840795aa46a43b8e968307ff76df4a3dfadac5173c5da8f21dee700159aceb6c60eaffb4783d0f954e0d870c3ec9a18ae3
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# 0.0.2 Initial release
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/fgrehm/vagrant-lxc.git
|
3
|
+
revision: 2f88a060c911c466d304768dd349708336f8af1c
|
4
|
+
specs:
|
5
|
+
vagrant-lxc (0.3.4)
|
6
|
+
|
7
|
+
GIT
|
8
|
+
remote: git://github.com/mitchellh/vagrant.git
|
9
|
+
revision: ccfd321ef98dc5c12b180cc3a26f12d870c0eff5
|
10
|
+
specs:
|
11
|
+
vagrant (1.2.3.dev)
|
12
|
+
childprocess (~> 0.3.7)
|
13
|
+
erubis (~> 2.7.0)
|
14
|
+
i18n (~> 0.6.0)
|
15
|
+
json (>= 1.5.1, < 1.8.0)
|
16
|
+
log4r (~> 1.1.9)
|
17
|
+
net-scp (~> 1.1.0)
|
18
|
+
net-ssh (~> 2.6.6)
|
19
|
+
|
20
|
+
PATH
|
21
|
+
remote: .
|
22
|
+
specs:
|
23
|
+
vagrant-cachier (0.0.6)
|
24
|
+
|
25
|
+
GEM
|
26
|
+
remote: https://rubygems.org/
|
27
|
+
specs:
|
28
|
+
childprocess (0.3.9)
|
29
|
+
ffi (~> 1.0, >= 1.0.11)
|
30
|
+
erubis (2.7.0)
|
31
|
+
ffi (1.8.1)
|
32
|
+
i18n (0.6.4)
|
33
|
+
json (1.7.7)
|
34
|
+
log4r (1.1.10)
|
35
|
+
net-scp (1.1.0)
|
36
|
+
net-ssh (>= 2.6.5)
|
37
|
+
net-ssh (2.6.7)
|
38
|
+
rake (10.0.4)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
rake
|
45
|
+
vagrant!
|
46
|
+
vagrant-cachier!
|
47
|
+
vagrant-lxc!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Fabio Rehm
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
# vagrant-cachier
|
2
|
+
|
3
|
+
A [Vagrant](http://www.vagrantup.com/) plugin that helps you reduce the amount of
|
4
|
+
coffee you drink while waiting for boxes to be provisioned by sharing a common
|
5
|
+
package cache among similiar VM instances. Kinda like [vagrant-apt_cache](https://github.com/avit/vagrant-apt_cache)
|
6
|
+
or [this magical snippet](http://gist.github.com/juanje/3797297) but targetting
|
7
|
+
multiple package managers and Linux distros.
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Make sure you have Vagrant 1.2+ and run:
|
13
|
+
|
14
|
+
```
|
15
|
+
vagrant plugin install vagrant-cachier
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
The easiest way to set things up is just to enable [cache buckets auto detection](#auto-detect-supported-cache-buckets)
|
21
|
+
from within your `Vagrantfile`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Vagrant.configure("2") do |config|
|
25
|
+
config.vm.box = 'your-box'
|
26
|
+
config.cache.auto_detect = true
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
For more information about available buckets, please see the [configuration section](#configurations) below.
|
31
|
+
|
32
|
+
|
33
|
+
## Compatible providers
|
34
|
+
|
35
|
+
* Vagrant's built in VirtualBox provider
|
36
|
+
* [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc)
|
37
|
+
|
38
|
+
_It is possibly compatible with the [VMware providers](http://www.vagrantup.com/vmware)
|
39
|
+
as well but I haven't tried yet._
|
40
|
+
|
41
|
+
|
42
|
+
## How does it work?
|
43
|
+
|
44
|
+
Right now the plugin does not make any assumptions for you and you have to
|
45
|
+
configure things properly from your `Vagrantfile`. Please have a look at
|
46
|
+
the [available cache buckets](#available-cache-buckets) section below for more
|
47
|
+
information.
|
48
|
+
|
49
|
+
Under the hood, the plugin will hook into calls to `Vagrant::Builtin::Provision`
|
50
|
+
during `vagrant up` / `vagrant reload` and will set things up for each configured
|
51
|
+
cache bucket. Before halting the machine, it will revert the changes required
|
52
|
+
to set things up by hooking into calls to `Vagrant::Builtin::GracefulHalt` so
|
53
|
+
that you can repackage the machine for others to use without requiring users to
|
54
|
+
install the plugin as well.
|
55
|
+
|
56
|
+
Cache buckets will be available from `/tmp/vagrant-cachier` on your guest and
|
57
|
+
the appropriate folders will get symlinked to the right path _after_ the machine is
|
58
|
+
up but _right before_ it gets provisioned. We _could_ potentially do it on one go
|
59
|
+
and share bucket's folders directly to the right path if we were only using VirtualBox
|
60
|
+
since it shares folders _after_ booting the machine, but the LXC provider does that
|
61
|
+
_as part of_ the boot process (shared folders are actually `lxc-start` parameters)
|
62
|
+
and as of now we are not able to get some information that this plugin requires
|
63
|
+
about the guest machine before it is actually up and running.
|
64
|
+
|
65
|
+
Please keep in mind that this plugin won't do magic, if you are compiling things
|
66
|
+
during provisioning or manually downloading packages that does not fit into a
|
67
|
+
"cache bucket" you won't see that much of improvement.
|
68
|
+
|
69
|
+
|
70
|
+
## Configurations
|
71
|
+
|
72
|
+
### Auto detect supported cache buckets
|
73
|
+
|
74
|
+
As described on the usage section above, you can enable automatic detection of
|
75
|
+
supported [cache "buckets"](#available-cache-buckets) by adding the code below to
|
76
|
+
your `Vagrantfile`:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Vagrant.configure("2") do |config|
|
80
|
+
# ...
|
81
|
+
config.cache.auto_detect = true
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
This will make vagrant-cachier do its best to find out what is supported on the
|
86
|
+
guest machine and will set buckets accordingly.
|
87
|
+
|
88
|
+
### Cache scope
|
89
|
+
|
90
|
+
By default downloaded packages will get stored on a folder scoped to base boxes
|
91
|
+
under your `$HOME/.vagrant.d/cache`. The idea is to leverage the cache by allowing
|
92
|
+
downloaded packages to be reused across projects. So, if your `Vagrantfile` has
|
93
|
+
something like:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Vagrant.configure("2") do |config|
|
97
|
+
config.vm.box = 'some-box'
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
The cached files will be stored under `$HOME/.vagrant.d/cache/some-box`.
|
102
|
+
|
103
|
+
If you are on a [multi VM environment](http://docs.vagrantup.com/v2/multi-machine/index.html),
|
104
|
+
there is a huge chance that you'll end up having issues by sharing the same bucket
|
105
|
+
across different machines. For example, if you `apt-get install` from two machines
|
106
|
+
at "almost the same time" you are probably going to hit a `SystemError: Failed to lock /var/cache/apt/archives/lock`.
|
107
|
+
To work around that, you can set the scope to be based on machines:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Vagrant.configure("2") do |config|
|
111
|
+
config.vm.box = 'some-box'
|
112
|
+
config.cache.scope = :machine
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
This will tell vagrant-cachier to download packages to `.vagrant/machines/<machine-name>/<provider-name>/cache`
|
117
|
+
on your current project directory.
|
118
|
+
|
119
|
+
|
120
|
+
### Available cache "buckets"
|
121
|
+
|
122
|
+
#### System package managers
|
123
|
+
|
124
|
+
##### APT
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
Vagrant.configure("2") do |config|
|
128
|
+
config.vm.box = 'some-debian-box'
|
129
|
+
config.cache.enable :apt
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
Used by Debian-like Linux distros, will get configured under guest's `/var/cache/apt/archives`.
|
134
|
+
|
135
|
+
_Please note that to avoid re-downloading packages, you should avoid `apt-get clean`
|
136
|
+
as much as possible in order to make a better use of the cache, even if you are
|
137
|
+
packaging a box_
|
138
|
+
|
139
|
+
##### Yum
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
Vagrant.configure("2") do |config|
|
143
|
+
config.vm.box = 'some-centos-box'
|
144
|
+
config.cache.enable :yum
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
Used by CentOS guests, will get configured under guest's `/var/cache/yum`. It will
|
149
|
+
also [make sure](lib/vagrant-cachier/bucket/yum.rb#L20) that `keepcache` is set to
|
150
|
+
`1` on guest's `/etc/yum.conf`.
|
151
|
+
|
152
|
+
##### Pacman
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
Vagrant.configure("2") do |config|
|
156
|
+
config.vm.box = 'some-arch-linux-box'
|
157
|
+
config.cache.enable :pacman
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
Used by Arch Linux, will get configured under guest's `/var/cache/pacman/pkg`.
|
162
|
+
|
163
|
+
#### RubyGems
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
Vagrant.configure("2") do |config|
|
167
|
+
config.vm.box = 'some-box-with-ruby-installed'
|
168
|
+
config.cache.enable :gem
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
Compatible with probably with any type of guest distro, will hook into the `cache`
|
173
|
+
folder under the result of running `gem env gemdir` as the default SSH user (usualy
|
174
|
+
`vagrant`) on your guest. If you use rbenv / rvm on the guest machine, make sure
|
175
|
+
it is already installed before enabling the bucket, otherwise you won't benefit
|
176
|
+
from this plugin.
|
177
|
+
|
178
|
+
|
179
|
+
## Finding out disk space used by buckets
|
180
|
+
|
181
|
+
_TODO_
|
182
|
+
|
183
|
+
```shell
|
184
|
+
$ vagrant cache stats
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
## Cleaning up cache buckets
|
189
|
+
|
190
|
+
_TODO_
|
191
|
+
|
192
|
+
```shell
|
193
|
+
$ vagrant cache clean apt
|
194
|
+
```
|
195
|
+
|
196
|
+
|
197
|
+
## Contributing
|
198
|
+
|
199
|
+
1. Fork it
|
200
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
201
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
202
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
203
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.require_plugin 'vagrant-cachier'
|
5
|
+
Vagrant.require_plugin 'vagrant-lxc'
|
6
|
+
|
7
|
+
Vagrant.configure("2") do |config|
|
8
|
+
config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root'#, nfs: true
|
9
|
+
|
10
|
+
config.cache.scope = :machine
|
11
|
+
config.cache.auto_detect = true
|
12
|
+
|
13
|
+
debian_like_configs = lambda do |debian|
|
14
|
+
debian.vm.provision :shell, inline: '
|
15
|
+
if ! (which bundle > /dev/null); then
|
16
|
+
sudo gem install bundler --no-ri --no-rdoc
|
17
|
+
sudo apt-get install -y build-essential libffi-dev ruby1.9.1-dev git
|
18
|
+
cd /vagrant && bundle
|
19
|
+
fi'
|
20
|
+
end
|
21
|
+
|
22
|
+
config.vm.define :ubuntu do |ubuntu|
|
23
|
+
ubuntu.vm.box = "quantal64"
|
24
|
+
debian_like_configs.call ubuntu
|
25
|
+
end
|
26
|
+
|
27
|
+
config.vm.define :debian do |debian|
|
28
|
+
debian.vm.box = "squeeze64"
|
29
|
+
debian.vm.box_url = 'http://f.willianfernandes.com.br/vagrant-boxes/DebianSqueeze64.box'
|
30
|
+
debian_like_configs.call debian
|
31
|
+
end
|
32
|
+
|
33
|
+
config.vm.define :centos do |centos|
|
34
|
+
centos.vm.box = 'centos6_64'
|
35
|
+
centos.vm.box_url = 'http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130309.box'
|
36
|
+
centos.vm.provision :shell, inline: '
|
37
|
+
if ! (which bundle > /dev/null); then
|
38
|
+
time sudo gem install bundler --no-ri --no-rdoc
|
39
|
+
time sudo yum install -y libffi-devel ruby-devel git
|
40
|
+
fi'
|
41
|
+
end
|
42
|
+
|
43
|
+
config.vm.define :arch do |arch|
|
44
|
+
arch.vm.box = 'arch64'
|
45
|
+
arch.vm.box_url = 'http://vagrant.pouss.in/archlinux_2012-07-02.box'
|
46
|
+
arch.vm.provision :shell, inline: '
|
47
|
+
if ! (which bundle > /dev/null); then
|
48
|
+
time sudo gem install bundler --no-ri --no-rdoc
|
49
|
+
time sudo pacman -Syu --noconfirm libffi git
|
50
|
+
fi'
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'bucket'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Cachier
|
5
|
+
class Action
|
6
|
+
class Install
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant::cachier::action::install")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
return @app.call(env) unless env[:machine].config.cache.enabled?
|
14
|
+
|
15
|
+
@env = env
|
16
|
+
|
17
|
+
FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
|
18
|
+
|
19
|
+
env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache"
|
20
|
+
|
21
|
+
@app.call env
|
22
|
+
|
23
|
+
env[:cache_dirs] = []
|
24
|
+
|
25
|
+
if env[:machine].config.cache.auto_detect
|
26
|
+
Bucket.auto_detect(env)
|
27
|
+
end
|
28
|
+
|
29
|
+
if env[:machine].config.cache.buckets.any?
|
30
|
+
env[:ui].info 'Configuring cache buckets...'
|
31
|
+
cache_config = env[:machine].config.cache
|
32
|
+
cache_config.buckets.each do |bucket_name, configs|
|
33
|
+
@logger.debug "Installing #{bucket_name} with configs #{configs.inspect}"
|
34
|
+
Bucket.install(bucket_name, env, configs)
|
35
|
+
end
|
36
|
+
|
37
|
+
data_file = env[:machine].data_dir.join('cache_dirs')
|
38
|
+
data_file.open('w') { |f| f.print env[:cache_dirs].join("\n") }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def cache_root
|
43
|
+
@cache_root ||= case @env[:machine].config.cache.scope
|
44
|
+
when :box
|
45
|
+
@env[:home_path].join('cache', @env[:machine].box.name)
|
46
|
+
when :machine
|
47
|
+
@env[:machine].data_dir.join('cache')
|
48
|
+
else
|
49
|
+
raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Clean
|
55
|
+
def initialize(app, env)
|
56
|
+
@app = app
|
57
|
+
@logger = Log4r::Logger.new("vagrant::cachier::action::clean")
|
58
|
+
end
|
59
|
+
|
60
|
+
def call(env)
|
61
|
+
@env = env
|
62
|
+
|
63
|
+
if env[:machine].state.id == :running && symlinks.any?
|
64
|
+
env[:ui].info 'Removing cache buckets symlinks...'
|
65
|
+
symlinks.each do |symlink|
|
66
|
+
remove_symlink symlink
|
67
|
+
end
|
68
|
+
|
69
|
+
File.delete env[:machine].data_dir.join('cache_dirs').to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
@app.call env
|
73
|
+
end
|
74
|
+
|
75
|
+
def symlinks
|
76
|
+
# TODO: Check if file exists instead of a blank rescue
|
77
|
+
@symlinks ||= @env[:machine].data_dir.join('cache_dirs').read.split rescue []
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_symlink(symlink)
|
81
|
+
if @env[:machine].communicate.test("test -L #{symlink}")
|
82
|
+
@logger.debug "Removing symlink for '#{symlink}'"
|
83
|
+
@env[:machine].communicate.sudo("unlink #{symlink}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Bucket
|
4
|
+
def self.inherited(base)
|
5
|
+
@buckets ||= []
|
6
|
+
@buckets << base
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.auto_detect(env)
|
10
|
+
@buckets.each do |bucket|
|
11
|
+
if env[:machine].guest.capability?(bucket.capability)
|
12
|
+
env[:machine].config.cache.enable bucket.bucket_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.bucket_name
|
18
|
+
# TODO: Handle MultiWord bucket classes
|
19
|
+
self.name.split('::').last.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.install(name, env, configs)
|
23
|
+
bucket = const_get(name.to_s.capitalize)
|
24
|
+
bucket.new(name, env, configs).install
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(name, env, configs)
|
28
|
+
@name = name
|
29
|
+
@env = env
|
30
|
+
@configs = configs
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require_relative "bucket/apt"
|
37
|
+
require_relative "bucket/gem"
|
38
|
+
require_relative "bucket/pacman"
|
39
|
+
require_relative "bucket/yum"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Bucket
|
4
|
+
class Apt < Bucket
|
5
|
+
def self.capability
|
6
|
+
:apt_cache_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def install
|
10
|
+
machine = @env[:machine]
|
11
|
+
guest = machine.guest
|
12
|
+
|
13
|
+
if guest.capability?(:apt_cache_dir)
|
14
|
+
guest_path = guest.capability(:apt_cache_dir)
|
15
|
+
|
16
|
+
@env[:cache_dirs] << guest_path
|
17
|
+
|
18
|
+
machine.communicate.tap do |comm|
|
19
|
+
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
20
|
+
unless comm.test("test -L #{guest_path}")
|
21
|
+
comm.sudo("rm -rf #{guest_path}")
|
22
|
+
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
23
|
+
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
# TODO: Raise a better error
|
28
|
+
raise "You've configured an APT cache for a guest machine that does not support it!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Bucket
|
4
|
+
class Gem < Bucket
|
5
|
+
def self.capability
|
6
|
+
:gemdir
|
7
|
+
end
|
8
|
+
|
9
|
+
def install
|
10
|
+
machine = @env[:machine]
|
11
|
+
guest = machine.guest
|
12
|
+
|
13
|
+
if guest.capability?(:gemdir)
|
14
|
+
if gemdir_path = guest.capability(:gemdir)
|
15
|
+
prefix = gemdir_path.split('/').last
|
16
|
+
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
17
|
+
machine.communicate.tap do |comm|
|
18
|
+
comm.execute("mkdir -p #{bucket_path}")
|
19
|
+
|
20
|
+
gem_cache_path = "#{gemdir_path}/cache"
|
21
|
+
|
22
|
+
@env[:cache_dirs] << gem_cache_path
|
23
|
+
|
24
|
+
unless comm.test("test -L #{gem_cache_path}")
|
25
|
+
comm.sudo("rm -rf #{gem_cache_path}")
|
26
|
+
comm.sudo("mkdir -p `dirname #{gem_cache_path}`")
|
27
|
+
comm.sudo("ln -s #{bucket_path} #{gem_cache_path}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
# TODO: Raise a better error
|
33
|
+
raise "You've configured a RubyGems cache for a guest machine that does not support it!"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Bucket
|
4
|
+
class Pacman < Bucket
|
5
|
+
def self.capability
|
6
|
+
:pacman_cache_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def install
|
10
|
+
machine = @env[:machine]
|
11
|
+
guest = machine.guest
|
12
|
+
|
13
|
+
if guest.capability?(:pacman_cache_dir)
|
14
|
+
guest_path = guest.capability(:pacman_cache_dir)
|
15
|
+
|
16
|
+
@env[:cache_dirs] << guest_path
|
17
|
+
|
18
|
+
machine.communicate.tap do |comm|
|
19
|
+
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
20
|
+
unless comm.test("test -L #{guest_path}")
|
21
|
+
comm.sudo("rm -rf #{guest_path}")
|
22
|
+
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
23
|
+
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
# TODO: Raise a better error
|
28
|
+
raise "You've configured a Pacman cache for a guest machine that does not support it!"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Bucket
|
4
|
+
class Yum < Bucket
|
5
|
+
def self.capability
|
6
|
+
:yum_cache_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def install
|
10
|
+
machine = @env[:machine]
|
11
|
+
guest = machine.guest
|
12
|
+
|
13
|
+
if guest.capability?(:yum_cache_dir)
|
14
|
+
guest_path = guest.capability(:yum_cache_dir)
|
15
|
+
|
16
|
+
@env[:cache_dirs] << guest_path
|
17
|
+
|
18
|
+
machine.communicate.tap do |comm|
|
19
|
+
# Ensure caching is enabled
|
20
|
+
comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf")
|
21
|
+
|
22
|
+
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
23
|
+
unless comm.test("test -L #{guest_path}")
|
24
|
+
comm.sudo("rm -rf #{guest_path}")
|
25
|
+
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
26
|
+
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# TODO: Raise a better error
|
31
|
+
raise "You've configured a Yum cache for a guest machine that does not support it!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
module Cap
|
4
|
+
module Linux
|
5
|
+
module Gemdir
|
6
|
+
def self.gemdir(machine)
|
7
|
+
gemdir = nil
|
8
|
+
machine.communicate.tap do |comm|
|
9
|
+
return unless comm.test('which gem')
|
10
|
+
comm.execute 'gem env gemdir' do |buffer, output|
|
11
|
+
gemdir = output.chomp if buffer == :stdout
|
12
|
+
end
|
13
|
+
end
|
14
|
+
return gemdir
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Config < Vagrant.plugin(2, :config)
|
4
|
+
attr_accessor :scope, :auto_detect
|
5
|
+
attr_reader :buckets
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@scope = UNSET_VALUE
|
9
|
+
@auto_detect = UNSET_VALUE
|
10
|
+
end
|
11
|
+
|
12
|
+
def enable(bucket, opts = {})
|
13
|
+
(@buckets ||= {})[bucket] = opts
|
14
|
+
end
|
15
|
+
|
16
|
+
def finalize!
|
17
|
+
return unless enabled?
|
18
|
+
|
19
|
+
@scope = :box if @scope == UNSET_VALUE
|
20
|
+
@auto_detect = false if @auto_detect == UNSET_VALUE
|
21
|
+
@buckets = @buckets ? @buckets.dup : {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def enabled?
|
25
|
+
@enabled ||= @auto_detect != UNSET_VALUE ||
|
26
|
+
@buckets != nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Cachier
|
3
|
+
class Plugin < Vagrant.plugin('2')
|
4
|
+
name 'vagrant-cachier'
|
5
|
+
|
6
|
+
config 'cache' do
|
7
|
+
require_relative "config"
|
8
|
+
Config
|
9
|
+
end
|
10
|
+
|
11
|
+
guest_capability 'linux', 'gemdir' do
|
12
|
+
require_relative 'cap/linux/gemdir'
|
13
|
+
Cap::Linux::Gemdir
|
14
|
+
end
|
15
|
+
|
16
|
+
guest_capability 'debian', 'apt_cache_dir' do
|
17
|
+
require_relative 'cap/debian/apt_cache_dir'
|
18
|
+
Cap::Debian::AptCacheDir
|
19
|
+
end
|
20
|
+
|
21
|
+
guest_capability 'redhat', 'yum_cache_dir' do
|
22
|
+
require_relative 'cap/redhat/yum_cache_dir'
|
23
|
+
Cap::RedHat::YumCacheDir
|
24
|
+
end
|
25
|
+
|
26
|
+
guest_capability 'arch', 'pacman_cache_dir' do
|
27
|
+
require_relative 'cap/arch/pacman_cache_dir'
|
28
|
+
Cap::Arch::PacmanCacheDir
|
29
|
+
end
|
30
|
+
|
31
|
+
install_action_hook = lambda do |hook|
|
32
|
+
require_relative 'action'
|
33
|
+
hook.after Vagrant::Action::Builtin::Provision, Vagrant::Cachier::Action::Install
|
34
|
+
end
|
35
|
+
action_hook 'set-shared-cache-on-machine-up', :machine_action_up, &install_action_hook
|
36
|
+
action_hook 'set-shared-cache-on-machine-reload', :machine_action_reload, &install_action_hook
|
37
|
+
|
38
|
+
clean_action_hook = lambda do |hook|
|
39
|
+
require_relative 'action'
|
40
|
+
hook.before Vagrant::Action::Builtin::GracefulHalt, Vagrant::Cachier::Action::Clean
|
41
|
+
end
|
42
|
+
action_hook 'remove-guest-symlinks-on-machine-halt', :machine_action_halt, &clean_action_hook
|
43
|
+
action_hook 'remove-guest-symlinks-on-machine-package', :machine_action_package, &clean_action_hook
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-cachier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-cachier"
|
8
|
+
spec.version = Vagrant::Cachier::VERSION
|
9
|
+
spec.authors = ["Fabio Rehm"]
|
10
|
+
spec.email = ["fgrehm@gmail.com"]
|
11
|
+
spec.description = %q{Speed up vagrant boxes provisioning}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/fgrehm/vagrant-cachier"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-cachier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabio Rehm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Speed up vagrant boxes provisioning
|
14
|
+
email:
|
15
|
+
- fgrehm@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- development/Vagrantfile
|
28
|
+
- lib/vagrant-cachier.rb
|
29
|
+
- lib/vagrant-cachier/action.rb
|
30
|
+
- lib/vagrant-cachier/bucket.rb
|
31
|
+
- lib/vagrant-cachier/bucket/apt.rb
|
32
|
+
- lib/vagrant-cachier/bucket/gem.rb
|
33
|
+
- lib/vagrant-cachier/bucket/pacman.rb
|
34
|
+
- lib/vagrant-cachier/bucket/yum.rb
|
35
|
+
- lib/vagrant-cachier/cap/arch/pacman_cache_dir.rb
|
36
|
+
- lib/vagrant-cachier/cap/debian/apt_cache_dir.rb
|
37
|
+
- lib/vagrant-cachier/cap/linux/gemdir.rb
|
38
|
+
- lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb
|
39
|
+
- lib/vagrant-cachier/config.rb
|
40
|
+
- lib/vagrant-cachier/plugin.rb
|
41
|
+
- lib/vagrant-cachier/version.rb
|
42
|
+
- vagrant-cachier.gemspec
|
43
|
+
homepage: https://github.com/fgrehm/vagrant-cachier
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.0.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Speed up vagrant boxes provisioning
|
67
|
+
test_files: []
|