Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c5a43ed
Showing
11 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Andrew Vit | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Vagrant apt-cache | ||
|
||
Share a common package cache among all VM instances. This gem will share a directory from the host to the `/var/cache/apt` on guest VMs to avoid downloading already-downloaded packages when building VMs. | ||
|
||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'vagrant-apt_cache' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install vagrant-apt_cache | ||
|
||
## Usage | ||
|
||
No configuration is currently provided. This gem is autoloaded by Vagrant. | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'vagrant-apt_cache/version' | ||
require 'vagrant-apt_cache/register_shared_folder' | ||
require 'vagrant-apt_cache/middleware' | ||
|
||
Vagrant.actions[:start].insert_before( | ||
Vagrant::Action::VM::ShareFolders, Vagrant::AptCache::Middleware | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Vagrant | ||
module AptCache | ||
|
||
class Middleware | ||
def initialize(app, env, options={}) | ||
@app = app | ||
@env = env | ||
@options = options | ||
end | ||
|
||
def call(env) | ||
@env = env | ||
|
||
if is_apt_managed? | ||
Vagrant::AptCache::RegisterSharedFolder.new(@env[:vm]).run | ||
end | ||
|
||
@app.call(env) | ||
end | ||
|
||
private | ||
|
||
def guest | ||
@env[:vm].guest | ||
end | ||
|
||
def is_apt_managed? | ||
[ | ||
Vagrant::Guest::Debian, | ||
Vagrant::Guest::Ubuntu | ||
].any? { |deb_distro| guest.is_a? deb_distro } | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Vagrant | ||
module AptCache | ||
|
||
class RegisterSharedFolder | ||
def initialize(vm, options={}) | ||
@vm = vm | ||
@options = options | ||
end | ||
|
||
def run | ||
config_vm.share_folder("v-apt-cache", | ||
guest_apt_cache_dir, host_apt_cache_dir) | ||
end | ||
|
||
private | ||
|
||
def config_vm | ||
@vm.config.vm | ||
end | ||
|
||
def guest_apt_cache_dir | ||
"/var/cache/apt/archives" | ||
end | ||
|
||
def host_apt_cache_dir | ||
prefix = File.expand_path(Vagrant::Environment::DEFAULT_HOME) | ||
cache_dir = File.join(prefix, 'cache', 'apt', @vm.box.name) | ||
partial_dir = File.join(cache_dir, 'partial') | ||
FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir | ||
cache_dir | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Vagrant | ||
module AptCache | ||
VERSION = "0.0.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'vagrant-apt_cache' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/vagrant-apt_cache/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Andrew Vit"] | ||
gem.email = ["andrew@avit.ca"] | ||
gem.description = <<-DESC | ||
Shares the /var/cache/apt/ folder for Ubuntu/Debian instances by storing | ||
already-downloaded packages on the host. | ||
DESC | ||
gem.summary = %q{Share apt-cache among vagrant VMs of the same box type} | ||
gem.homepage = "http://github.com/avit/vagrant-apt_cache" | ||
|
||
gem.files = `git ls-files`.split($\) | ||
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.name = "vagrant-apt_cache" | ||
gem.require_paths = ["lib"] | ||
gem.version = Vagrant::AptCache::VERSION | ||
end |