Yii 2.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4KB

  1. require 'yaml'
  2. require 'fileutils'
  3. domains = {
  4. frontend: 'y2aa-frontend.dev',
  5. backend: 'y2aa-backend.dev'
  6. }
  7. config = {
  8. local: './vagrant/config/vagrant-local.yml',
  9. example: './vagrant/config/vagrant-local.example.yml'
  10. }
  11. # copy config from example if local config not exists
  12. FileUtils.cp config[:example], config[:local] unless File.exist?(config[:local])
  13. # read config
  14. options = YAML.load_file config[:local]
  15. # check github token
  16. if options['github_token'].nil? || options['github_token'].to_s.length != 40
  17. puts "You must place REAL GitHub token into configuration:\n/yii2-app-advancded/vagrant/config/vagrant-local.yml"
  18. exit
  19. end
  20. # vagrant configurate
  21. Vagrant.configure(2) do |config|
  22. # select the box
  23. config.vm.box = 'ubuntu/trusty64'
  24. # should we ask about box updates?
  25. config.vm.box_check_update = options['box_check_update']
  26. config.vm.provider 'virtualbox' do |vb|
  27. # machine cpus count
  28. vb.cpus = options['cpus']
  29. # machine memory size
  30. vb.memory = options['memory']
  31. # machine name (for VirtualBox UI)
  32. vb.name = options['machine_name']
  33. end
  34. # machine name (for vagrant console)
  35. config.vm.define options['machine_name']
  36. # machine name (for guest machine console)
  37. config.vm.hostname = options['machine_name']
  38. # network settings
  39. config.vm.network 'private_network', ip: options['ip']
  40. # sync: folder 'yii2-app-advanced' (host machine) -> folder '/app' (guest machine)
  41. config.vm.synced_folder './', '/app', owner: 'vagrant', group: 'vagrant'
  42. # disable folder '/vagrant' (guest machine)
  43. config.vm.synced_folder '.', '/vagrant', disabled: true
  44. # hosts settings (host machine)
  45. config.vm.provision :hostmanager
  46. config.hostmanager.enabled = true
  47. config.hostmanager.manage_host = true
  48. config.hostmanager.ignore_private_ip = false
  49. config.hostmanager.include_offline = true
  50. config.hostmanager.aliases = domains.values
  51. # provisioners
  52. config.vm.provision 'shell', path: './vagrant/provision/once-as-root.sh', args: [options['timezone']]
  53. config.vm.provision 'shell', path: './vagrant/provision/once-as-vagrant.sh', args: [options['github_token']], privileged: false
  54. config.vm.provision 'shell', path: './vagrant/provision/always-as-root.sh', run: 'always'
  55. # post-install message (vagrant console)
  56. config.vm.post_up_message = "Frontend URL: http://#{domains[:frontend]}\nBackend URL: http://#{domains[:backend]}"
  57. end