Created
September 28, 2012 00:38
-
-
Save juanje/3797297 to your computer and use it in GitHub Desktop.
Revisions
-
juanje revised this gist
Sep 30, 2012 . 1 changed file with 4 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,10 @@ This is a little trick I use to spin up the packages instalation on **Debian/Ubu I add a simple function that checks if a directory named something similar to `~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial` (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist. ```ruby def local_cache(basebox_name) cache_dir = Vagrant::Environment.new.home_path.join('cache', 'apt', basebox_name) partial_dir = cache_dir.join('partial') partial_dir.mkdir unless partial_dir.exist? cache_dir end ``` -
juanje created this gist
Sep 28, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ This is a little trick I use to spin up the packages instalation on **Debian/Ubuntu boxes** in **Vagrant**. I add a simple function that checks if a directory named something similar to `~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial` (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist. ```ruby def local_cache(box_name) cache_dir = File.join(File.expand_path(Vagrant::Environment::DEFAULT_HOME), 'cache', 'apt', box_name) partial_dir = File.join(cache_dir, 'partial') FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir cache_dir end ``` I put this funcion in my `Vagrantfile` so I can use it like this: ```ruby Vagrant::Config.run do |config| config.vm.box = "opscode-ubuntu-12.04" config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box" cache_dir = local_cache(config.vm.box) config.vm.share_folder "v-cache", "/var/cache/apt/archives/", cache_dir end ``` The result is that the *apt cache* inside the VM (`/var/cache/apt/archives/`) is always mounted on the same directory on the host (`~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/` in this case) and *apt* just download the packages the first time or if the package has been updated. This save me a lot of time while I'm developing or debuging Chef cookbooks. Mostly when my recipes need to install many packages.