Automate your Development Environment with Vagrant & Chef

Post on 16-Jul-2015

473 views 3 download

Tags:

Transcript of Automate your Development Environment with Vagrant & Chef

Automate yourDevelopment Environment

with Vagrant & Chef

Michael Lihs

@kaktusmimi

CHANGEOVER TIME

“How long does it take you

to set up a new XYZ project?”

COLLABORATION

How do you share projects with colleagues?

YOU BUILD IT –YOU RUN IT!

“But it worked on my machine!”

How can Vagrant help you?

• Set up ANY projects in minutes

• Have it “to go”

• Share it with others

• Have a “copy” of your production server

Technology Stack

VirtualBoxFree Open Source Virtualization Tool

ChefConfiguration ManagementFramework

Vagrant“Remote Control” for VirtualBox

What is Vagrant?

• Building tool for portable dev environments

• Tool for distributing work environments

• Written in Ruby

• Open Source

• Build upon well-established tools

Vagrant Components

• Vagrant Box

• Vagrantfile

• Provisioners

• Providers

Vagrant Boxes

• Basically a “tweaked” virtual machine Image

• Used as base layer for all further provisioning

• Many pre-installed boxes available online:

$ vagrant box add {title} {url}

$ vagrant init {title}

$ vagrant up

Provisioners

• „Where the magic happens“

– Installing packages and software

– Configuration and starting of services

– E.g. creating vhost, database, ...

• Run once the box is booted in VirtualBox

What is Chef?

• Configuration Management automation tool

• Written in Ruby

– Provides easy-to-learn (?) DSL

• „Infrastructure as code“

– Use versioning

– Use tests, Continuous Integration & Delivery

Chef Tools

• Chef Client

• Chef Server

• Knife

• …too many

Chef Components

• Cookbooks, Recipes, Resources

• Attributes

• Templates

• Roles

• and many more…

└── cookbook_name

├── attributes

│ └── default.rb

├── recipes

│ └── default.rb

├── templates

│ └── default

│ └── template.erb

└── metadata.rb

Provisioning

Run Chef in your VagrantBox

sudo chef-solo –c solo.rb -j config.json

chef run

vagrant up

import image

provision projectsmount cookbooks

Your own Vagrant Box

• The “Playbook-to-Cookbook-Algorithm”

– Write installation steps in a text document

– Follow steps yourself, refine document

– Give document to someone else, refine again

– No changes in document start writing

cookbooks

Generic WebProjectCookbook

1. Install Packages for Apache, MySQL, PHP

2. Provision Webspace(s) and vhost(s)

3. Provision MySQL Database(s)

4. Download TYPO3 sources (or use Composer)

5. Clone your Git project

Next Step

• Provisioning of hosting servers with Chef

• Building Vagrant Boxes on CI Server

• Vagrant Boxes for customers

• Codecoon

Summary

• Vagrant is a great tool for portable boxes

• Chef can help you manage your configuration

• „Infrastructure as Code“

• Same environment on dev and production

• DevOps brings devs and admins together

@kaktusmimi