OSDN Git Service

Добавлен тест модели типов.
[invent/invent.git] / Vagrantfile
1 require 'yaml'
2 require 'fileutils'
3
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
7 end
8
9 domains = {
10   app: 'yii2basic.test'
11 }
12
13 vagrantfile_dir_path = File.dirname(__FILE__)
14
15 config = {
16   local: vagrantfile_dir_path + '/vagrant/config/vagrant-local.yml',
17   example: vagrantfile_dir_path + '/vagrant/config/vagrant-local.example.yml'
18 }
19
20 # copy config from example if local config not exists
21 FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
22 # read config
23 options = YAML.load_file config[:local]
24
25 # check github token
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"
28   exit
29 end
30
31 # vagrant configurate
32 Vagrant.configure(2) do |config|
33   # select the box
34   config.vm.box = 'bento/ubuntu-16.04'
35
36   # should we ask about box updates?
37   config.vm.box_check_update = options['box_check_update']
38
39   config.vm.provider 'virtualbox' do |vb|
40     # machine cpus count
41     vb.cpus = options['cpus']
42     # machine memory size
43     vb.memory = options['memory']
44     # machine name (for VirtualBox UI)
45     vb.name = options['machine_name']
46   end
47
48   # machine name (for vagrant console)
49   config.vm.define options['machine_name']
50
51   # machine name (for guest machine console)
52   config.vm.hostname = options['machine_name']
53
54   # network settings
55   config.vm.network 'private_network', ip: options['ip']
56
57   # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
58   config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
59
60   # disable folder '/vagrant' (guest machine)
61   config.vm.synced_folder '.', '/vagrant', disabled: true
62
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
70
71   # quick fix for failed guest additions installations
72   # config.vbguest.auto_update = false
73
74   # provisioners
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'
78
79   # post-install message (vagrant console)
80   config.vm.post_up_message = "App URL: http://#{domains[:app]}"
81 end