/rails-dev-box

A virtual machine for Ruby on Rails core development

Primary LanguageRubyMIT LicenseMIT

A Virtual Machine for Ruby on Rails Development

Introduction

This project automates the setup of a development environment for working on Ruby on Rails. Use this virtual machine to work on a pull request with everything ready to hack and run the test suites.

Requirements

Pre VM Build

  1. Install VirtualBox (or parallels)
  2. Install Vagrant

How To Build The Virtual Machine

Building the virtual machine is this easy:

host $ git clone https://github.com/paulcook/rails-dev-box.git
host $ cd rails-dev-box
host $ vagrant up

That's it.

(If you want to use VMWare Fusion instead of VirtualBox, write vagrant up --provider=vmware_fusion instead of vagrant up when building the VM for the first time. After that, Vagrant will remember your provider choice, and you won't need to include the provider flag again.)

(If you want to use Parallels Desktop instead of VirtualBox, you need Vagrant 1.5+, and write vagrant up --provider=parallels instead of vagrant up when building the VM for the first time. After that, Vagrant will remember your provider choice, and you won't need to include the provider flag again.)

If the base box is not present that command fetches it first. The setup itself takes about 3 minutes in my MacBook Air. After the installation has finished, you can access the virtual machine with

host $ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
...
vagrant@rails-dev-box:~$

Port 3000 in the host computer is forwarded to port 3000 in the virtual machine. Thus, applications running in the virtual machine can be accessed via localhost:3000 in the host computer.

Next Steps: Rails Project setup

host $ git clone git@github.com:Taivara/RingSide.git
host $ vagrant ssh
vagrant@rails-dev-box:~$ cd /vagrant/RingSide
vagrant@rails-dev-box:~$ bundle
vagrant@rails-dev-box:~$ rails s
=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-08-09 17:17:37] INFO  WEBrick 1.3.1
[2014-08-09 17:17:37] INFO  ruby 2.1.1 (2014-02-24) [i686-linux]
[2014-08-09 17:17:37] INFO  WEBrick::HTTPServer#start: pid=3130 port=3000

After firing up the rails server you should be able to get the rails project home page by going to localhost:3000 on your host machine.

What's In The Box

  • Git

  • RVM

  • Ruby 2.1.1 (binary RVM install)

  • Bundler

  • SQLite3, MySQL, and Postgres

  • System dependencies for nokogiri, sqlite3, mysql, mysql2, and pg

  • Databases and users needed to run the Active Record test suite

  • Node.js for the asset pipeline

  • Memcached

Recommended Workflow

The recommended workflow is

  • edit in the host computer and

  • test within the virtual machine.

Just clone your Rails fork into the rails-dev-box directory on the host computer:

host $ ls
README.md   Vagrantfile puppet
host $ git clone git@github.com:<your username>/rails.git

Vagrant mounts that directory as /vagrant within the virtual machine:

vagrant@rails-dev-box:~$ ls /vagrant
puppet  rails  README.md  Vagrantfile

Install gem dependencies in there:

vagrant@rails-dev-box:~$ cd /vagrant/rails
vagrant@rails-dev-box:/vagrant/rails$ bundle

We are ready to go to edit in the host, and test in the virtual machine.

This workflow is convenient because in the host computer you normally have your editor of choice fine-tuned, Git configured, and SSH keys in place.

Virtual Machine Management

When done just log out with ^D and suspend the virtual machine

host $ vagrant suspend

then, resume to hack again

host $ vagrant resume

Run

host $ vagrant halt

to shutdown the virtual machine, and

host $ vagrant up

to boot it again.

You can find out the state of a virtual machine anytime by invoking

host $ vagrant status

Finally, to completely wipe the virtual machine from the disk destroying all its contents:

host $ vagrant destroy # DANGER: all is gone

Please check the Vagrant documentation for more information on Vagrant.

Faster Rails test suites

The default mechanism for sharing folders is convenient and works out the box in all Vagrant versions, but there are a couple of alternatives that are more performant.

rsync

Vagrant 1.5 implements a sharing mechanism based on rsync that dramatically improves read/write because files are actually stored in the guest. Just throw

config.vm.synced_folder '.', '/vagrant', type: 'rsync'

to the Vagrantfile and either rsync manually with

vagrant rsync

or run

vagrant rsync-auto

for automatic syncs. See the post linked above for details.

NFS

If you're using Mac OS X or Linux you can increase the speed of Rails test suites with Vagrant's NFS synced folders.

With a NFS server installed (already installed on Mac OS X), add the following to the Vagrantfile:

config.vm.synced_folder '.', '/vagrant', type: 'nfs'
config.vm.network 'private_network', ip: '192.168.50.4' # ensure this is available

Then

host $ vagrant up

Please check the Vagrant documentation on NFS synced folders for more information.

License

Released under the MIT License, Copyright (c) 2012–ω Xavier Noria.