##Session 2: Provisioning Test Environment with Chef and Vagrant
The aim of this session is to help Tester to quickly set up Test / Dev environment on their own machine and share the configuration among team members.
####Contents:
- Common Tasks on setting up new Dev/Test Environment (without Chef/Vagrant)
- Most common used Vagrant commands
- Installing pre-require packages
- Iteration 1: Installing base packages for the Guest VM
- Iteration 2: Installing DB and creating seed data
- Iteration 3: Loading latest code
- Iteration 4: Handling the configuration to other members
####Installation Instruction ######Prerequisite packages:
- Install Vagrant
Choose Vagrant for your prefer OS from: https://www.vagrantup.com/downloads.html - Install Virtualbox
https://www.virtualbox.org/wiki/Downloads - Install ChefDK
http://downloads.getchef.com/chef-dk/ - Install DevKit (Windows user only)
This package is to support Ruby to build native package (for gem installation). You can find it at http://rubyinstaller.org/downloads
You should choose a non-space in full path as the destination for the kit. i.e C:\Hashicorp\DevKit
Then go to the DevKit folder to run devkitvars.bat
######Important time saving note Since creating first virtual machine would trigger downloading of hundred of megabytes, please run below command prior coming to the session
vagrant box add chef/ubuntu-14.04
and select option 1 (Virtual Box), this would trigger downloading the base virtual box for ubuntu 14.04 x64
######Ruby and related Gems
- For Unix:
curl -sSL https://get.rvm.io | bash -s stable --ruby
- For Windows: download and install Ruby from http://rubyinstaller.org/downloads/
- Installing require gems and vagrant plugins:
sudo gem install bundler
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-omnibus
######Checkout project from GitHub
- If you don't have git, please get it from: http://git-scm.com/downloads
git clone https://github.com/SydneyTestersBootcamp/sydneyTestersBootcamp.git
- Bring up the machine
cd sydneyTestersBootcamp/02_ProvisioningTestEnvironment/machines
bundle install
vagrant up
- You're now ready to travel to your VM
vagrant ssh
####Most used commands
- vagrant up: bring up and provision the machine
- vagrant destroy: anything goes wrong, destroy the machine and rebuild it with vagrant up
- vagrant halt: shutdown the machine
- vagrant reload: restart the machine
- vargant provision: provision the machine with all chef's recipes
- vagrant box add box-name / box-url: download the base box (this step is included in vagrant up, but we can still pre-download it)
- vagrant suspend: hibernate the machine, you can later resume it with vagrant resume
- vagrant ssh: connect to the local virtual machine via ssh
####Common issues
- RuntimeError: Couldn't determine Berks version
You would need to add chefdk/bin at front of your PATH
For MacOSX: default chefdk is at /opt/chefdk/bin
For Windows: default chefdk is at C:\opscode\chefdk\bin - The directory where plugins are installed (the Vagrant home directory) has a space in it...
For Windows user only, you can useecho %username%
to get username and you can fix this by moving the .vagrant.d to a folder that has no space in the full path, and set the system variable VAGRANT_HOME=new_path_to_vagrant.d
i.e: VAGRANT_HOME=C:\HashiCorp.vagrant.d
####Reading Material
- Mischa Taylor's Coding Blog:
http://misheska.com/blog/2013/06/16/getting-started-writing-chef-cookbooks-the-berkshelf-way/
http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/
http://misheska.com/blog/2013/08/06/getting-started-writing-chef-cookbooks-the-berkshelf-way-part3/
-
Chef Online Documents:
https://docs.getchef.com/essentials_cookbooks.html -
Vagrant Online Documents:
http://docs.vagrantup.com/v2/