Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit c5a43eda31ecdc5c5830080a0c1f60e692ee9ab4 0 parents
@avit authored
17 .gitignore
@@ -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
2  Gemfile
@@ -0,0 +1,2 @@
+source 'https://rubygems.org'
+gemspec
22 LICENSE
@@ -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.
30 README.md
@@ -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
2  Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
7 lib/vagrant-apt_cache.rb
@@ -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
+)
36 lib/vagrant-apt_cache/middleware.rb
@@ -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
35 lib/vagrant-apt_cache/register_shared_folder.rb
@@ -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
5 lib/vagrant-apt_cache/version.rb
@@ -0,0 +1,5 @@
+module Vagrant
+ module AptCache
+ VERSION = "0.0.1"
+ end
+end
1  lib/vagrant_init.rb
@@ -0,0 +1 @@
+require 'vagrant-apt_cache'
20 vagrant-apt_cache.gemspec
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.