Top Banner
Putting Your Vagrants in the Cloud Richard Boyd II [email protected] @richardboydii
11

Putting Your Vagrants in the Cloud

Jul 17, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Putting Your Vagrants in the Cloud

Putting Your Vagrants in the CloudRichard Boyd II [email protected] @richardboydii

Page 2: Putting Your Vagrants in the Cloud

The Problem• We need Vagrant boxes that are multi-

provider (VirtualBox and AWS). • We need Vagrant boxes that are versioned. • We need Vagrant boxes that use same

‘golden image’ that we deploy servers on. • We need to host those Vagrant boxes in S3.

Page 3: Putting Your Vagrants in the Cloud

The Solution• Create a baseline Chef cookbook. • Use Packer to create named Vagrant Boxes using the

baseline for: • Each provider, e.g. baseline_vbox, baseline_aws. • Each version, e.g. baseline_vbox_v0.1.0.box,

baseline_aws_v0.1.0.vbox. • Create a JSON file containing metadata on all versions

and providers. • Automate the creation of the Vagrant boxes when the

baseline is updated.

Page 4: Putting Your Vagrants in the Cloud

How We Build It

1. Check the version

2. Run Packer. Provision an AMI and a VirtualBox VM using the Chef cookbook stored in GitHub. Turn those into Vagrant boxes at the end of the Packer run.

3. Upload the boxes to S3.

4. Update the metadata file.

Packer'

h)p://s3.amazonaws.com/vagrant/baseline_box/'

baseline'

h)p://s3.amazonaws.com/vagrant/baseline_box/boxes/'

baseline.json'

baseline_ami'

conveyor.rb'

baseline_vbox'

baseline_aws_v0.1.0.vbox'

baseline_vbox_v0.1.0.vbox'

baseline_aws_v0.1.0.vbox'

baseline_vbox_v0.1.0.vbox'

VERSION'

Page 5: Putting Your Vagrants in the Cloud

A Sample AWS Vagrantfile USER = ENV['USER'] TIME = Time.now DATE = TIME.strftime('%Y%m%d%H%M') RAND = TIME.strftime('%Y%m%d%H%M%S%L') HOST = `hostname`

Vagrant.require_version '>= 1.5.0' Vagrant.configure('2') do |config| config.vm.box = "baseline" config.ssh.username = “vagrant" config.ssh.private_key_path = “/path/to/a/key“ config.vm.box_check_update = true config.vm.provider :aws do |aws, override| aws.access_key_id = config.user.aws.access_key aws.secret_access_key = config.user.aws.secret_key aws.region_config “us-east-1“, :ami => “ami-123fd2" aws.instance_type = 'm1.small' aws.security_groups = [‘vagrant_group'] aws.tags = { 'user' => USER, 'date' => DATE, 'host' => HOST, 'segment' => 'dev.vagrant', 'environment' => 'local', 'launcher' => 'vagrant', 'boxname' => 'baseline' } aws.block_device_mapping = [ { 'DeviceName' => '/dev/xvdi', 'Ebs.VolumeSize' => 20, 'Ebs.VolumeType' => 'gp2' } ] end

end

Page 6: Putting Your Vagrants in the Cloud

A Sample Virtualbox Vagrantfile USER = ENV['USER'] TIME = Time.now DATE = TIME.strftime('%Y%m%d%H%M') RAND = TIME.strftime('%Y%m%d%H%M%S%L') HOST = `hostname`

Vagrant.require_version '>= 1.5.0' Vagrant.configure('2') do |config| config.vm.box = "baseline" config.ssh.username = "vagrant" config.ssh.private_key_path = “/path/to/key“ config.vm.box_url = “https://s3.amazonaws.com/vagrant/baseline_box/baseline.json" config.vm.network :private_network, ip: “10.20.30.1” config.vm.provider "virtualbox" do |v| v.name = "boxname-\#\{RAND\}" v.memory = 512 end config.vm.box_check_update = true

end

Page 7: Putting Your Vagrants in the Cloud

A Multi-provider Metadata File{ "name": NAME, “description": DESCRIPTION, "versions":

[ { “version": VERSION_1, "providers":

[ { "name": TYPE_OF_PROVIDER, “url": URL_TO_BOX_FILE, “checksum_type": TYPE_OF_CHECKSUM, "checksum": CHECKSUM_VALUE }, { "name": TYPE_OF_PROVIDER, “url": URL_TO_BOX_FILE, “checksum_type": TYPE_OF_CHECKSUM, "checksum": CHECKSUM_VALUE } ] }, {

“version": VERSION_2, BLAH },

] }

Page 8: Putting Your Vagrants in the Cloud

Example Metadata File{ "name": “box_name", "description": "Debian 7.7 (Wheezy) 64-bit box provisioned with the baseline::default recipe.", "versions": [ { "version": “0.1.0”, "providers": [ { "name": "aws", "url": “https://s3.amazonaws.com/vagrant/baseline_box/boxes/baseline_v0.1.0_vbox.box”, "checksum_type": "sha1", "checksum": "bfdb3e81b09a8daff479e160717413a24f77f0ae" }, { "name": "virtualbox", "url": “https://s3.amazonaws.com/vagrant/baseline_box/boxes/baseline_v0.1.0_aws.box”, "checksum_type": "sha1", "checksum": "53d711379eba58b9b19b15759d022f33aa720592" } ] } ] }

Page 9: Putting Your Vagrants in the Cloud

How Do You Use It?

vagrant box add https://s3.amazonaws.com/

vagrant/baseline_box/baseline.json

Page 10: Putting Your Vagrants in the Cloud

Things to Watch Out For• The content-type on the metadata file needs to be

set to JSON in S3. • Create a Packer template for each Vagrant box to

be built. • For the AMI, use the community (Debian) official

AMI as a starting point. • The Bento project (from Chef) provided a lot of

inspiration for this.

Page 11: Putting Your Vagrants in the Cloud

[email protected]

https://github.com/richardboydii/

@richardboydii

countze.ro