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

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

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