Skip to content

Commit

Permalink
[vcpkg ci] add macos scripts to vcpkg repo (#12172)
Browse files Browse the repository at this point in the history
* [vcpkg ci] add macos scripts to vcpkg repo

* CR changes

* docs stuff
  • Loading branch information
strega-nil authored Jul 1, 2020
1 parent c8ebb5a commit 0084acc
Show file tree
Hide file tree
Showing 9 changed files with 668 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,4 @@ __pycache__/
archives
.DS_Store
prefab/
*.swp
80 changes: 80 additions & 0 deletions scripts/azure-pipelines/osx/Install-Prerequisites.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!pwsh
#Requires -Version 6.0

<#
.SYNOPSIS
Installs the set of prerequisites for the macOS CI hosts.
.DESCRIPTION
Install-Prerequisites.ps1 installs all of the necessary prerequisites
to run the vcpkg macOS CI in a vagrant virtual machine,
skipping all prerequisites that are already installed.
.PARAMETER Force
Don't skip the prerequisites that are already installed.
.INPUTS
None
.OUTPUTS
None
#>
[CmdletBinding()]
Param(
[Parameter()]
[Switch]$Force
)

Set-StrictMode -Version 2

if (-not $IsMacOS) {
Write-Error 'This script should only be run on a macOS host'
throw
}

Import-Module "$PSScriptRoot/Utilities.psm1"

$Installables = Get-Content "$PSScriptRoot/configuration/installables.json" | ConvertFrom-Json

$Installables.Applications | ForEach-Object {
if (-not (Get-CommandExists $_.TestCommand)) {
Write-Host "$($_.Name) not installed; installing now"
} elseif ($Force) {
Write-Host "$($_.Name) found; attempting to upgrade or re-install"
} else {
Write-Host "$($_.Name) already installed"
return
}

$pathToDmg = "~/Downloads/$($_.Name).dmg"
Get-RemoteFile -OutFile $pathToDmg -Uri $_.DmgUrl -Sha256 $_.Sha256

hdiutil attach $pathToDmg -mountpoint /Volumes/setup-installer
sudo installer -pkg "/Volumes/setup-installer/$($_.InstallerPath)" -target /
hdiutil detach /Volumes/setup-installer
}

# Install plugins
$installedExtensionPacks = Get-InstalledVirtualBoxExtensionPacks

$Installables.VBoxExtensions | ForEach-Object {
$extension = $_
$installedExts = $installedExtensionPacks | Where-Object { $_.Pack -eq $extension.FullName -and $_.Usable -eq 'true' }

if ($null -eq $installedExts) {
Write-Host "VBox extension: $($extension.Name) not installed; installing now"
} elseif ($Force) {
Write-Host "VBox extension: $($extension.Name) found; attempting to upgrade or re-install"
} else {
Write-Host "VBox extension: $($extension.Name) already installed"
return
}

$pathToExt = "~/Downloads/$($extension.FullName -replace ' ','_').vbox-extpack"

Get-RemoteFile -OutFile $pathToExt -Uri $extension.Url -Sha256 $extension.Sha256 | Out-Null

Write-Host 'Attempting to install extension with sudo; you may need to enter your password'
sudo VBoxManage extpack install --replace $pathToExt
sudo VBoxManage extpack cleanup
}
69 changes: 69 additions & 0 deletions scripts/azure-pipelines/osx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# `vcpkg-eg-mac` VMs

## Table of Contents

- [`vcpkg-eg-mac` VMs](#vcpkg-eg-mac-vms)
- [Table of Contents](#table-of-contents)
- [Basic Usage](#basic-usage)
- [Setting up a new macOS machine](#setting-up-a-new-macos-machine)

## Basic Usage

The simplest usage, and one which should be used for when spinning up
new VMs, and when restarting old ones, is a simple:

```
$ cd ~/vagrant/vcpkg-eg-mac
$ vagrant up
```

Any modifications to the machines should be made in `configuration/VagrantFile`
and `Setup-VagrantMachines.ps1`, and make sure to push any changes!

## Setting up a new macOS machine

Before anything else, one must download `brew` and `powershell`.

```sh
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew cask install powershell
```

Then, we need to download the `vcpkg` repository:

```sh
$ git clone https:/microsoft/vcpkg
```

And now all we need to do is set it up! Replace `XX` with the number of
the virtual machine. Generally, that should be the same as the number
for the physical machine; i.e., vcpkgmm-04 will have vcpkg-eg-mac-04.

```sh
$ cd vcpkg/scripts/azure-pipelines/osx
$ ./Install-Prerequisites.ps1 -Force
# NOTE: you may get an error about CoreCLR; see the following paragraph if you do
$ ./Setup-VagrantMachines.ps1 XX \
-Pat '<get this from azure>' \
-ArchivesUsername '<get this from the archives share>' \
-ArchivesAccessKey '<get this from the archives share>' \
-ArchivesUrn '<something>.file.core.windows.net' \
-ArchivesShare 'archives'
$ cd ~/vagrant/vcpkg-eg-mac
$ vagrant up
```

If you see the following error:

```
Failed to initialize CoreCLR, HRESULT: 0x8007001F
```

You have to reboot the machine; run

```sh
$ sudo shutdown -r now
```

and wait for the machine to start back up. Then, start again from
`Install-Prerequisites.ps1`.
113 changes: 113 additions & 0 deletions scripts/azure-pipelines/osx/Setup-VagrantMachines.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!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.
.PARAMETER Pat
The personal access token which has Read & Manage permissions on the ADO pool.
.PARAMETER ArchivesUsername
The username for the archives share.
.PARAMETER ArchivesAccessKey
The access key for the archives share.
.PARAMETER ArchivesUri
The URN of the archives share; looks like `foo.windows.core.net`.
.PARAMETER ArchivesShare
The archives share name.
.PARAMETER BaseName
The base name for the vagrant VM; the machine name is $BaseName-$MachineIdentifiers.
Defaults to 'vcpkg-eg-mac'.
.PARAMETER Force
Delete any existing vagrant/vcpkg-eg-mac directory.
.PARAMETER DiskSize
The size to make the temporary disks in gigabytes. Defaults to 425.
.PARAMETER MachineIdentifiers
The numbers to give the machines; should match [0-9]{2}.
.INPUTS
None
.OUTPUTS
None
#>
[CmdletBinding(PositionalBinding=$False)]
Param(
[Parameter(Mandatory=$True)]
[String]$Pat,

[Parameter(Mandatory=$True)]
[String]$ArchivesUsername,

[Parameter(Mandatory=$True)]
[String]$ArchivesAccessKey,

[Parameter(Mandatory=$True)]
[String]$ArchivesUrn,

[Parameter(Mandatory=$True)]
[String]$ArchivesShare,

[Parameter()]
[String]$BaseName = 'vcpkg-eg-mac',

[Parameter()]
[Switch]$Force,

[Parameter()]
[Int]$DiskSize = 425,

[Parameter(Mandatory=$True, ValueFromRemainingArguments)]
[String[]]$MachineIdentifiers
)

Set-StrictMode -Version 2

if (-not $IsMacOS) {
throw 'This script should only be run on a macOS host'
}

if (Test-Path '~/vagrant') {
if ($Force) {
Write-Host 'Deleting existing directories'
Remove-Item -Recurse -Force -Path '~/vagrant' | Out-Null
} else {
throw '~/vagrant already exists; try re-running with -Force'
}
}

Write-Host 'Creating new directories'
New-Item -ItemType 'Directory' -Path '~/vagrant' | Out-Null
New-Item -ItemType 'Directory' -Path '~/vagrant/vcpkg-eg-mac' | Out-Null

Copy-Item `
-Path "$PSScriptRoot/configuration/VagrantFile" `
-Destination '~/vagrant/vcpkg-eg-mac/VagrantFile'

$configuration = @{
pat = $Pat;
base_name = $BaseName;
machine_identifiers = $MachineIdentifiers;
disk_size = $DiskSize;
archives = @{
username = $ArchivesUsername;
access_key = $ArchivesAccessKey;
url = $ArchivesUri;
share = $ArchivesShare;
};
}
ConvertTo-Json -InputObject $configuration -Depth 5 `
| Set-Content -Path '~/vagrant/vcpkg-eg-mac/vagrant-configuration.json'
Loading

0 comments on commit 0084acc

Please sign in to comment.