We want all attendees of this workshop to develop in the same environment. To do this, we will be using a combination of VirtualBox and Vagrant so that each attendee (no matter what OS their laptop is running on) will be able to develop from an Ubuntu Linux 14.04 virtual machine. We are assuming some familiarity with the linux command line, but if you are not familiar please reach out to an instructor and your fellow students.
VirtualBox Vagrant
VirtualBox allows your system to run multiple virtual machines from your laptop's OS without needing to reboot or affect your laptop's OS.
Vagrant is a wrapper for VirtualBox VMs which allows you to create portable work environments you can take from system to system. It makes it easy to ssh into a virtual machine and interact with it the way you would interact with a cloud server.
Download the VirtualBox package appropriate for your Operating system here After it is downloaded and installed, follow the instructions here to start up VirtualBox.
[TO DO: Decide if we want to provide Virtual Box installation packages on a USB stick to avoid hitting the wifi so hard]
Download the Vagrant package appropriate for your Operating System here
[TO DO: Decide if we want to provide Vagrant installation packages on a USB stick to avoid hitting the wifi so hard]
Follow the Vagrant setup instructions located here
Create a new directory to host your workshop material. Call it whatever you like.
Open up a terminal window and change directories into your workshop directory. IE, if you created your workshop folder within your documents directory, you would navigate there by typing this in the terminal.
$ cd Documents/my_workshop_folder
Head on down to the "Using Vagrant" section of these instructions.
You must also install PuTTY (a Telnet and SSH client) and PuTTY gen (an RSA and DSA key generation utility). You can downlad and install these here
Create a new folder to host your workshop material. Call it whatever you like, I created mine on my windows desktop but you can create it wherever you choose.
Hold down shift and right click on the project folder, then select "open command window here"
Head on down to the "Using Vagrant" section of these instructions.
Open up a command prompt by holding down the windows key and x, then clicking the windows start button at the bottom left of the screen, then selecting "Command Prompt."
Run this command in the command prompt to create your project folder (call it whatever you like).
C: mkdir project_folder
Then switch to that folder with this command:
C: cd project_folder
Head on down to the "Using Vagrant" section of these instructions.
Let's create a Vagrant box that runs Ubuntu 14.04 LTS (Trusty Tahr). We've created an image that is based on Trusty, with a few tools added.
TODO - instructions on how to find basebox image
In your project directory (using terminal if you're on a Mac or Linux box, using the command prompt if you're on a Windows box) type in this command:
$ vagrant box add dev4ops4dev $USB_STICK_PATH/workshop.box
This will locate the workshop image, and load it into Vagrant's library of boxesunder the name 'dev4ops4dev'. Now Vagrant will be able to create a running VM based on that box!
$ vagrant init dev4ops4dev
This will create a Vagrantfile in the project directory, which will allow us to configure our Vagrant box. Go ahead and open it up and take a look through if you like.
Then run this command to start up your new Vagrant box:
$ vagrant up
Now it's time to SSH into your new Vagrant box so we can use it as a development environment! The procedure for doing this varies slightly by Operating System, so please follow the appropriate instructions below.
In your project folder (make sure it's the same directory with the Vagrant file you just created), run this command:
your-laptop $ vagrant ssh
This will log you into your Vagrant box as the user 'vagrant', which has passwordless sudo.
Logging into a Vagrant box from Windows is a little more complicated, because windows does not come with an SSH command line client.
Zack Wallace has a fantastic blog post called "Getting Started with Vagrant on Window". Follow the instructions in the "Now I Can Access my Server, Right?" section to ssh into your Vagrant box.
Look around! Your development machine should have some tools - some familiar, some perhaps not:
vagrant@d4o4d-workshop $ for cmd in nano vim emacs git vagrant tugboat chef rubocop foodcritic rspec; do $cmd --version; echo ""; done
Also notice that the prompt has changed, indicating that you on another machine - VM within your laptop!:
vagrant@d4o4d-workshop $ uname -a
Within your VM, we'd like to be able to reference your workshop group name. To do that, we'll add an environment variable.
This command will add a line to your user profile to set a new variable. Use the real name of your group here
vagrant@workshop $ echo 'export GROUP_NAME=lasagna' >> ~/.bash_profile
This command will re-load your profile:
vagrant@workshop $ source ~/.bash_profile
And this command will tell you if you did it right:
vagrant@workshop $ echo $GROUP_NAME
You should see the name of your group. If not, raise your hand.
At this point, you only need to know a bit about Vagrant. We'll add more as we go along.
You can pass files directly into and out of your vagrant instance using the /vagrant area, which is mounted on the directory on the host containing the Vagrantfile.
NOTE: this works seamlessly for VirtualBox-based VMs. Later, we may work on other systems, in which this feature has different behavior.
As you saw above, you use init to start a new project. Given the name of a Vagrant box, it will create a Vagrantfile with default settings, which will tell it to create a VM from the box.
When run in a directory with a Vagrantfile, this will create a VM if one does not exist, or resume one if it has been suspended.
'vagrant ssh-config' tells you the settings it would use to connect to the VM. 'vagrant ssh' connects using the command line SSH, if available.
Tells the guest operating system to perform a graceful shutdown. Add --force to pull the plug immediately.
Force-halts the guest, then deletes the instance or disk image. No going back - once it's gone, it's gone.
And that sets up your development environment for this workshop! Now onto using it!
We started with a base ubuntu image, which we got via Vagrant Atlas:
$ vagrant init ubuntu/trusty64
$ vagrant up
$ vagrant ssh
The first thing we want to do is update the operating system on our Vagrant box. To do this in Ubuntu 14.04, run:
vagrant@d4o4d-workshop $ sudo apt-get update
We'll be using Chef throughout this workshop to set up a webserver, so let's get the ChefDK (Chef Developer Kit) installed on your Vagrant box.
Run this command:
vagrant@d4o4d-workshop $ curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -P chefdk
This will take a few minutes. Once it is complete (you'll see a message that says "Thank you for installing Chef Development Kit!"), verify that ChefDK installed like this:
vagrant@d4o4d-workshop $ chef --version
You should see something along the lines of "Chef Development Kit Version: 0.4.0"
We'll be using Ruby to create Chef code. Although ChefDK does come with a current version of Ruby, there is also an earlier version of Ruby already installed on our Ubuntu 14.04 system.
We need to configure are our development environment to use the ChefDK version of Ruby, rather than the system version of Ruby. To do this, first run:
vagrant@d4o4d-workshop $ which ruby
If it returns something like:
usr/bin/ruby
That means your development environment is using the system ruby, rather than the ChefDK version of Ruby. To fix this, run:
vagrant@d4o4d-workshop $ echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
This adds a line to your .bash_profile file, telling it to use the ChefDK version of Ruby.
Now we need to apply this change. To do this, run:
vagrant$ source ~/.bash_profile
Then re-run:
vagrant@d4o4d-workshop $ which ruby
It should now return:
/opt/chefdk/embedded/bin/ruby
We installed several editors to suit various tastes. As a safe default, we set EDITOR to nano in vagrant's .bash_profile .
sudo apt-get install emacs24-nox emacs24-el vim nano joe
sudo apt-get install tree
### Chef, Vagrant, and DigitalOcean drivers
We'll be doing some development using Chef and a cloud provider, so we need to install Vagrant within the VM.
```bash
echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
sudo apt-get install git
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.deb && sudo dpkg -i vagrant_1.7.2_x86_64.deb && rm vagrant_1.7.2_x86_64.deb
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-digitalocean
gem install tugboat
There are some additional packages you will need to install to work with Ruby on Ubuntu. You can install these with this command:
vagrant@d4o4d-workshop $ sudo apt-get install git git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
vagrant@d4o4d-workshop $ exit
your-laptop $ vagrant halt
your-laptop $ vagrant package --output dev4ops4dev-workshop-0.1.0.box