Skip to content

Instantly share code, notes, and snippets.

@nicholas
Created August 31, 2013 22:40
Show Gist options
  • Save nicholas/6401101 to your computer and use it in GitHub Desktop.
Save nicholas/6401101 to your computer and use it in GitHub Desktop.
Example Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_plugin('vagrant-omnibus')
Vagrant.require_plugin('vagrant-librarian-chef')
Vagrant.configure("2") do |config|
config.omnibus.chef_version = :latest
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.synced_folder ".", "/home/vagrant/app"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "git"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::system"
chef.add_recipe "postgresql::server"
chef.add_recipe "nodejs"
chef.add_recipe "imagemagick"
chef.json.merge!({
rbenv: {
rubies: ['2.0.0-p247'],
global: '2.0.0-p247',
gems: {
'2.0.0-p247' => [
name: 'bundler'
]
}
},
postgresql: {
password: {
postgres: 'postgres'
},
config: {
ssl: false,
listen_addresses: '*'
},
pg_hba: [
{ type: 'local', db: 'all', user: 'all', addr: nil, method: 'trust' },
{ type: 'host', db: 'all', user: 'all', addr: '127.0.0.1/32', method: 'trust' },
{ type: 'host', db: 'all', user: 'all', addr: '::1/128', method: 'trust' }
]
}
})
end
config.vm.provision :shell, :inline => <<-EOS
# Setup Postgres users
createuser -ds root -U postgres -h 127.0.0.1
createuser -ds vagrant -U postgres -h 127.0.0.1
# http://ezekielbinion.com/blog/making-rake-dbcreate-postgres-behave
psql template1 -c "UPDATE pg_database SET datallowconn = TRUE where datname = 'template0';"
psql template0 -c "UPDATE pg_database SET datistemplate = FALSE where datname = 'template1';"
psql template0 -c "DROP database template1;"
psql template0 -c "CREATE database template1 with template = template0 encoding = 'UNICODE' LC_CTYPE = 'en_US.UTF-8' LC_COLLATE = 'C';"
psql template0 -c "UPDATE pg_database SET datistemplate = TRUE where datname = 'template1';"
psql template1 -c "UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';"
cd app
bundle --quiet
bundle exec rake db:create
bundle exec rake db:migrate
EOS
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment