SlideShare a Scribd company logo
1 of 35
Download to read offline
Virtually improve your dev workflow
with Vagrant
Justin Filip - @jfilip
boltmade.com
CC BY-SA 3.0 Justin Filip 1
What even is Vagrant?
Vagrant is a tool for building complete development environments.
With an easy-to-use workflow and focus on automation, Vagrant
lowers development environment setup time, increases
development/production parity, and makes the "works on my
machine" excuse a relic of the past.
-- official Vagrant docs
CC BY-SA 3.0 Justin Filip 2
Supported environments
• The Vagrant application can be run inside the following host
environments:
• Windows / OS X / Linux (both DEB and RPM packages available)
• both 32 and 64 bit versions of each OS are supported
More or less any VM that can run in any of the supported
virtualization providers will run with Vagrant, provided you have a
compatible .box file.
CC BY-SA 3.0 Justin Filip 3
What's a .box file?
Some Vagrant concepts we will learn today:
• Boxes
• Provisioning
• Networking
• Synced Folders
• Providers
• Plugins
CC BY-SA 3.0 Justin Filip 4
Boxes
Basically a specially packaged VM image with some extra metadata
information contained inside to help control Vagrant.
CC BY-SA 3.0 Justin Filip 5
Provisioning
Steps that are run when the VM is initially created and can,
optionally, be re-run afterward. Supported provisioners:
• file uploads, inline shell scripts and files
• Ansible, Chef, Puppet, Salt
• ... and more!
CC BY-SA 3.0 Justin Filip 6
Networking
Allows for easy configuration of the network interfaces running
inside the VM. Makes it easy to configure:
• private internal IP addresses
• port forwarding
• connecting to public networks
CC BY-SA 3.0 Justin Filip 7
Synced Folders
Allows you to get folders from your machine into the Vagrant VM.
Supported methods (host OS dependent):
• NFS
• RSync
• SMB
• provider-specific shared folders (plugin dependent)
CC BY-SA 3.0 Justin Filip 8
Providers
The software runs the VM, including:
• VirtualBox
• VMWare
• Docker
• Hyper-V
• Parallels (with a plugin)
• Others, see wiki page
CC BY-SA 3.0 Justin Filip 9
Plugins
• Large list of available plugins in the Vagrant wiki
• Some examples I use:
• vagrant-vbguest -- automatically update VirtualBox guest
additions if necessary
• vagrant-cachier -- caches packages for different managers like
apt, yum, Rubygems, NPM, Bower, etc.
• vagrant-parallels -- allows running guests with Parallels on OS X
CC BY-SA 3.0 Justin Filip 10
Extras
Tools that are used to build Vagrant environments for you
• https://github.com/jedi4ever/veewee
• https://puphpet.com/
Running OS X guest VMs with Vagrant:
• https://github.com/AndrewDryga/vagrant-box-osx
• https://github.com/radeksimko/vagrant-osx
CC BY-SA 3.0 Justin Filip 11
Conventions for this workshop
Commands:
# Commands run in your native OS, prefixed with '$'
$ vagrant up
$ ls -aFh
# Commands run inside Vagrant VM, prefixed with '>'
> uname -a
> sudo apt-get update
CC BY-SA 3.0 Justin Filip 12
Requirements for this workshop
Required software (for your specific operating system):
• VirtualBox -- https://virtualbox.org/
• Vagrant -- https://vagrantup.com/
• GitBash -- https://git-scm.com/download/ (for Windows users
only)
CC BY-SA 3.0 Justin Filip 13
Our goal for today
We are going to create a Linux environment for doing Ruby on Rails
development:
1. Use Ubuntu Linux 14.04 (Trusty) running on VirtualBox (64 bit or 32 bit
depending on if whether you are running a 32bit / 64bit OS)
2. Use a simple, repeatable provisioning process to setup our environment
3. Install Ruby 2.2.3 and Postgres 9.3
4. Get a default Rails application up and running
CC BY-SA 3.0 Justin Filip 14
Let's Rock
CC BY-SA 3.0 Justin Filip 15
Step 1: Find a .box to start with
We are going to make our own custom environment so we will pick a base
box image that doesn't really have any extras pre-installed.
We will use the Atlas box search feature to find a base Ubuntu box. In your
browser, go to:
• https://vagrantcloud.com/boxes/search
• search for "ubuntu trusty64"
• optionally click the virtualbox provider filter to narrow the search
CC BY-SA 3.0 Justin Filip 16
Step 2: Initialize our Vagrantfile
We want to create a default machine just to make sure our
environment is working at all. In your command terminal (GitBash
for Windows users), enter the following commands:
$ mkdir vagrant-workshop
$ cd vagrant-workshop/
$ vagrant init ubuntu/trusty64
$ vagrant up --provider=virtualbox
CC BY-SA 3.0 Justin Filip 17
Step 3: Make sure everything is working fine
$ vagrant ssh
You should see a default Ubuntu login message.
You are now logged into your Vagrant VM. Enter the following:
> uname -a
Linux vagrant-ubuntu-trusty-64 3.13.0-65-generic
#106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015
x86_64 x86_64 x86_64 GNU/Linux
CC BY-SA 3.0 Justin Filip 18
Step 4: Start to customize our VM
Open your Vagrantfile with your favourite editor. Below the config.vm.box =
"ubuntu/trusty64" line, add the following:
# ruby22.sh
config.vm.provision 'shell', path: 'http://bit.ly/1GDfJrY'
# postgres9.sh
config.vm.provision 'shell', path: 'http://bit.ly/1R5ZEAy'
Save the file and run (from your host OS):
> exit
$ vagrant provision
CC BY-SA 3.0 Justin Filip 19
Step 5: Name the VM and setup our shared folder
Edit your Vagrantfile to add the following lines below what you
added in Step 4:
config.vm.hostname = 'rails-getting-started'
config.vm.synced_folder '.', '/vagrant'
Save the file and run (from your host OS):
$ vagrant reload
CC BY-SA 3.0 Justin Filip 20
Step 6: Redirect to shared folder on login
Edit your Vagrantfile to add the following lines below what you added
in:
config.vm.provision 'shell', inline: 'echo -e "ncd /vagrant" >> /home/vagrant/.bashrc'
Restart the VM, login and check where we end up:
$ vagrant provision
$ vagrant ssh
> pwd
/vagrant
CC BY-SA 3.0 Justin Filip 21
Step 7: Install Ruby on Rails
Create a new file Gemfile and enter the following inside of it:
source 'https://rubygems.org'
ruby '2.2.3'
gem 'rails', '4.2.4'
gem 'pg'
Inside of the VM, run:
> bundle install --path vendor/bundle
CC BY-SA 3.0 Justin Filip 22
Step 8: Create a new Rails application
Inside the VM:
> bundle exec rails new blog -d postgresql
Edit the file blog/Gemfile with your editor, uncomment the
following line and save the file:
# gem 'therubyracer', platforms: :ruby
CC BY-SA 3.0 Justin Filip 23
Step 9: Install packages and setup the database
Execute the following in the VM:
> cd blog/
> bundle install --path vendor/bundle
> bundle exec rake db:create db:migrate
CC BY-SA 3.0 Justin Filip 24
Step 10: Start the rails server
> bundle exec rails s
Great! Everything looks good here, we're probably done so let's go
to the URL that the server says it is running on:
• http://localhost:3000/
CC BY-SA 3.0 Justin Filip 25
Why didn't this work?
CC BY-SA 3.0 Justin Filip 26
Step 11: Forward a port into the VM
We need to forward a port into the VM from our host so we can
access it in the browser. Edit your Vagrantfile and add the
following line:
config.vm.network 'forwarded_port', guest: 3000, host: 3000
And then run:
$ vagrant reload
CC BY-SA 3.0 Justin Filip 27
Step 12: Start the rails server (again)
$ vagrant ssh
> cd blog/
> bundle exec rails s -b 0.0.0.0
Now, load the site up in your browser:
• http://localhost:3000/
CC BY-SA 3.0 Justin Filip 28
Success?
CC BY-SA 3.0 Justin Filip 29
(Un-)Fuck up the VM 1
$ vagrant ssh
> # Dangerous commands hidden to prevent disasters
> exit
$ vagrant reload
Whoops. The SSH command isn't responding. We messed up the VM
and prevented it from being bootable. That's bad.
CC BY-SA 3.0 Justin Filip 30
(Un-)Fuck up the VM 2
Fortunately our code lives outside of the VM so we can just recreate it
from scratch without loosing any work!
$ vagrant destroy -f
$ vagrant up
$ vagrant ssh
> cd blog/
> bundle install --path vendor/bundle
> bundle exec db:create db:migrate
> bundle exec rails s -b 0.0.0.0
CC BY-SA 3.0 Justin Filip 31
VM performance tuning
We are running a database server and a web server at the same time inside our VM. It
might be nice to use two CPUs to do this.
Edit your Vagrantfile to add:
config.vm.provider 'virtualbox' do |vb|
vb.cpus = 2
vb.memory = 1024
end
And run:
$ vagrant reload
CC BY-SA 3.0 Justin Filip 32
Want to continue?
Now that you have a Rails dev environment setup and configured,
you can follow along with the Rails Getting Started Guide, if you
wish:
• http://guides.rubyonrails.org/getting_started.html
CC BY-SA 3.0 Justin Filip 33
Resources
• Official Vagrant site
• Vagrant Support
• Atlas Vagrant Box Search
CC BY-SA 3.0 Justin Filip 34
Thanks!
Slides available at -- http://bit.ly/1VOzCmI
Code available at -- http://bit.ly/1Mm3hyG
CC BY-SA 3.0 Justin Filip 35

