mirror of
https://github.com/actions/runner-images.git
synced 2025-12-18 07:46:57 +00:00
fixes #1633 , using azure module, adjusted documentation
This commit is contained in:
@@ -12,6 +12,7 @@ After successful image generation, a snapshot of the temporary VM will be conver
|
|||||||
- `packer` - Can be downloaded from https://www.packer.io/downloads
|
- `packer` - Can be downloaded from https://www.packer.io/downloads
|
||||||
- `PowerShell 5.0 or higher` or `PSCore` for linux distributes.
|
- `PowerShell 5.0 or higher` or `PSCore` for linux distributes.
|
||||||
- `Azure CLI ` - https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
|
- `Azure CLI ` - https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
|
||||||
|
- `Azure Powershell module` - https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-4.6.1
|
||||||
|
|
||||||
### Azure DevOps self-hosted pool requirements
|
### Azure DevOps self-hosted pool requirements
|
||||||
To connect to a temporary VM packer use WinRM or SSH connections on public IP interfaces.
|
To connect to a temporary VM packer use WinRM or SSH connections on public IP interfaces.
|
||||||
@@ -31,7 +32,7 @@ Download `packer` from https://www.packer.io/downloads, or install it via Chocol
|
|||||||
choco install packer
|
choco install packer
|
||||||
```
|
```
|
||||||
|
|
||||||
Install Azure CLI - https://docs.microsoft.com/ru-ru/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli.
|
Install Azure CLI - https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli.
|
||||||
```
|
```
|
||||||
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
|
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -110,12 +110,12 @@ Function GenerateResourcesAndImage {
|
|||||||
$ServicePrincipalClientSecret = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper();
|
$ServicePrincipalClientSecret = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper();
|
||||||
$InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper();
|
$InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper();
|
||||||
|
|
||||||
Login-AzureRmAccount
|
Connect-AzAccount
|
||||||
Set-AzureRmContext -SubscriptionId $SubscriptionId
|
Set-AzContext -SubscriptionId $SubscriptionId
|
||||||
|
|
||||||
$alreadyExists = $true;
|
$alreadyExists = $true;
|
||||||
try {
|
try {
|
||||||
Get-AzureRmResourceGroup -Name $ResourceGroupName
|
Get-AzResourceGroup -Name $ResourceGroupName
|
||||||
Write-Verbose "Resource group was found, will delete and recreate it."
|
Write-Verbose "Resource group was found, will delete and recreate it."
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
@@ -126,8 +126,8 @@ Function GenerateResourcesAndImage {
|
|||||||
if ($alreadyExists) {
|
if ($alreadyExists) {
|
||||||
if($Force -eq $true) {
|
if($Force -eq $true) {
|
||||||
# Cleanup the resource group if it already exitsted before
|
# Cleanup the resource group if it already exitsted before
|
||||||
Remove-AzureRmResourceGroup -Name $ResourceGroupName -Force
|
Remove-AzResourceGroup -Name $ResourceGroupName -Force
|
||||||
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation
|
New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation
|
||||||
} else {
|
} else {
|
||||||
$title = "Delete Resource Group"
|
$title = "Delete Resource Group"
|
||||||
$message = "The resource group you specified already exists. Do you want to clean it up?"
|
$message = "The resource group you specified already exists. Do you want to clean it up?"
|
||||||
@@ -146,13 +146,13 @@ Function GenerateResourcesAndImage {
|
|||||||
|
|
||||||
switch ($result)
|
switch ($result)
|
||||||
{
|
{
|
||||||
0 { Remove-AzureRmResourceGroup -Name $ResourceGroupName -Force; New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation }
|
0 { Remove-AzResourceGroup -Name $ResourceGroupName -Force; New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation }
|
||||||
1 { <# Do nothing #> }
|
1 { <# Do nothing #> }
|
||||||
2 { exit }
|
2 { exit }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation
|
New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
# This script should follow the recommended naming conventions for azure resources
|
# This script should follow the recommended naming conventions for azure resources
|
||||||
@@ -164,19 +164,19 @@ Function GenerateResourcesAndImage {
|
|||||||
$storageAccountName = $storageAccountName.Replace("-", "").Replace("_", "").Replace("(", "").Replace(")", "").ToLower()
|
$storageAccountName = $storageAccountName.Replace("-", "").Replace("_", "").Replace("(", "").Replace(")", "").ToLower()
|
||||||
$storageAccountName += "001"
|
$storageAccountName += "001"
|
||||||
|
|
||||||
New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $storageAccountName -Location $AzureLocation -SkuName "Standard_LRS"
|
New-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $storageAccountName -Location $AzureLocation -SkuName "Standard_LRS"
|
||||||
|
|
||||||
$spDisplayName = [System.GUID]::NewGuid().ToString().ToUpper()
|
$spDisplayName = [System.GUID]::NewGuid().ToString().ToUpper()
|
||||||
$sp = New-AzureRmADServicePrincipal -DisplayName $spDisplayName -Password (ConvertTo-SecureString $ServicePrincipalClientSecret -AsPlainText -Force)
|
$sp = New-AzADServicePrincipal -DisplayName $spDisplayName -Password (ConvertTo-SecureString $ServicePrincipalClientSecret -AsPlainText -Force)
|
||||||
|
|
||||||
$spAppId = $sp.ApplicationId
|
$spAppId = $sp.ApplicationId
|
||||||
$spClientId = $sp.ApplicationId
|
$spClientId = $sp.ApplicationId
|
||||||
$spObjectId = $sp.Id
|
$spObjectId = $sp.Id
|
||||||
Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup
|
Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup
|
||||||
|
|
||||||
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $spAppId
|
New-AzRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $spAppId
|
||||||
Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup
|
Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup
|
||||||
$sub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId
|
$sub = Get-AzSubscription -SubscriptionId $SubscriptionId
|
||||||
$tenantId = $sub.TenantId
|
$tenantId = $sub.TenantId
|
||||||
# "", "Note this variable-setting script for running Packer with these Azure resources in the future:", "==============================================================================================", "`$spClientId = `"$spClientId`"", "`$ServicePrincipalClientSecret = `"$ServicePrincipalClientSecret`"", "`$SubscriptionId = `"$SubscriptionId`"", "`$tenantId = `"$tenantId`"", "`$spObjectId = `"$spObjectId`"", "`$AzureLocation = `"$AzureLocation`"", "`$ResourceGroupName = `"$ResourceGroupName`"", "`$storageAccountName = `"$storageAccountName`"", "`$install_password = `"$install_password`"", ""
|
# "", "Note this variable-setting script for running Packer with these Azure resources in the future:", "==============================================================================================", "`$spClientId = `"$spClientId`"", "`$ServicePrincipalClientSecret = `"$ServicePrincipalClientSecret`"", "`$SubscriptionId = `"$SubscriptionId`"", "`$tenantId = `"$tenantId`"", "`$spObjectId = `"$spObjectId`"", "`$AzureLocation = `"$AzureLocation`"", "`$ResourceGroupName = `"$ResourceGroupName`"", "`$storageAccountName = `"$storageAccountName`"", "`$install_password = `"$install_password`"", ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user