Last active
August 29, 2015 14:03
-
-
Save gmontard/378a00c46ff12560e132 to your computer and use it in GitHub Desktop.
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
##### Custom Settings #### | |
private_ip = ENV['VAGRANT_PRIVATE_IP'] || "10.0.0.42" | |
sql_root_pwd = ENV['VAGRANT_SQL_ROOT_PWD'] || 'while42' | |
cpu = ENV['VAGRANT_CPU'] || "3" | |
ram = ENV['VAGRANT_RAM'] || "1024" | |
packages = ["ftp", "vim", "libmysql-ruby", "libmysqlclient-dev"] | |
chef_cookbooks_path = ["chef/cookbooks"] | |
ruby_version = "ruby-2.1.1" | |
## Box hostname | |
config.vm.hostname = "while42" | |
# Create a private network, which allows host-only access to the machine | |
# using a specific IP | |
config.vm.network "private_network", ip: private_ip | |
# Create a public network, which generally matched to bridged network. | |
# Bridged networks make the machine appear as another physical device on | |
# your network. | |
config.vm.network "public_network", bridge: "en0: Ethernet" | |
## Forward the SSH agent from host machine | |
config.ssh.forward_agent = true | |
# Use NFS to share current host folder to /vagrant | |
config.vm.synced_folder ".", "/vagrant", type: "nfs" | |
# Provider-specific configuration. | |
# For VirtualBox: | |
config.vm.provider :virtualbox do |vm, override| | |
override.vm.box = "precise64" | |
override.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
vm.customize ["modifyvm", :id, "--memory", ram] | |
vm.customize ["modifyvm", :id, "--cpus", cpu] | |
end | |
# For VMware: | |
config.vm.provider :vmware_fusion do |vm, override| | |
override.vm.box = "precise64-vmware" | |
override.vm.box_url = "http://files.vagrantup.com/precise64_vmware_fusion.box" | |
vm.vmx["memsize"] = ram | |
vm.vmx["numvcpus"] = cpu | |
end | |
# Enable provisioning with chef solo | |
## Must use vagrant plugin install vagrant-librarian-chef | |
config.librarian_chef.cheffile_dir = "chef" | |
# PostgreSQL was using LATIN1 instead of UTF-8 as a server_encoding value | |
config.vm.provision :shell, inline: "echo 'LC_ALL=\"en_US.UTF-8\"' > /etc/default/locale" | |
# Chef >= 11.4.0 needs to be install. It requires ruby to run. | |
config.vm.provision :shell, inline: "sudo aptitude update && sudo aptitude -y install build-essential && sudo aptitude -y install ruby1.9.3 && sudo gem install chef --version 11.6.0 --no-rdoc --no-ri --conservative" | |
# Install Heroku tools | |
config.vm.provision :shell, inline: "wget -qO- https://toolbelt.heroku.com/install.sh | sh" | |
config.vm.provision :chef_solo do |chef| | |
chef.cookbooks_path = chef_cookbooks_path | |
chef.roles_path = "chef/roles" | |
chef.add_role "server" | |
## Override Roles config | |
chef.json = { | |
"mysql" => { | |
"server_root_password" => sql_root_pwd, | |
"bind_address" => private_ip | |
}, | |
"rvm" => { | |
'version' => "1.25.22", | |
'global_gems' => [ | |
{ | |
'name' => "bundler" | |
} | |
], | |
'user_installs' => [{ | |
'user' => 'vagrant', | |
'default_ruby' => ruby_version, | |
'rubies' => [ruby_version], | |
'gems' => { | |
ruby_version + '@rails' => [ | |
{ 'name' => 'bundler' } | |
] | |
} | |
}] | |
} | |
} | |
end | |
# Install additionnal custom lib without Chef | |
packages.each{|package| | |
config.vm.provision :shell, inline: "sudo aptitude install -y #{package}" | |
} | |
# Run custom script | |
script = <<SCRIPT | |
#!/usr/bin/env bash | |
echo 'Running Bundler, DB migration etc.' | |
echo 'Init RVM (Ruby #{ruby_version})' | |
source /home/vagrant/.rvm/environments/#{ruby_version} | |
echo "Running bundler" | |
cd /vagrant && bundle install ; true | |
SCRIPT | |
config.vm.provision :shell, inline: script | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment