Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Forked from bergantine/Vagrantfile
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcanfield/627933f2451fd58c84b7 to your computer and use it in GitHub Desktop.
Save jcanfield/627933f2451fd58c84b7 to your computer and use it in GitHub Desktop.
Vagrant configuration offering setup of Ruby, NodeJS, Grunt, Bower and ZURB Foundation. (I put a fork in this!)

Initial setup of Vagrant Base

This step only ever needs to be done once. Once the precise64 box is installed on a system the remaining steps refer to that same box regardless of the project.

Download and install Xcode from the Apple App Store.

Download virtualbox from http://www.virtualbox.org/wiki/Downloads, install dmg.

Download vagrant from http://downloads.vagrantup.com/, install dmg.

Launch a terminal window, check that it installed:

(host) $ which vagrant

Add a vagrant box (we'll be using Ubuntu Precise Pangolin (12.04 LTS) 64-bit):

(host) $ vagrant box add precise64 http://files.vagrantup.com/precise64.box

Starting a New Project

Make a directory for the project and change to it, replacing <path_to> with the path to the project and <project_name> with the name of the project.

(host) $ mkdir <path_to>/<project_name> && cd $_

For example, to create a project called 'website' in your home directory:

(host) $ mkdir ~/website && cd $_

When you're all done, within this directory will be a directory named vagrant/ which will match up with /home/vagrant/ in the virtual envirionment. Virtualbox keeps the two directories in sync so changes to one will be made in the other.

Copy in the Vagrantfile.

(host) $ curl https://gist.github.com/jbergantine/8854784/raw/Vagrantfile > Vagrantfile

Copy in the provisioning files.

(host) $ curl https://gist.github.com/jbergantine/8854784/raw/install-linux-utils > install-linux-utils.sh
(host) $ curl https://gist.github.com/jbergantine/8854784/raw/install-rvm.sh > install-rvm.sh
(host) $ curl https://gist.github.com/jbergantine/8854784/raw/install-ruby.sh > install-ruby.sh
(host) $ curl https://gist.github.com/jbergantine/8854784/raw/set-default-ruby.sh > set-default-ruby.sh
(host) $ curl https://gist.github.com/jbergantine/8854784/raw/install-node.sh > install-node.sh
(host) $ curl https://gist.github.com/jbergantine/8854784/raw/install-bower-and-grunt-cli.sh > install-bower-and-grunt-cli.sh

Startup Vagrant and provision the Virtual Machine:

(host) $ vagrant up

SSH in to the virtualbox:

(host) $ vagrant ssh 

Manually install the two non-automated Gists

Copy and paste line for line the code from install-node.sh and install-bower-and-grunt-cli.sh.

Start a Zurb Foundation project

(vm) $ cd /home/vagrant
(vm) $ foundation new my_project

Resources

Known Issues

  1. The shell script provisioning doesn't do any checking, it just tries to go it again
  2. The Vagrantfile is misconfigured in some way that throws an SSH error when attempting to run vagrant provision
#!/usr/bin/env bash
source /home/vagrant/.profile
# requires npm to be installed first
npm install -g bower grunt-cli
#!/usr/bin/env bash
apt-get update
apt-get install build-essential -q -y
# install curl without prompts
apt-get install curl -q -y
# install git
apt-get install git-core -q -y
#!/usr/bin/env bash
# install nodejs and npm from source
# (apt-get fetches a version too old to use with bower)
# required for bower and grunt-cli
echo 'export PATH=$HOME/local/bin:$PATH' >> /home/vagrant/.profile
source /home/vagrant/.profile
mkdir -p /home/vagrant/local
mkdir -p /home/vagrant/node-latest-install
cd /home/vagrant/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=/home/vagrant/local
make install
curl https://npmjs.org/install.sh | sh
#!/usr/bin/env bash
source /usr/local/rvm/scripts/rvm
rvm use --install $1
shift
if (( $# ))
then gem install $@ --no-ri --no-rdoc
fi
#!/usr/bin/env bash
curl -sSL https://get.rvm.io | bash -s $1
#!/usr/bin/env bash
source /usr/local/rvm/scripts/rvm
rvm use $1 --default
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64-2"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# Provision
# upgrade linux and fetch utils for installing other things
config.vm.provision :shell, :path => "install-linux-utils.sh"
# install rvm
config.vm.provision :shell, :path => "install-rvm.sh", :args => "stable"
# install ruby 2.1.0 using rvm
# install the foundation gem and compass gem
config.vm.provision :shell, :path => "install-ruby.sh", :args => "2.1.0 foundation compass"
# set the default version of ruby to 2.1.0
config.vm.provision :shell, :path => "set-default-ruby.sh", :args => "2.1.0"
################################################################################
# The following recipes don't work - probably a path issue
# SSH in and follow them manually line by line
################################################################################
# install node.js and npm
#config.vm.provision :shell, :path => "install-node.sh"
# install bower and grunt-cli
#config.vm.provision :shell, :path => "install-bower-and-grunt-cli.sh"
# Forward a few ports
# (defaults for apache http traffic, rails http traffic, django http traffic)
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 8000, host: 8000
# Enable a shared folder
config.vm.synced_folder "vagrant/", "/home/vagrant", create: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment