A vagrant+puppet-based setup to provide an Ubuntu-based Ruby web-app development environment.
-
Vagrant, version 1.4.1 or higher after installing vagrant you will need to install the hostmanager plugin:
> vagrant plugin install vagrant-hostmanager > vagrant hostmaster # starts the hostmaster process
Download this repository, open up the project in your terminal and start the first-time provisioning as follows:
> cd vagrant/ # you'll need to operate vagrant within this directory
> vagrant up # boot the virtual machine
This will provision the environment (a 5-10 minutes process) as follows:
Your base box (which is automatically downloaded by Vagrant) provides the following:
- Ubuntu 12.04 LTS virtual machine with support for VirtualBox 4.3.0
- pre-installed Puppet 3.3.1 support
- (up to) 32GB of space
Upon first boot, vagrant will provision this base box via puppet, providing the following enhancements:
- Puppet extensions, including:
- libshadow-based password configuration
- augeaus-based configuration management
- librarian-puppet-based module installation
- basic web-app support software, including:
- Apache
- Mysql
- Sqlite
- Imagemagick
- network connection support, including:
- Smbd (windows-based) networking
- Afpd (apple-based) networking
- Ruby Version Manager, including:
- "playground"-aliased configurations for Ruby 2.x and a fresh gemset
- Passenger installed and configured to work with Apache ("ready for Rails")
- virtual host "playground.vm"
- domain is auto-configured on your Host system (via the hostmanager plugin)
- login user "dev" with password "playground"
- override these passwords via the "puppet/hiera/common.yaml" configuration
- pre-created personal and MySQL databases, "dev", "playground_development" and "playground_test"
- 2 synced directories between the Guest and Host systems:
- the first is this project's "vagrant" directory, which maps to "/vagrant/" on the Guest system
- the second is this projects' "working" directory, which maps to "/var/sites/playground" on the Guest system
As soon as the initial provisioning is completed, there are a few quick steps to enable the synchronized working directory (in addition to the synchronized directory for vagrant/puppet configuration):
-
create a directory named "working" at the top level of the project (parent directory of "vagrant/")
> cd ../ > mkdir working -
edit the Vagrantfile (located under "vagrant/") - un-comment the following line:
# config.vm.synced_folder '../working', '/var/sites/playground'This will activate the working folder (which requires/is owned by the the newly-created "dev" user)
-
Next, reload vagrant to make these changes take effect:
> cd vagrant/ # return to the vagrant directory > vagrant reload # restart the virtual machine
Once the vagrant environment has reloaded, log-in, which will drop you into the vagrant user's home directory:
> vagrant ssh
You are now logged into the Guest system as the user "vagrant"; now log-in as the user whose account you'll be developing with, "dev":
> su -l dev
You'll be prompted for the dev user's password ("playground"), after which you'll drop into "dev's" home directory.
Now you'll want to set up Rails 4:
> cd /var/sites
> rvm use playground@playground # use the rvm ruby and gemset pre-created for the "playground" app
> gem install rails --version=4.0.2 --no-rdoc --no-ri # or your preferred Rails version
> rails new playground # installs a new Rails 4 app under /var/sites/playground
> cd playground
Vagrant maps "/var/sites/playground" directory maps to the "working" directory, so you can begin modifiying this rails app skeleton from your Host system. Your first step should be to edit the Gemfile (in the new Rails app root) and uncomment the "therubyracecar" gem (this provides a Javascript engine, which is required by Rails 4's asset pipeline)
> bundle install # update bundled gems to include "therubyracecar"
> touch tmp/restart.txt # restart the server
Finally, verify that Rails 4 is working in a text-mode browser:
> lynx http://playground.vm # view the pristine Rails 4 app main page in a text-mode web browser
You can also access this site from a browser on your Host system by appending the forwarded port number (for web traffic on port 80). Vagrant displays forwarded port info when starting/reloading a VM, and this info can also be looked up via Virtualbox network settings for the running VM.
You're all set to start development; have fun!