authserver/homestead/scripts/homestead.rb
author durandn
Mon, 02 Nov 2015 16:03:59 +0100
changeset 176 ba9f193121c3
parent 8 5a0cbbe0922a
permissions -rw-r--r--
Adjustements on Markers scenario (now displays a "teacher" markers row) + Added a new "markers_teacher" scenario to edit the teacher markers and browse user markers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     1
class Homestead
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     2
  def Homestead.configure(config, settings)
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     3
    # Set The VM Provider
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     4
    ENV['VAGRANT_DEFAULT_PROVIDER'] = settings["provider"] ||= "virtualbox"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     5
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     6
    # Configure Local Variable To Access Scripts From Remote Location
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     7
    scriptDir = File.dirname(__FILE__)
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     8
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
     9
    # Prevent TTY Errors
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    10
    config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    11
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    12
    # Configure The Box
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    13
    config.vm.box = "laravel/homestead"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    14
    config.vm.hostname = "homestead"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    15
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    16
    # Configure A Private Network IP
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    17
    config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    18
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    19
    # Configure A Few VirtualBox Settings
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    20
    config.vm.provider "virtualbox" do |vb|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    21
      vb.name = 'homestead'
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    22
      vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    23
      vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    24
      vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    25
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    26
      vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    27
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    28
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    29
    # Configure A Few VMware Settings
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    30
    ["vmware_fusion", "vmware_workstation"].each do |vmware|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    31
      config.vm.provider vmware do |v|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    32
        v.vmx["displayName"] = "homestead"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    33
        v.vmx["memsize"] = settings["memory"] ||= 2048
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    34
        v.vmx["numvcpus"] = settings["cpus"] ||= 1
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    35
        v.vmx["guestOS"] = "ubuntu-64"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    36
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    37
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    38
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    39
    # Configure Port Forwarding To The Box
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    40
    config.vm.network "forwarded_port", guest: 80, host: 8000
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    41
    config.vm.network "forwarded_port", guest: 443, host: 44300
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    42
    config.vm.network "forwarded_port", guest: 3306, host: 33060
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    43
    config.vm.network "forwarded_port", guest: 5432, host: 54320
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    44
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    45
    # Add Custom Ports From Configuration
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    46
    if settings.has_key?("ports")
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    47
      settings["ports"].each do |port|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    48
        config.vm.network "forwarded_port", guest: port["guest"] || port["to"], host: port["host"] || port["send"], protocol: port["protocol"] ||= "tcp"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    49
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    50
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    51
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    52
    # Configure The Public Key For SSH Access
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    53
    if settings.include? 'authorize'
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    54
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    55
        s.inline = "echo $1 | grep -xq \"$1\" /home/vagrant/.ssh/authorized_keys || echo $1 | tee -a /home/vagrant/.ssh/authorized_keys"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    56
        s.args = [File.read(File.expand_path(settings["authorize"]))]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    57
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    58
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    59
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    60
    # Copy The SSH Private Keys To The Box
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    61
    if settings.include? 'keys'
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    62
      settings["keys"].each do |key|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    63
        config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    64
          s.privileged = false
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    65
          s.inline = "echo \"$1\" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    66
          s.args = [File.read(File.expand_path(key)), key.split('/').last]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    67
        end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    68
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    69
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    70
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    71
    # Register All Of The Configured Shared Folders
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    72
    if settings.include? 'folders'
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    73
      settings["folders"].each do |folder|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    74
        mount_opts = folder["type"] == "nfs" ? ['actimeo=1'] : []
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    75
        config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil, mount_options: mount_opts
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    76
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    77
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    78
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    79
    # Install All The Configured Nginx Sites
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    80
    settings["sites"].each do |site|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    81
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    82
          if (site.has_key?("hhvm") && site["hhvm"])
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    83
            s.path = scriptDir + "/serve-hhvm.sh"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    84
            s.args = [site["map"], site["to"], site["port"] ||= "80", site["ssl"] ||= "443"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    85
          else
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    86
            s.path = scriptDir + "/serve.sh"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    87
            s.args = [site["map"], site["to"], site["port"] ||= "80", site["ssl"] ||= "443"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    88
          end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    89
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    90
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    91
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    92
    # Configure All Of The Configured Databases
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    93
    settings["databases"].each do |db|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    94
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    95
        s.path = scriptDir + "/create-mysql.sh"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    96
        s.args = [db]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    97
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    98
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
    99
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   100
        s.path = scriptDir + "/create-postgres.sh"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   101
        s.args = [db]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   102
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   103
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   104
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   105
    # Configure All Of The Server Environment Variables
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   106
    if settings.has_key?("variables")
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   107
      settings["variables"].each do |var|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   108
        config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   109
          s.inline = "echo \"\nenv[$1] = '$2'\" >> /etc/php5/fpm/php-fpm.conf"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   110
          s.args = [var["key"], var["value"]]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   111
        end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   112
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   113
        config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   114
            s.inline = "echo \"\n#Set Homestead environment variable\nexport $1=$2\" >> /home/vagrant/.profile"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   115
            s.args = [var["key"], var["value"]]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   116
        end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   117
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   118
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   119
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   120
        s.inline = "service php5-fpm restart"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   121
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   122
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   123
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   124
    # Update Composer On Every Provision
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   125
    config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   126
      s.inline = "/usr/local/bin/composer self-update"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   127
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   128
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   129
    # Configure Blackfire.io
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   130
    if settings.has_key?("blackfire")
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   131
      config.vm.provision "shell" do |s|
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   132
        s.path = scriptDir + "/blackfire.sh"
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   133
        s.args = [
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   134
          settings["blackfire"][0]["id"],
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   135
          settings["blackfire"][0]["token"],
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   136
          settings["blackfire"][0]["client-id"],
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   137
          settings["blackfire"][0]["client-token"]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   138
        ]
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   139
      end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   140
    end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   141
  end
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents:
diff changeset
   142
end