require 'securerandom' module DevenvBuild module Files class Vagrantfile < Base def filename File.join(options[:destination_directory], 'Vagrantfile') end def template <<-EOF # -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = '2' VAGRANT_BOX_NAME = '#{box_name}' VAGRANT_PROVIDER = :virtualbox PROVIDERS = { virtualbox: { box: 'ubuntu/xenial64', shared_folder: [ '.', '/vagrant', type: 'nfs' ], configuration: proc do |v| v.name = VAGRANT_BOX_NAME v.memory = 1024 v.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] v.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] end }, parallels: { box: 'parallels/ubuntu-16.04', shared_folder: [ '.', '/vagrant'], configuration: proc do |v| v.name = VAGRANT_BOX_NAME v.memory = 1024 v.update_guest_tools = true end } } Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = PROVIDERS[VAGRANT_PROVIDER][:box] config.vm.network "private_network", ip: "192.168.50.4" config.vm.network "forwarded_port", guest: 3000, host: 3000 config.vm.network "forwarded_port", guest: 7000, host: 7000 config.vm.network "forwarded_port", guest: 8000, host: 8000 config.ssh.forward_agent = true config.vm.provision "shell", path: "provision/provision.sh" config.vm.synced_folder(*PROVIDERS[VAGRANT_PROVIDER][:shared_folder]) config.vm.provider VAGRANT_PROVIDER, &PROVIDERS[VAGRANT_PROVIDER][:configuration] end EOF end private def box_name options[:box_name] || "Development Environment #{SecureRandom.uuid}" end end end end