Automate your Development Environment with Vagrant & Chef

29
Automate your Development Environment with Vagrant & Chef Michael Lihs

Transcript of Automate your Development Environment with Vagrant & Chef

Page 1: Automate your Development Environment with Vagrant & Chef

Automate yourDevelopment Environment

with Vagrant & Chef

Michael Lihs

Page 2: Automate your Development Environment with Vagrant & Chef

@kaktusmimi

Page 3: Automate your Development Environment with Vagrant & Chef

CHANGEOVER TIME

“How long does it take you

to set up a new XYZ project?”

Page 4: Automate your Development Environment with Vagrant & Chef

COLLABORATION

How do you share projects with colleagues?

Page 5: Automate your Development Environment with Vagrant & Chef

YOU BUILD IT –YOU RUN IT!

“But it worked on my machine!”

Page 6: Automate your Development Environment with Vagrant & Chef

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

Page 7: Automate your Development Environment with Vagrant & Chef

Technology Stack

VirtualBoxFree Open Source Virtualization Tool

ChefConfiguration ManagementFramework

Vagrant“Remote Control” for VirtualBox

Page 8: Automate your Development Environment with Vagrant & Chef

What is Vagrant?

• Building tool for portable dev environments

• Tool for distributing work environments

• Written in Ruby

• Open Source

• Build upon well-established tools

Page 9: Automate your Development Environment with Vagrant & Chef

Vagrant Components

• Vagrant Box

• Vagrantfile

• Provisioners

• Providers

Page 10: Automate your Development Environment with Vagrant & Chef

Vagrant Boxes

• Basically a “tweaked” virtual machine Image

• Used as base layer for all further provisioning

• Many pre-installed boxes available online:

Page 11: Automate your Development Environment with Vagrant & Chef
Page 12: Automate your Development Environment with Vagrant & Chef

$ vagrant box add {title} {url}

$ vagrant init {title}

$ vagrant up

Page 13: Automate your Development Environment with Vagrant & Chef
Page 14: Automate your Development Environment with Vagrant & Chef

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

Page 15: Automate your Development Environment with Vagrant & Chef

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

Page 16: Automate your Development Environment with Vagrant & Chef
Page 17: Automate your Development Environment with Vagrant & Chef

Chef Tools

• Chef Client

• Chef Server

• Knife

• …too many

Page 18: Automate your Development Environment with Vagrant & Chef

Chef Components

• Cookbooks, Recipes, Resources

• Attributes

• Templates

• Roles

• and many more…

Page 19: Automate your Development Environment with Vagrant & Chef

└── cookbook_name

├── attributes

│ └── default.rb

├── recipes

│ └── default.rb

├── templates

│ └── default

│ └── template.erb

└── metadata.rb

Page 20: Automate your Development Environment with Vagrant & Chef
Page 21: Automate your Development Environment with Vagrant & Chef
Page 22: Automate your Development Environment with Vagrant & Chef

Provisioning

Run Chef in your VagrantBox

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

Page 23: Automate your Development Environment with Vagrant & Chef

chef run

vagrant up

import image

provision projectsmount cookbooks

Page 24: Automate your Development Environment with Vagrant & Chef

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

Page 25: Automate your Development Environment with Vagrant & Chef

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

Page 26: Automate your Development Environment with Vagrant & Chef

Next Step

• Provisioning of hosting servers with Chef

• Building Vagrant Boxes on CI Server

• Vagrant Boxes for customers

• Codecoon

Page 27: Automate your Development Environment with Vagrant & Chef

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

Page 28: Automate your Development Environment with Vagrant & Chef
Page 29: Automate your Development Environment with Vagrant & Chef

@kaktusmimi