aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/osx/configuration/VagrantFile
blob: 1e1cce50f06c99728caf683eafaf6035a803ab47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'json'

require "erb"
include ERB::Util

configuration = JSON.parse(File.read('./vagrant-configuration.json'))

servers = configuration['machine_identifiers'].map do |id|
  {
    :hostname => "#{configuration['base_name']}-#{id}",
    :box => 'ramsey/macos-catalina',
    :ram => 12000,
    :cpu => 5
  }
end

brew_formulas = [
  'autoconf',
  'automake',
  'libtool',
  'bison' ]

brew_cask_formulas = [
  'powershell',
  'gfortran' ]

azure_agent_url = 'https://vstsagentpackage.azureedge.net/agent/2.171.1/vsts-agent-osx-x64-2.171.1.tar.gz'
devops_url = 'https://dev.azure.com/vcpkg'
agent_pool = 'vcpkgAgentPool'
pat = configuration['pat']
archives = configuration['archives']
archives_url = "//#{archives['username']}:#{url_encode(archives['access_key'])}@#{archives['urn']}/#{archives['share']}"

Vagrant.configure('2') do |config|
  # give them extra time to boot up
  config.vm.boot_timeout = 600

  servers.each do |machine|
    config.vm.define machine[:hostname] do |node|

      node.vm.box = machine[:box]
      node.vm.hostname = machine[:hostname]
      node.vm.synced_folder '.', '/vagrant', disabled: true

      diskname = "#{machine[:hostname]}-data.vmdk"

      # I don't like this, but as far as I can tell, it's the only way
      # to do this. When vagrant finishes the `disk` feature, switch
      # over to that -- Nicole Mazzuca
      if (not File.exists? diskname) then
        system "VBoxManage createmedium --filename #{diskname} --size #{1024 * 220}"
      end

      node.vm.provider 'virtualbox' do |vb|
        vb.memory = machine[:ram]
        vb.cpus = machine[:cpu]
        vb.customize ['modifyvm', :id, '--ioapic', 'on']
        vb.customize ['storageattach', :id,
          '--storagectl', 'SATA Controller',
          '--port', '1', '--device', '0', '--type', 'hdd',
          '--medium', "#{diskname}"
        ]
      end

      node.vm.provision 'shell',
        run: 'once',
        name: 'Format and mount the data filesystem',
        inline: 'diskutil partitionDisk /dev/disk0 1 GPT jhfs+ data 0',
        privileged: true

      node.vm.provision 'shell',
        run: 'once',
        name: 'Link the data filesystem to the home directory',
        inline: "ln -s /Volumes/data ~/Data",
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Download azure agent',
        inline: "curl -s -o ~/Downloads/azure-agent.tar.gz #{azure_agent_url}",
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Unpack azure agent',
        inline: 'mkdir myagent; cd myagent; tar xf ~/Downloads/azure-agent.tar.gz',
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Install brew and xcode command line tools',
        inline: '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"',
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Install brew applications',
        inline: "brew install #{brew_formulas.join(' ')} && brew cask install #{brew_cask_formulas.join(' ')}",
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Create archives mountpoint',
        inline: 'mkdir ~/Data/archives',
        privileged: false

      node.vm.provision "shell",
        run: 'once',
        name: 'Mount archives directory',
        inline: "mount_smbfs -d 777 -f 777 #{archives_url} ~/Data/archives",
        privileged: false

      node.vm.provision 'shell',
        run: 'once',
        name: 'Add VM to azure agent pool',
        inline: "cd ~/myagent;\
          ./config.sh --unattended \
            --url #{devops_url} \
            --work ~/Data/work \
            --auth pat --token #{pat} \
            --pool #{agent_pool} \
            --agent `hostname` \
            --replace \
            --acceptTeeEula",
        privileged: false

      # Start listening for jobs
      node.vm.provision 'shell',
        run: 'always',
        name: 'Start running azure pipelines',
        inline: 'cd /Users/vagrant/myagent;\
          nohup ./run.sh&',
        privileged: false
    end
  end
end