using vagrant

18
Using Vagrant Cuong Huynh @cuongdev AppsCyclone - Workshop - 2016.7.23

Upload: cuong-huynh

Post on 17-Jan-2017

179 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Using vagrant

Using VagrantCuong Huynh @cuongdev

AppsCyclone - Workshop - 2016.7.23

Page 2: Using vagrant

WHY VAGRANT?

Page 3: Using vagrant

Your development and production environment are not the same!

Page 4: Using vagrant

● Different OS

● Different version (PHP, …)

● Different default configuration files

Page 5: Using vagrant

● Vagrant lowers development environment setup time

● Maximizes dev/pro parity

Page 6: Using vagrant

GETSTARTED

Page 7: Using vagrant

Installation

Enabled Virtualization mode on Host machineInstall Oracle’s VirtualBoxhttps://www.virtualbox.org/wiki/Downloads Install Vagrant (for Windows, Mac, Linux)https://www.vagrantup.com/downloads.html

Page 8: Using vagrant

BoxCreate a box $vagrant box add [name] [location

of basebox]

$vagrant box add laravel/homestead

https://atlas.hashicorp.com/boxes/searchInitialise a project$vagrant init laravel/homestead

Page 9: Using vagrant

ConfigurationUsing the Vagrantfile that be created after run initialise projectVagrant.configure("2") do |config|

//…

End

Page 10: Using vagrant

ConfigurationDefine hostnameconfig.vm.hostname = "develop-server"

Define static IPconfig.vm.network "private_network", ip: "192.168.37.10"

Define synced folderconfig.vm.synced_folder ".", "/var/www"

Page 11: Using vagrant

ConfigurationDefine virtual machine configurationconfig.vm.provider "virtualbox" do |v|

v.gui = false v.memory = 2048 v.cpus = 1end

Page 12: Using vagrant

ConfigurationDefine Provisionconfig.vm.provision "shell", inline: <<-SHELL

sudo apt-get update sudo apt-get install -y whois git sudo useradd -m -p `mkpasswd password` -s /bin/bash dev sudo usermod -a -G sudo devSHELL

Page 13: Using vagrant

CommandsRun vagrant$vagrant up

Shutdown vagrant$vagrant halt

Destroy project box$vagrant destroy

Reload vagrant$vagrant reload

Connect vagrant$vagrant ssh

Page 14: Using vagrant

PackageStart with a Base box, customize it as neededRun command to package$vagrant package --output my_box.box

Other users can now use$vagrant box add my_box /path/to/my_box.box

$vagrant init my_box$vagrant up

Page 15: Using vagrant

Improve Vagrant on Windows

Page 16: Using vagrant

ProblemThe problem comes from shares. Using VirtualBox native sharing is horribly slow. You can use Windows sharing (SMB), but that is also painfully slow

Page 17: Using vagrant

FIXInstall WinNFSD Plugin vagrantvagrant plugin install vagrant-winnfsd

Details at: https://github.com/winnfsd/vagrant-winnfsd

Page 18: Using vagrant

FIXAdd configs

config.vm.network "private_network", type: "dhcp"

config.vm.synced_folder ".", "/var/www", type: "nfs"

Show log (optional)

Config.winnfsd.logging = “on”

After that, reload vagrant to apply new config. ENJOY IT !