More Related Content

Recently uploaded

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 

Recently uploaded (20)

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Virtualize your dev workflow with Vagrant

  • 1. Virtually improve your dev workflow with Vagrant Justin Filip - @jfilip boltmade.com CC BY-SA 3.0 Justin Filip 1
  • 2. What even is Vagrant? Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the "works on my machine" excuse a relic of the past. -- official Vagrant docs CC BY-SA 3.0 Justin Filip 2
  • 3. Supported environments • The Vagrant application can be run inside the following host environments: • Windows / OS X / Linux (both DEB and RPM packages available) • both 32 and 64 bit versions of each OS are supported More or less any VM that can run in any of the supported virtualization providers will run with Vagrant, provided you have a compatible .box file. CC BY-SA 3.0 Justin Filip 3
  • 4. What's a .box file? Some Vagrant concepts we will learn today: • Boxes • Provisioning • Networking • Synced Folders • Providers • Plugins CC BY-SA 3.0 Justin Filip 4
  • 5. Boxes Basically a specially packaged VM image with some extra metadata information contained inside to help control Vagrant. CC BY-SA 3.0 Justin Filip 5
  • 6. Provisioning Steps that are run when the VM is initially created and can, optionally, be re-run afterward. Supported provisioners: • file uploads, inline shell scripts and files • Ansible, Chef, Puppet, Salt • ... and more! CC BY-SA 3.0 Justin Filip 6
  • 7. Networking Allows for easy configuration of the network interfaces running inside the VM. Makes it easy to configure: • private internal IP addresses • port forwarding • connecting to public networks CC BY-SA 3.0 Justin Filip 7
  • 8. Synced Folders Allows you to get folders from your machine into the Vagrant VM. Supported methods (host OS dependent): • NFS • RSync • SMB • provider-specific shared folders (plugin dependent) CC BY-SA 3.0 Justin Filip 8
  • 9. Providers The software runs the VM, including: • VirtualBox • VMWare • Docker • Hyper-V • Parallels (with a plugin) • Others, see wiki page CC BY-SA 3.0 Justin Filip 9
  • 10. Plugins • Large list of available plugins in the Vagrant wiki • Some examples I use: • vagrant-vbguest -- automatically update VirtualBox guest additions if necessary • vagrant-cachier -- caches packages for different managers like apt, yum, Rubygems, NPM, Bower, etc. • vagrant-parallels -- allows running guests with Parallels on OS X CC BY-SA 3.0 Justin Filip 10
  • 11. Extras Tools that are used to build Vagrant environments for you • https://github.com/jedi4ever/veewee • https://puphpet.com/ Running OS X guest VMs with Vagrant: • https://github.com/AndrewDryga/vagrant-box-osx • https://github.com/radeksimko/vagrant-osx CC BY-SA 3.0 Justin Filip 11
  • 12. Conventions for this workshop Commands: # Commands run in your native OS, prefixed with '$' $ vagrant up $ ls -aFh # Commands run inside Vagrant VM, prefixed with '>' > uname -a > sudo apt-get update CC BY-SA 3.0 Justin Filip 12
  • 13. Requirements for this workshop Required software (for your specific operating system): • VirtualBox -- https://virtualbox.org/ • Vagrant -- https://vagrantup.com/ • GitBash -- https://git-scm.com/download/ (for Windows users only) CC BY-SA 3.0 Justin Filip 13
  • 14. Our goal for today We are going to create a Linux environment for doing Ruby on Rails development: 1. Use Ubuntu Linux 14.04 (Trusty) running on VirtualBox (64 bit or 32 bit depending on if whether you are running a 32bit / 64bit OS) 2. Use a simple, repeatable provisioning process to setup our environment 3. Install Ruby 2.2.3 and Postgres 9.3 4. Get a default Rails application up and running CC BY-SA 3.0 Justin Filip 14
  • 15. Let's Rock CC BY-SA 3.0 Justin Filip 15
  • 16. Step 1: Find a .box to start with We are going to make our own custom environment so we will pick a base box image that doesn't really have any extras pre-installed. We will use the Atlas box search feature to find a base Ubuntu box. In your browser, go to: • https://vagrantcloud.com/boxes/search • search for "ubuntu trusty64" • optionally click the virtualbox provider filter to narrow the search CC BY-SA 3.0 Justin Filip 16
  • 17. Step 2: Initialize our Vagrantfile We want to create a default machine just to make sure our environment is working at all. In your command terminal (GitBash for Windows users), enter the following commands: $ mkdir vagrant-workshop $ cd vagrant-workshop/ $ vagrant init ubuntu/trusty64 $ vagrant up --provider=virtualbox CC BY-SA 3.0 Justin Filip 17
  • 18. Step 3: Make sure everything is working fine $ vagrant ssh You should see a default Ubuntu login message. You are now logged into your Vagrant VM. Enter the following: > uname -a Linux vagrant-ubuntu-trusty-64 3.13.0-65-generic #106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux CC BY-SA 3.0 Justin Filip 18
  • 19. Step 4: Start to customize our VM Open your Vagrantfile with your favourite editor. Below the config.vm.box = "ubuntu/trusty64" line, add the following: # ruby22.sh config.vm.provision 'shell', path: 'http://bit.ly/1GDfJrY' # postgres9.sh config.vm.provision 'shell', path: 'http://bit.ly/1R5ZEAy' Save the file and run (from your host OS): > exit $ vagrant provision CC BY-SA 3.0 Justin Filip 19
  • 20. Step 5: Name the VM and setup our shared folder Edit your Vagrantfile to add the following lines below what you added in Step 4: config.vm.hostname = 'rails-getting-started' config.vm.synced_folder '.', '/vagrant' Save the file and run (from your host OS): $ vagrant reload CC BY-SA 3.0 Justin Filip 20
  • 21. Step 6: Redirect to shared folder on login Edit your Vagrantfile to add the following lines below what you added in: config.vm.provision 'shell', inline: 'echo -e "ncd /vagrant" >> /home/vagrant/.bashrc' Restart the VM, login and check where we end up: $ vagrant provision $ vagrant ssh > pwd /vagrant CC BY-SA 3.0 Justin Filip 21
  • 22. Step 7: Install Ruby on Rails Create a new file Gemfile and enter the following inside of it: source 'https://rubygems.org' ruby '2.2.3' gem 'rails', '4.2.4' gem 'pg' Inside of the VM, run: > bundle install --path vendor/bundle CC BY-SA 3.0 Justin Filip 22
  • 23. Step 8: Create a new Rails application Inside the VM: > bundle exec rails new blog -d postgresql Edit the file blog/Gemfile with your editor, uncomment the following line and save the file: # gem 'therubyracer', platforms: :ruby CC BY-SA 3.0 Justin Filip 23
  • 24. Step 9: Install packages and setup the database Execute the following in the VM: > cd blog/ > bundle install --path vendor/bundle > bundle exec rake db:create db:migrate CC BY-SA 3.0 Justin Filip 24
  • 25. Step 10: Start the rails server > bundle exec rails s Great! Everything looks good here, we're probably done so let's go to the URL that the server says it is running on: • http://localhost:3000/ CC BY-SA 3.0 Justin Filip 25
  • 26. Why didn't this work? CC BY-SA 3.0 Justin Filip 26
  • 27. Step 11: Forward a port into the VM We need to forward a port into the VM from our host so we can access it in the browser. Edit your Vagrantfile and add the following line: config.vm.network 'forwarded_port', guest: 3000, host: 3000 And then run: $ vagrant reload CC BY-SA 3.0 Justin Filip 27
  • 28. Step 12: Start the rails server (again) $ vagrant ssh > cd blog/ > bundle exec rails s -b 0.0.0.0 Now, load the site up in your browser: • http://localhost:3000/ CC BY-SA 3.0 Justin Filip 28
  • 29. Success? CC BY-SA 3.0 Justin Filip 29
  • 30. (Un-)Fuck up the VM 1 $ vagrant ssh > # Dangerous commands hidden to prevent disasters > exit $ vagrant reload Whoops. The SSH command isn't responding. We messed up the VM and prevented it from being bootable. That's bad. CC BY-SA 3.0 Justin Filip 30
  • 31. (Un-)Fuck up the VM 2 Fortunately our code lives outside of the VM so we can just recreate it from scratch without loosing any work! $ vagrant destroy -f $ vagrant up $ vagrant ssh > cd blog/ > bundle install --path vendor/bundle > bundle exec db:create db:migrate > bundle exec rails s -b 0.0.0.0 CC BY-SA 3.0 Justin Filip 31
  • 32. VM performance tuning We are running a database server and a web server at the same time inside our VM. It might be nice to use two CPUs to do this. Edit your Vagrantfile to add: config.vm.provider 'virtualbox' do |vb| vb.cpus = 2 vb.memory = 1024 end And run: $ vagrant reload CC BY-SA 3.0 Justin Filip 32
  • 33. Want to continue? Now that you have a Rails dev environment setup and configured, you can follow along with the Rails Getting Started Guide, if you wish: • http://guides.rubyonrails.org/getting_started.html CC BY-SA 3.0 Justin Filip 33
  • 34. Resources • Official Vagrant site • Vagrant Support • Atlas Vagrant Box Search CC BY-SA 3.0 Justin Filip 34
  • 35. Thanks! Slides available at -- http://bit.ly/1VOzCmI Code available at -- http://bit.ly/1Mm3hyG CC BY-SA 3.0 Justin Filip 35