Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
10. Vagrant
Vagrant is an invaluable tool for creating standardized virtual environments that
make it incredibly easy to bring on new developers.
+
For Windows +
vagrant plugin install vagrant-winnfsd
11. Remember 5 Commands:
$ vagrant init # Initialize Vagrant
$ vagrant up # Boot up
$ vagrant halt # Shutdown
$ vagrant destroy #Destroy vm
$ vagrant ssh # connect via ssh
Files:
Vagrantfile # Vagrant configuration file
.vagrant folder # Must be in .gitignore
Vagrant
13. Boxes
Vagrant uses a base image to quickly clone a virtual machine. These base
images are known as boxes in Vagrant, and specifying the box to use for your
Vagrant environment is always the first step after creating a new Vagrantfile.
$ vagrant box add {title} {url} # Add box
$ vagrant box list # List box files
Find boxes:
https://atlas.hashicorp.com/boxes/search
http://www.vagrantbox.es/
Vagrant
14. Provisioners in Vagrant allow you to automatically install software, alter
configurations, and more on the machine as part of the vagrant up process.
Provisioners:
• Shell;
• Chef;
• Puppet;
• Ansible;
• Salt;
• Docker;
Provisioners
16. Provisioners
Chef is a configuration management tool written in Ruby and Erlang. It uses
pure-Ruby, domain-specific language (DSL) for writing system configuration
"recipes".
21. Pluses:
1. Easy sharing with project repository;
2. Simple usage;
3. Provisioners;
4. Clean host OS;
5. Same env configuration for all project teams;
Minuses:
1. Virtualbox performance;
2. Not very friendly with Windows (Virtualbox issue, NFS, ssh, chef);
3. Configuration;
4. Buggy sometimes;
Recommendation:
1. Use all CPU cores and half of system memory;
2. Use the NFS;
Summary
I am going to tell you about Vagrant; If you have any questions, please feel free to asks me during the presentation.
In the first part I will tell you about the problems that Vagrant can solve, in the second part I will tell about Vagrant :) and in the last part - about its provisioners.
Usually on one project in one team there are always different dev environments. Someone uses Windows, someone Ubuntu 13.10, someone 14.04, or even OS X. And yes, sometimes we can hear: “This works on my machine, I don’t know why you have a problem with my code”, “I can’t do this, I use OS X and there are no libraries for this task”, etc
Ok, imagine that we have the following project...
And another one...
And another one...
So, as you can see our projects are different, maybe you can handle the first and second project, but for the third project you must set up a totally different environment . Sometimes the project has dependencies with some libraries, and libraries from one project can conflict with libraries from another one, etc
And usually even though you spend hours for the first setup project on your machine, git clone isn’t enough. You read instructions, ask guru (or other developers), etc. Sometimes it’s a painful process and can stall all your day and even evening.
Solution of all this problems is virtualisation. For each project you have own virtual OS (guest OS), with all stack that you need for your project. And in Host OS you just have a browser, skype, atom (editor), etc. And yes, Vagrant helps you to manage/create this virtual OS, install soft on it, etc
Vagrant is….
You need just VirtualBox, Vagrant (available to Windows, Linux and OS X). If you use Windows you need install also Putty or Cygwin (for ssh connect to your OS). And also plugin for windows nfs support.
In Vagrantfile you can setup IP, guest and host port, synced folder (in this example folder with project mounts to guest OS on /vagrant path). nfs: true you enable nfs (nfs special protocol that used for mount folder), it increases performance in 2x times. Also you can configure how much RAM and CPU cores you guest OS will use. In this example if you on Linux your guest OS will use half of RAM, and all CPU cores. If you on WIndows, just 2 cores and 1 Gb RAM. And you set box. About boxes on next slide…..
Boxes are special images of OS that create for Vagrant. For each OS there exists a box. There are a few websites where you can download them. Also you can install for example base Ubuntu 14.04 install all soft that you need, then run command vagrant package. This command creates from your os box, and you can share it, for example upload to dropbox and share it. And there are boxes that create other developers for example for php or rail development.
we have a few provisioners…..
You just have a shell file with commands, and vagrant runs it and installs all that soft that you need.
Chef is a very powerful tool. There are Chef Solo and Chef Server (Dev OPS guys knows), vagrant use Chef Solo. How it works is a topic of another presentation
Chef has cookbooks and you add it in your vagrant file. For example in this example we have rvm, git, nodejs, etc
But first you need get this cookbooks and put them into your project folder. There are gems for that, or you can just manually download them.
And config of cookbooks, For example you set up ruby 2.2.0 and 2.1.4, postgres with configuration. And after the first vagrant up or after vagrant provision it installs all soft to your OS.
Vagrant support VMware but it costs 79$ and you must have WMware workstation that is also not free.