├── .gitignore ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── Vagrantfile ├── lib └── vagrant │ ├── faster.rb │ └── faster │ ├── action.rb │ └── plugin.rb ├── provisioning └── dev.yml └── vagrant-faster.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by http://www.gitignore.io 2 | 3 | ### Linux ### 4 | *~ 5 | 6 | # KDE directory preferences 7 | .directory 8 | 9 | 10 | ### Windows ### 11 | # Windows image file caches 12 | Thumbs.db 13 | ehthumbs.db 14 | 15 | # Folder config file 16 | Desktop.ini 17 | 18 | # Recycle Bin used on file shares 19 | $RECYCLE.BIN/ 20 | 21 | # Windows Installer files 22 | *.cab 23 | *.msi 24 | *.msm 25 | *.msp 26 | 27 | 28 | ### OSX ### 29 | .DS_Store 30 | .AppleDouble 31 | .LSOverride 32 | 33 | # Icon must end with two \r 34 | Icon 35 | 36 | 37 | # Thumbnails 38 | ._* 39 | 40 | # Files that might appear on external disk 41 | .Spotlight-V100 42 | .Trashes 43 | 44 | # Directories potentially created on remote AFP share 45 | .AppleDB 46 | .AppleDesktop 47 | Network Trash Folder 48 | Temporary Items 49 | .apdisk 50 | 51 | 52 | ### vim ### 53 | [._]*.s[a-w][a-z] 54 | [._]s[a-w][a-z] 55 | *.un~ 56 | Session.vim 57 | .netrwhist 58 | *~ 59 | 60 | 61 | ### SublimeText ### 62 | # workspace files are user-specific 63 | *.sublime-workspace 64 | 65 | # project files should be checked into the repository, unless a significant 66 | # proportion of contributors will probably not be using SublimeText 67 | # *.sublime-project 68 | 69 | #sftp configuration file 70 | sftp-config.json 71 | 72 | 73 | ### RubyMine ### 74 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 75 | 76 | ## Directory-based project format 77 | .idea/ 78 | # if you remove the above rule, at least ignore user-specific stuff: 79 | # .idea/workspace.xml 80 | # .idea/tasks.xml 81 | # and these sensitive or high-churn files: 82 | # .idea/dataSources.ids 83 | # .idea/dataSources.xml 84 | # .idea/sqlDataSources.xml 85 | # .idea/dynamic.xml 86 | 87 | ## File-based project format 88 | *.ipr 89 | *.iml 90 | *.iws 91 | 92 | ## Additional for IntelliJ 93 | out/ 94 | 95 | # generated by mpeltonen/sbt-idea plugin 96 | .idea_modules/ 97 | 98 | # generated by JIRA plugin 99 | atlassian-ide-plugin.xml 100 | 101 | # generated by Crashlytics plugin (for Android Studio and Intellij) 102 | com_crashlytics_export_strings.xml 103 | 104 | 105 | ### Vagrant ### 106 | .vagrant/ 107 | 108 | 109 | ### Ruby ### 110 | *.gem 111 | *.rbc 112 | /.config 113 | /coverage/ 114 | /InstalledFiles 115 | /pkg/ 116 | /spec/reports/ 117 | /test/tmp/ 118 | /test/version_tmp/ 119 | /tmp/ 120 | 121 | ## Specific to RubyMotion: 122 | .dat* 123 | .repl_history 124 | build/ 125 | 126 | ## Documentation cache and generated files: 127 | /.yardoc/ 128 | /_yardoc/ 129 | /doc/ 130 | /rdoc/ 131 | 132 | ## Environment normalisation: 133 | /.bundle/ 134 | /lib/bundler/man/ 135 | 136 | # for a library or gem, you might want to ignore these files since the code is 137 | # intended to run in multiple environments; otherwise, check them in: 138 | # Gemfile.lock 139 | # .ruby-version 140 | # .ruby-gemset 141 | 142 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 143 | .rvmrc 144 | 145 | ### 146 | ### Custom ignores 147 | ### 148 | 149 | *.gem 150 | *.rbc 151 | .bundle 152 | .config 153 | .yardoc 154 | Gemfile.lock 155 | InstalledFiles 156 | _yardoc 157 | coverage 158 | doc/ 159 | lib/bundler/man 160 | pkg 161 | rdoc 162 | spec/reports 163 | test/tmp 164 | test/version_tmp 165 | tmp 166 | *.bundle 167 | *.so 168 | *.o 169 | *.a 170 | mkmf.log 171 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: ruby 3 | sudo: false 4 | cache: bundler 5 | deploy: 6 | provider: rubygems 7 | api_key: 8 | secure: bb8ndwqNOqoDJg7oTipEBYpmF9Eg7A7eb5KhP8aG+J1qaaMv+xDksJ4J5ldTZUxsFBeVC9RIAiTHuK7gRElL7bwnRtQzLfDYLSuby2MzNLCu90QKN8ovmcvnytCyRyvL7GiSw0Uc0Q5o/ve040/i6YccUTxw12TJMcWaSHZA95o= 9 | on: 10 | tags: true 11 | notifications: 12 | email: false 13 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in vagrant-faster.gemspec 4 | gemspec 5 | 6 | group :development do 7 | gem "vagrant", git: "https://github.com/mitchellh/vagrant.git" 8 | end 9 | 10 | group :plugins do 11 | gem "vagrant-faster", path: "." 12 | end 13 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 rdsubhas 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. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant::Faster 2 | 3 | [![Gem Version](https://badge.fury.io/rb/vagrant-faster.svg)](https://badge.fury.io/rb/vagrant-faster) 4 | [![Build Status](https://travis-ci.org/rdsubhas/vagrant-faster.svg?branch=master)](https://travis-ci.org/rdsubhas/vagrant-faster) 5 | 6 | Tired of Vagrant VMs running slow? This plugin automatically allocates more Memory/CPU based on your machine's capacity. 7 | 8 | To install: 9 | 10 | vagrant plugin install vagrant-faster 11 | 12 | And that's it. All VMs started from now will be made faster. 13 | 14 | ## How much does it allocate? 15 | 16 | * 1/4th of memory, if you have more than 2GB RAM 17 | * 1/2 of the available CPU cores, if you have more than 1 CPU. 18 | * For machines with less than 2GB RAM or single-CPU, it will simply leave the machine defaults as it is 19 | 20 | **NOTE**: These were rudimentary values I picked based on usage. Please feel free to suggest better. 21 | 22 | ## Known Issues 23 | 24 | * Presently supports only VirtualBox 25 | * No option to disable this for specific VMs for now. 26 | 27 | Please open an issue if you feel any of this are nagging you. 28 | 29 | **Contributions Welcome** 30 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | task :default => :build 4 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | config.vm.box = "ubuntu/trusty64" 9 | 10 | if Vagrant.has_plugin?('vagrant-cachier') 11 | config.cache.scope = :box 12 | else 13 | puts "Run `vagrant plugin install vagrant-cachier` to reduce caffeine intake when provisioning" 14 | end 15 | 16 | config.vm.define "dev", primary: true do |dev| 17 | dev.vm.provision "ansible" do |ansible| 18 | ansible.playbook = 'provisioning/dev.yml' 19 | ansible.verbose = 'vvv' 20 | end 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /lib/vagrant/faster.rb: -------------------------------------------------------------------------------- 1 | require 'vagrant/faster/plugin' 2 | 3 | module Vagrant 4 | module Faster 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/vagrant/faster/action.rb: -------------------------------------------------------------------------------- 1 | module Vagrant 2 | module Faster 3 | class Action 4 | def initialize(app, env) 5 | @app = app 6 | end 7 | 8 | def call(env) 9 | vm = env[:vm] || env[:machine] 10 | 11 | cpus, mem = optimal_settings 12 | if cpus > 0 && mem > 0 13 | env[:ui].warn "[vagrant-faster] Setting CPUs: #{cpus}, Memory: #{mem}" 14 | vm.provider_config.customizations << ["pre-boot", ["modifyvm", :id, "--memory", mem]] 15 | vm.provider_config.customizations << ["pre-boot", ["modifyvm", :id, "--cpus", cpus]] 16 | else 17 | env[:ui].warn "[vagrant-faster] was unable to detect optimal settings for your machine" 18 | end 19 | 20 | @app.call env 21 | end 22 | 23 | def optimal_settings 24 | host = RbConfig::CONFIG['host_os'] 25 | 26 | cpus = -1 27 | mem = -1 28 | 29 | begin 30 | if host =~ /darwin/ 31 | cpus = `sysctl -n hw.ncpu`.to_i 32 | mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 33 | elsif host =~ /linux/ 34 | cpus = `nproc`.to_i 35 | mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 36 | elsif host =~ /mswin|mingw|cygwin/ 37 | cpus = `wmic cpu Get NumberOfCores`.split[1].to_i 38 | mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024 / 1024 39 | end 40 | 41 | # Give VM 1/4 system memory & access to half of cpu cores on the host 42 | cpus = cpus / 2 if cpus > 1 43 | mem = mem / 4 if mem > 2048 44 | rescue; end 45 | 46 | [ cpus, mem ] 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/vagrant/faster/plugin.rb: -------------------------------------------------------------------------------- 1 | module Vagrant 2 | module Faster 3 | class Plugin < Vagrant.plugin('2') 4 | name 'vagrant-faster' 5 | description 'Make VMs faster by allocating more Memory/CPU based on your machine capacity' 6 | 7 | action_hook 'faster', :machine_action_up do |hook| 8 | require_relative './action' 9 | hook.before VagrantPlugins::ProviderVirtualBox::Action::Customize, Vagrant::Faster::Action 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /provisioning/dev.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | gather_facts: yes 4 | sudo: yes 5 | 6 | tasks: 7 | - name: Add Ruby repository 8 | apt_repository: repo='ppa:brightbox/ruby-ng' 9 | 10 | - name: Install packages 11 | apt: name={{ item }} state=present 12 | with_items: 13 | - build-essential 14 | - git 15 | - libxml2-dev 16 | - libxslt1-dev 17 | - zlib1g-dev 18 | - ruby2.2 19 | - ruby2.2-dev 20 | - ruby-switch 21 | - curl 22 | - wget 23 | 24 | - name: Dont install gem docs 25 | lineinfile: "dest=/etc/gemrc line='gem: --no-ri --no-rdoc' create=yes" 26 | 27 | - name: Check bundler 28 | shell: bundle -v 29 | register: bundler_present 30 | ignore_errors: True 31 | 32 | - name: Install bundler 33 | shell: gem install bundler -v '~> 1.7.0' 34 | when: bundler_present|failed 35 | 36 | - name: Install gems 37 | shell: bundle install -j4 chdir=/vagrant 38 | sudo_user: vagrant 39 | -------------------------------------------------------------------------------- /vagrant-faster.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "vagrant-faster" 7 | spec.version = "0.2.0" 8 | 9 | spec.authors = ["rdsubhas"] 10 | spec.email = ["rdsubhas@gmail.com"] 11 | spec.description = %q{A Vagrant Plugin that makes your VirtualBox VMs faster by allocating more Memory/CPU based on your machine capacity} 12 | spec.summary = spec.description 13 | spec.homepage = "http://github.com/rdsubhas/vagrant-faster" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 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 | 21 | spec.add_development_dependency "bundler", "~> 1.6" 22 | spec.add_development_dependency "rake" 23 | end 24 | --------------------------------------------------------------------------------