2020-04-29 13:16:12 +08:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
#
|
|
|
|
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Creates a Linux virtual machine scale set, set up for vcpkg's CI.
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
create-vmss.ps1 creates an Azure Linux VM scale set, set up for vcpkg's CI
|
|
|
|
system. See https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/overview
|
|
|
|
for more information.
|
|
|
|
|
|
|
|
This script assumes you have installed Azure tools into PowerShell by following the instructions
|
|
|
|
at https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.6.1
|
|
|
|
or are running from Azure Cloud Shell.
|
2020-06-22 10:13:13 +08:00
|
|
|
|
|
|
|
This script assumes you have installed the OpenSSH Client optional Windows component.
|
2021-09-12 04:43:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
.PARAMETER ImageName
|
|
|
|
The name of the image to deploy into the scale set.
|
2020-04-29 13:16:12 +08:00
|
|
|
#>
|
|
|
|
|
2021-09-12 04:43:19 +08:00
|
|
|
[CmdLetBinding()]
|
|
|
|
Param(
|
|
|
|
[parameter(Mandatory=$true)]
|
|
|
|
[string]$ImageName
|
|
|
|
)
|
|
|
|
|
2022-05-21 04:42:58 +08:00
|
|
|
$Location = 'eastasia'
|
2021-09-12 04:43:19 +08:00
|
|
|
$Prefix = 'PrLin-'
|
|
|
|
$Prefix += (Get-Date -Format 'yyyy-MM-dd')
|
|
|
|
$VMSize = 'Standard_D32a_v4'
|
2020-04-29 13:16:12 +08:00
|
|
|
$LiveVMPrefix = 'BUILD'
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
|
2020-05-30 13:46:05 +08:00
|
|
|
Import-Module "$PSScriptRoot/../create-vmss-helpers.psm1" -DisableNameChecking
|
2020-04-29 13:16:12 +08:00
|
|
|
|
2020-06-22 10:13:13 +08:00
|
|
|
$sshDir = [System.IO.Path]::GetTempPath() + [System.IO.Path]::GetRandomFileName()
|
|
|
|
mkdir $sshDir
|
|
|
|
try {
|
|
|
|
ssh-keygen.exe -q -b 2048 -t rsa -f "$sshDir/key" -P [string]::Empty
|
|
|
|
$sshPublicKey = Get-Content "$sshDir/key.pub"
|
|
|
|
} finally {
|
|
|
|
Remove-Item $sshDir -Recurse -Force
|
|
|
|
}
|
2020-04-29 13:16:12 +08:00
|
|
|
$ResourceGroupName = Find-ResourceGroupName $Prefix
|
|
|
|
$AdminPW = New-Password
|
2021-09-12 04:43:19 +08:00
|
|
|
$Image = Get-AzImage -ResourceGroupName 'vcpkg-image-minting' -ImageName $ImageName
|
2020-04-29 13:16:12 +08:00
|
|
|
|
2021-09-12 04:43:19 +08:00
|
|
|
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
|
2020-04-29 13:16:12 +08:00
|
|
|
|
2021-09-12 04:43:19 +08:00
|
|
|
$VirtualNetwork = Create-LockedDownNetwork -ResourceGroupName $ResourceGroupName -Location $Location
|
2020-04-29 13:16:12 +08:00
|
|
|
$VmssIpConfigName = $ResourceGroupName + 'VmssIpConfig'
|
2021-09-12 04:43:19 +08:00
|
|
|
$VmssIpConfig = New-AzVmssIpConfig -SubnetId $VirtualNetwork.Subnets[0].Id -Primary -Name $VmssIpConfigName
|
2020-04-29 13:16:12 +08:00
|
|
|
$VmssName = $ResourceGroupName + 'Vmss'
|
|
|
|
$Vmss = New-AzVmssConfig `
|
|
|
|
-Location $Location `
|
|
|
|
-SkuCapacity 0 `
|
|
|
|
-SkuName $VMSize `
|
|
|
|
-SkuTier 'Standard' `
|
|
|
|
-Overprovision $false `
|
|
|
|
-UpgradePolicyMode Manual `
|
|
|
|
-EvictionPolicy Delete `
|
|
|
|
-Priority Spot `
|
|
|
|
-MaxPrice -1
|
|
|
|
|
2021-09-12 04:43:19 +08:00
|
|
|
$NicName = $ResourceGroupName + 'NIC'
|
|
|
|
New-AzNetworkInterface `
|
|
|
|
-Name $NicName `
|
|
|
|
-ResourceGroupName $ResourceGroupName `
|
|
|
|
-Location $Location `
|
|
|
|
-Subnet $VirtualNetwork.Subnets[0]
|
|
|
|
|
2020-04-29 13:16:12 +08:00
|
|
|
$Vmss = Add-AzVmssNetworkInterfaceConfiguration `
|
|
|
|
-VirtualMachineScaleSet $Vmss `
|
|
|
|
-Primary $true `
|
|
|
|
-IpConfiguration $VmssIpConfig `
|
2021-09-12 04:43:19 +08:00
|
|
|
-NetworkSecurityGroupId $VirtualNetwork.Subnets[0].NetworkSecurityGroup.Id `
|
2020-04-29 13:16:12 +08:00
|
|
|
-Name $NicName
|
|
|
|
|
2020-06-22 10:13:13 +08:00
|
|
|
$VmssPublicKey = New-Object -TypeName 'Microsoft.Azure.Management.Compute.Models.SshPublicKey' `
|
|
|
|
-ArgumentList @('/home/AdminUser/.ssh/authorized_keys', $sshPublicKey)
|
|
|
|
|
2021-09-12 04:43:19 +08:00
|
|
|
$Vmss = Set-AzVmssOsProfile `
|
|
|
|
-VirtualMachineScaleSet $Vmss `
|
|
|
|
-ComputerNamePrefix $LiveVMPrefix `
|
|
|
|
-AdminUsername AdminUser `
|
|
|
|
-AdminPassword $AdminPW `
|
|
|
|
-LinuxConfigurationDisablePasswordAuthentication $true `
|
|
|
|
-PublicKey @($VmssPublicKey)
|
2020-04-29 13:16:12 +08:00
|
|
|
|
|
|
|
$Vmss = Set-AzVmssStorageProfile `
|
|
|
|
-VirtualMachineScaleSet $Vmss `
|
|
|
|
-OsDiskCreateOption 'FromImage' `
|
2021-07-16 04:47:58 +08:00
|
|
|
-OsDiskCaching ReadOnly `
|
|
|
|
-DiffDiskSetting Local `
|
2020-04-29 13:16:12 +08:00
|
|
|
-ImageReferenceId $Image.Id
|
|
|
|
|
|
|
|
New-AzVmss `
|
|
|
|
-ResourceGroupName $ResourceGroupName `
|
|
|
|
-Name $VmssName `
|
|
|
|
-VirtualMachineScaleSet $Vmss
|
|
|
|
|
|
|
|
Write-Host "Location: $Location"
|
|
|
|
Write-Host "Resource group name: $ResourceGroupName"
|
|
|
|
Write-Host 'Finished!'
|