2020-07-02 01:08:06 +08:00
|
|
|
#!pwsh
|
|
|
|
#Requires -Version 6.0
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Sets up the configuration for the vagrant virtual machines.
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
Setup-VagrantMachines.ps1 sets up the virtual machines for
|
|
|
|
vcpkg's macOS CI. It puts the VagrantFile and necessary
|
|
|
|
configuration JSON file into ~/vagrant/vcpkg-eg-mac.
|
|
|
|
|
2020-09-25 06:15:06 +08:00
|
|
|
.PARAMETER MachineId
|
|
|
|
The number to give the machine; should match [0-9]{2}.
|
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
.PARAMETER DevopsPat
|
|
|
|
The personal access token which has Read & Manage permissions on the ADO pool.
|
|
|
|
|
|
|
|
.PARAMETER Date
|
|
|
|
The date on which this pool is being created. Sets the default values for BoxVersion and AgentPool.
|
|
|
|
|
2020-09-25 06:15:06 +08:00
|
|
|
.PARAMETER BoxVersion
|
2020-09-30 07:49:49 +08:00
|
|
|
The version of the box to use. If -Date is passed, uses that as the version.
|
2020-09-25 06:15:06 +08:00
|
|
|
|
|
|
|
.PARAMETER AgentPool
|
2020-09-30 07:49:49 +08:00
|
|
|
The agent pool to add the machine to. If -Date is passed, uses "PrOsx-$Date" as the pool.
|
2020-09-25 06:15:06 +08:00
|
|
|
|
|
|
|
.PARAMETER DevopsUrl
|
2020-09-30 07:49:49 +08:00
|
|
|
The URL of the ADO instance; defaults to vcpkg's, which is https://dev.azure.com/vcpkg.
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
.PARAMETER ArchivesMachine
|
|
|
|
The machine where the archives are located; a URN.
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
.PARAMETER ArchivesPath
|
|
|
|
The path to where the archives are located on the machine. If -Date is passed,
|
|
|
|
uses "/Users/${ArchivesUsername}/share/archives/${Date}".
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
.PARAMETER ArchivesUsername
|
|
|
|
The user to log in to on the archives machine. Defaults to 'fileshare'.
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
.PARAMETER BaseName
|
2020-09-25 06:15:06 +08:00
|
|
|
The base name for the vagrant VM; the machine name is $BaseName-$MachineId.
|
2020-07-02 01:08:06 +08:00
|
|
|
Defaults to 'vcpkg-eg-mac'.
|
|
|
|
|
2020-09-25 06:15:06 +08:00
|
|
|
.PARAMETER BoxName
|
|
|
|
The name of the box to use. Defaults to 'vcpkg/macos-ci',
|
|
|
|
which is only available internally.
|
|
|
|
|
2020-07-02 01:08:06 +08:00
|
|
|
.PARAMETER Force
|
|
|
|
Delete any existing vagrant/vcpkg-eg-mac directory.
|
|
|
|
|
|
|
|
.PARAMETER DiskSize
|
2020-09-30 07:49:49 +08:00
|
|
|
The size to make the temporary disks in gigabytes. Defaults to 350.
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
.INPUTS
|
|
|
|
None
|
|
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
None
|
|
|
|
#>
|
2020-09-30 07:49:49 +08:00
|
|
|
[CmdletBinding(PositionalBinding=$False, DefaultParameterSetName='DefineDate')]
|
2020-07-02 01:08:06 +08:00
|
|
|
Param(
|
2020-09-25 06:15:06 +08:00
|
|
|
[Parameter(Mandatory=$True)]
|
|
|
|
[String]$MachineId,
|
|
|
|
|
|
|
|
[Parameter(Mandatory=$True)]
|
2020-09-30 07:49:49 +08:00
|
|
|
[String]$DevopsPat,
|
2020-09-25 06:15:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$True, ParameterSetName='DefineDate')]
|
|
|
|
[String]$Date,
|
2020-09-25 06:15:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$True, ParameterSetName='DefineVersionAndAgentPool')]
|
|
|
|
[String]$BoxVersion,
|
2020-09-25 06:15:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$True, ParameterSetName='DefineVersionAndAgentPool')]
|
|
|
|
[String]$AgentPool,
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$False)]
|
|
|
|
[String]$DevopsUrl = 'https://dev.azure.com/vcpkg',
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
[Parameter(Mandatory=$True)]
|
2020-09-30 07:49:49 +08:00
|
|
|
[String]$ArchivesMachine,
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$True, ParameterSetName='DefineVersionAndAgentPool')]
|
|
|
|
[String]$ArchivesPath,
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
[Parameter(Mandatory=$False)]
|
|
|
|
[String]$ArchivesUsername = 'archivesshare',
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
[Parameter()]
|
|
|
|
[String]$BaseName = 'vcpkg-eg-mac',
|
|
|
|
|
|
|
|
[Parameter()]
|
2020-09-25 06:15:06 +08:00
|
|
|
[String]$BoxName = 'vcpkg/macos-ci',
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
[Parameter()]
|
2020-09-30 07:49:49 +08:00
|
|
|
[Int]$DiskSize = 350,
|
2020-07-02 01:08:06 +08:00
|
|
|
|
2020-09-25 06:15:06 +08:00
|
|
|
[Parameter()]
|
2020-09-30 07:49:49 +08:00
|
|
|
[Switch]$Force
|
2020-07-02 01:08:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
Set-StrictMode -Version 2
|
|
|
|
|
|
|
|
if (-not $IsMacOS) {
|
|
|
|
throw 'This script should only be run on a macOS host'
|
|
|
|
}
|
|
|
|
|
2020-09-30 07:49:49 +08:00
|
|
|
if (-not [String]::IsNullOrEmpty($Date)) {
|
|
|
|
$BoxVersion = $Date
|
|
|
|
$AgentPool = "PrOsx-$Date"
|
|
|
|
$ArchivesPath = "/Users/${ArchivesUsername}/share/archives/${Date}"
|
|
|
|
}
|
|
|
|
|
2020-09-25 06:15:06 +08:00
|
|
|
if (Test-Path '~/vagrant/vcpkg-eg-mac') {
|
2020-07-02 01:08:06 +08:00
|
|
|
if ($Force) {
|
|
|
|
Write-Host 'Deleting existing directories'
|
2020-09-25 06:15:06 +08:00
|
|
|
Remove-Item -Recurse -Force -Path '~/vagrant/vcpkg-eg-mac' | Out-Null
|
2020-07-02 01:08:06 +08:00
|
|
|
} else {
|
2020-09-25 06:15:06 +08:00
|
|
|
throw '~/vagrant/vcpkg-eg-mac already exists; try re-running with -Force'
|
2020-07-02 01:08:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host 'Creating new directories'
|
2020-09-30 07:49:49 +08:00
|
|
|
if (-not (Test-Path -Path '~/vagrant')) {
|
2020-09-25 06:15:06 +08:00
|
|
|
New-Item -ItemType 'Directory' -Path '~/vagrant' | Out-Null
|
|
|
|
}
|
2020-07-02 01:08:06 +08:00
|
|
|
New-Item -ItemType 'Directory' -Path '~/vagrant/vcpkg-eg-mac' | Out-Null
|
|
|
|
|
|
|
|
Copy-Item `
|
2020-09-25 06:15:06 +08:00
|
|
|
-Path "$PSScriptRoot/configuration/Vagrantfile" `
|
|
|
|
-Destination '~/vagrant/vcpkg-eg-mac/Vagrantfile'
|
2020-07-02 01:08:06 +08:00
|
|
|
|
|
|
|
$configuration = @{
|
2020-09-30 07:49:49 +08:00
|
|
|
pat = $DevopsPat;
|
2020-09-25 06:15:06 +08:00
|
|
|
agent_pool = $AgentPool;
|
|
|
|
devops_url = $DevopsUrl;
|
|
|
|
machine_name = "${BaseName}-${MachineId}";
|
|
|
|
box_name = $BoxName;
|
|
|
|
box_version = $BoxVersion;
|
2020-07-02 01:08:06 +08:00
|
|
|
disk_size = $DiskSize;
|
|
|
|
archives = @{
|
|
|
|
username = $ArchivesUsername;
|
2020-09-30 07:49:49 +08:00
|
|
|
urn = $ArchivesMachine;
|
|
|
|
path = $ArchivesPath;
|
2020-07-02 01:08:06 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
ConvertTo-Json -InputObject $configuration -Depth 5 `
|
|
|
|
| Set-Content -Path '~/vagrant/vcpkg-eg-mac/vagrant-configuration.json'
|