This project is a base configuration to run a Ruby project both in development with Vagrant and in production.
It uses Chef to provision the server.
Install Vagrant: http://docs.vagrantup.com/v2/installation/ Install Virtual Box: https://www.virtualbox.org/wiki/Downloads
gem install berkshelf
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelfThe recommended way is to use this kitchen as a git submodule. Here is a good example of project structure:
my_project/
chef/
kitchen/ (submodule https://github.com/lakim/ruby-chef-box.git)
app-cookbooks/ (project specific cookbooks)
nodes/
Vagrantfile
Berksfile
cd my_project
git submodule add https://github.com/lakim/ruby-chef-box.git chef/kitchen
cp chef/kitchen/Berksfile.sample Berksfile
cp chef/kitchen/Vagrantfile.sample Vagrantfile
vagrant up
vagrant sshOn the VM:
sudo su deploy
echo "source /etc/profile.d/rbenv.sh" >> ~/.bashrc
bash
rbenv versionsIf the previous steps were fine, you should get a list of installed Ruby versions. Then go for some tests:
cd /vagrant
gem install bundler
gem install rails
rbenv rehash
rails new .Default user/password: postgres/postgres
To generate a password:
echo -n 'my_password''postgres' | openssl md5 | sed 's/^.* //' | sed 's/^/md5/'Test postgresql connection:
psql --username=postgres --password --host=localhostTaking snapshots of your Vagrant VM can save you a lot of time, especially when you experimenting. Vagrant comes with a build in snapshot engine, which can be controlled from the command line thanks to this plugin : https://github.com/dergachev/vagrant-vbox-snapshot
On your host:
vagrant plugin install vagrant-vbox-snapshotHere are the most usefull commands, from the plugin page:
vagrant snapshot take [NAME] # take snapshot, labeled by NAME
vagrant snapshot list # list snapshots
vagrant snapshot back # restore last taken snapshot
vagrant snapshot delete [NAME] # delete specified snapshot
vagrant snapshot go [NAME] # restore specified snapshotRemember you can also manage snapshots using Vagrant GUI.
- Fix rbenv PATH for deploy user
- Use UNIX socket for postgres instead of TCP connection
- Do not configure gems doc by default