4 required_plugins = %w( vagrant-hostmanager vagrant-vbguest )
5 required_plugins.each do |plugin|
6 exec "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
13 vagrantfile_dir_path = File.dirname(__FILE__)
16 local: vagrantfile_dir_path + '/vagrant/config/vagrant-local.yml',
17 example: vagrantfile_dir_path + '/vagrant/config/vagrant-local.example.yml'
20 # copy config from example if local config not exists
21 FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
23 options = YAML.load_file config[:local]
26 if options['github_token'].nil? || options['github_token'].to_s.length != 40
27 puts "You must place REAL GitHub token into configuration:\n/yii2-app-basic/vagrant/config/vagrant-local.yml"
32 Vagrant.configure(2) do |config|
34 config.vm.box = 'bento/ubuntu-16.04'
36 # should we ask about box updates?
37 config.vm.box_check_update = options['box_check_update']
39 config.vm.provider 'virtualbox' do |vb|
41 vb.cpus = options['cpus']
43 vb.memory = options['memory']
44 # machine name (for VirtualBox UI)
45 vb.name = options['machine_name']
48 # machine name (for vagrant console)
49 config.vm.define options['machine_name']
51 # machine name (for guest machine console)
52 config.vm.hostname = options['machine_name']
55 config.vm.network 'private_network', ip: options['ip']
57 # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
58 config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
60 # disable folder '/vagrant' (guest machine)
61 config.vm.synced_folder '.', '/vagrant', disabled: true
63 # hosts settings (host machine)
64 config.vm.provision :hostmanager
65 config.hostmanager.enabled = true
66 config.hostmanager.manage_host = true
67 config.hostmanager.ignore_private_ip = false
68 config.hostmanager.include_offline = true
69 config.hostmanager.aliases = domains.values
71 # quick fix for failed guest additions installations
72 # config.vbguest.auto_update = false
75 config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
76 config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
77 config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'
79 # post-install message (vagrant console)
80 config.vm.post_up_message = "App URL: http://#{domains[:app]}"