Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vagrant for real

Vagrant for real

Vagrant is a well-known tool for creating development environments in a simple and consistent way. Since we adopted in our organization we experienced several benefits: lower project setup times, better shared knowledge among team members, less wtf moments ;-)In this session we’d like to share our experience, including but not limited to:advanced vagrantfile configurationvm configuration tips for dev environment: performance, debug, tuningour wtf momentspuphet/phansilbe: hot or not?packaging a box

Riccardo

June 01, 2015
Tweet

More Decks by Riccardo

Other Decks in Programming

Transcript

  1. require ‘yaml' _config = YAML.load(File.open(File.join(File.dirname(__FILE__), “vagrantfile-local-config.yml”), File::RDONLY).read) CONF = _config

    config.vm.provider "virtualbox" do |vb| vb.customize["modifyvm",:id,“--memory", CONF["ram"]] vb.customize ["modifyvm",:id,"--cpus", CONF[“cpus"]] … end
  2. As rule of thumb you could assign the half cpus

    and a quarter of the memory based on your host machine https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck
  3. Default provider: virtualbox 3 PHP test suites with unit, functional,

    integration mix small (sf1): build runs in ~25 sec medium (zf2): build runs in ~2 mins large (sf2): build runs ~ 20 mins
  4. class AppKernel extends Kernel { public function getCacheDir() { if

    (in_array($this->environment, array('dev', 'test'))) { return '/dev/shm/appname/cache/' . $this->environment; } return parent::getCacheDir(); } public function getLogDir() { if (in_array($this->environment, array('dev', ‘test'))) { return '/dev/shm/appname/logs'; } return parent::getLogDir(); } } #tip: moveiofromshared
  5. class AppKernel extends Kernel { public function getCacheDir() { if

    (in_array($this->environment, array('dev', 'test'))) { return '/dev/shm/appname/cache/' . $this->environment; } return parent::getCacheDir(); } public function getLogDir() { if (in_array($this->environment, array('dev', ‘test'))) { return '/dev/shm/appname/logs'; } return parent::getLogDir(); } } #tip: moveiofromshared
  6. class { public function { { } public function {

    { } } #tip: moveiofromshared +13-16%
  7. if Vagrant.has_plugin?("vagrant-cachier") config.cache.scope = :box config.cache.synced_folder_opts = { type: :nfs,

    mount_options: ['rw','vers=3','tcp','nolock'] } end #tip: moveiofromshared Vagrantfile
  8. #tip: cachefilesd - name: Install cachefilesd apt: pkg=cachefilesd state=present -

    name: Enable cachefilesd lineinfile: dest=/etc/default/cachefilesd line=“RUN=yes” - name: Start cachefilesd service service: name=cachefilesd state=restarted
  9. - name: add mysql user mysql_user: name=ideato host='%' password=ideato priv=*.*:ALL,GRANT

    login_user=root login_password= - name: config bind address to allow remote remote connections lineinfile: dest=/etc/mysql/my.cnf state=present regexp='bind-address = 127\.0\.0\.1' line='bind-address = 0\.0\.0\.0' backup=yes - name: restart mysql service: name=mysql state=restarted
  10. - name: Install phpmyadmin apt: pkg=phpmyadmin state=present - name: Include

    phpmyadmin in Apache config lineinfile: dest=/etc/apache2/apache2.conf line="Include /etc/phpmyadmin apache.conf" notify: restart apache
  11. - name: adminer clone git: repo=https://github.com/vrana/adminer.git dest=/var/www/adminer version=v4.2.1 accept_hostkey=true -

    name: adminer compile command: php compile.php chdir=/var/www/adminer creates=/var/www/adminer/adminer-4.2.1.php
  12. • quick and easy way to start • they’re general

    • old platforms are not supported • a lot of a good ideas you can steal from • on the long run move to your own template #tip: provisioningtpls
  13. #tip: provisioningtpls if which('ansible-playbook') config.vm.provision "ansible" do |ansible| ansible.playbook =

    "ansible/playbook.yml" ansible.inventory_path = "ansible/inventories/dev" ansible.limit = 'all' ansible.extra_vars = { private_interface: "192.168.33.99", hostname: "default" } end else config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"] end
  14. can you assume everyone in your team have the same

    version? #tip: provisioningtpls
  15. #tip: provisioningtpls if which('ansible-playbook') config.vm.provision "ansible" do |ansible| ansible.playbook =

    "ansible/playbook.yml" ansible.inventory_path = "ansible/inventories/dev" ansible.limit = 'all' ansible.extra_vars = { private_interface: "192.168.33.99", hostname: "default" } end else config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"] end
  16. #tip: provisioningtpls config.vm.provision :shell, :path => "scripts/bootstrap.sh", :args => "/var/www"

    config.vm.provision :shell, :path => “scripts/provision.sh", :args => "/var/www"
  17. you’re in control of provisioning command you can perform additional

    checks on host machine #tip: provisioningtpls
  18. live on the edge and fix provision script use stable

    package repositories #tip: packaging