commit
d6066fbde7
5 changed files with 86 additions and 3 deletions
28
README.md
28
README.md
|
@ -208,6 +208,34 @@ folder under the result of running `rvm info` as the default SSH user (usualy
|
||||||
it is already installed before enabling the bucket, otherwise you won't benefit
|
it is already installed before enabling the bucket, otherwise you won't benefit
|
||||||
from this plugin.
|
from this plugin.
|
||||||
|
|
||||||
|
|
||||||
|
##### APT-CACHER
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = 'some-debian-box'
|
||||||
|
config.cache.enable :apt_cacher
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
This is useful, if you are using containers inside your VMs, e.g VirtualBox -> LXC. This would allow you to reuse packages without sharing folder inside VirtualBox. Only works with NFS-shared folders (since `vboxsf` is enforcing `vagrant`-user and `apt-cacher` is running under `apt-cacher-ng` user)
|
||||||
|
|
||||||
|
# install apt-cacher on (Host)-VM
|
||||||
|
$ sudo apt-get install apt-cacher-ng
|
||||||
|
|
||||||
|
# get the IP for eth0 interface
|
||||||
|
$ ifconfig eth0 |grep "inet addr"|awk '{print $2}' |cut -c6-20
|
||||||
|
|
||||||
|
# configure mirror on for your docker/LXC instances:
|
||||||
|
$ echo 'Acquire::http { Proxy "http://X.X.X.X:3142"; };' > /etc/apt/apt.conf.d/10mirror
|
||||||
|
|
||||||
|
# check, if working by tailing log on (Host)-VM, while installing packages on (Guest)-VMs
|
||||||
|
$ tail -f /var/log/apt-cacher-ng/apt-cacher.log
|
||||||
|
|
||||||
|
|
||||||
|
Used by Debian-like Linux distros, will get configured under guest's `/var/cache/apt-cacher-ng`.
|
||||||
|
|
||||||
|
|
||||||
## Finding out disk space used by buckets
|
## Finding out disk space used by buckets
|
||||||
|
|
||||||
_TODO_
|
_TODO_
|
||||||
|
|
|
@ -15,12 +15,12 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.bucket_name
|
def self.bucket_name
|
||||||
# TODO: Handle MultiWord bucket classes
|
class_name = self.name.split('::').last
|
||||||
self.name.split('::').last.downcase
|
class_name.scan(/[A-Z][a-z]*/).map{|x| x.downcase}.join("_")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.install(name, env, configs)
|
def self.install(name, env, configs)
|
||||||
bucket = const_get(name.to_s.capitalize)
|
bucket = const_get(name.to_s.split("_").map{|x| x.capitalize}.join(""))
|
||||||
bucket.new(name, env, configs).install
|
bucket.new(name, env, configs).install
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,3 +39,4 @@ require_relative "bucket/gem"
|
||||||
require_relative "bucket/pacman"
|
require_relative "bucket/pacman"
|
||||||
require_relative "bucket/yum"
|
require_relative "bucket/yum"
|
||||||
require_relative "bucket/rvm"
|
require_relative "bucket/rvm"
|
||||||
|
require_relative "bucket/apt_cacher"
|
||||||
|
|
35
lib/vagrant-cachier/bucket/apt_cacher.rb
Normal file
35
lib/vagrant-cachier/bucket/apt_cacher.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Apt-Cacher NG is a caching proxy for software packages which are downloaded by Unix/Linux system distribution mechanisms from mirror servers accessible via HTTP.
|
||||||
|
module VagrantPlugins
|
||||||
|
module Cachier
|
||||||
|
class Bucket
|
||||||
|
class AptCacher < Bucket
|
||||||
|
def self.capability
|
||||||
|
:apt_cacher_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
machine = @env[:machine]
|
||||||
|
guest = machine.guest
|
||||||
|
|
||||||
|
if guest.capability?(:apt_cacher_dir)
|
||||||
|
guest_path = guest.capability(:apt_cacher_dir)
|
||||||
|
|
||||||
|
@env[:cache_dirs] << guest_path
|
||||||
|
|
||||||
|
machine.communicate.tap do |comm|
|
||||||
|
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
|
||||||
|
# TODO: Raise a better error
|
||||||
|
raise "You've configured an APT-CACHER cache for a guest machine that does not support it!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
14
lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb
Normal file
14
lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module Cachier
|
||||||
|
module Cap
|
||||||
|
module Debian
|
||||||
|
module AptCacherDir
|
||||||
|
def self.apt_cacher_dir(machine)
|
||||||
|
# cat /etc/apt-cacher-ng/acng.conf |grep CacheDir
|
||||||
|
'/var/cache/apt-cacher-ng'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -36,6 +36,11 @@ module VagrantPlugins
|
||||||
Cap::Debian::AptCacheDir
|
Cap::Debian::AptCacheDir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability 'debian', 'apt_cacher_dir' do
|
||||||
|
require_relative 'cap/debian/apt_cacher_dir'
|
||||||
|
Cap::Debian::AptCacherDir
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability 'redhat', 'yum_cache_dir' do
|
guest_capability 'redhat', 'yum_cache_dir' do
|
||||||
require_relative 'cap/redhat/yum_cache_dir'
|
require_relative 'cap/redhat/yum_cache_dir'
|
||||||
Cap::RedHat::YumCacheDir
|
Cap::RedHat::YumCacheDir
|
||||||
|
|
Loading…
Reference in a new issue