[macOS] Remove stale code (#10430)

This commit is contained in:
Erik Bershel
2024-08-26 13:54:01 +02:00
committed by GitHub
parent e5de19ba15
commit 23c98d86f0
11 changed files with 0 additions and 725 deletions

View File

@@ -1,151 +0,0 @@
jobs:
- job: Image_generation
displayName: Image Generation (${{ parameters.image_label }})
timeoutInMinutes: 1200
pool:
name: Mac-Cloud Image Generation
demands:
- PrimaryRackAgent -equals ${{ parameters.primary_agent }}
variables:
- group: ${{ parameters.variable_group_name }}
steps:
- pwsh: |
$cleanBuildNumber = "$(Build.BuildNumber)" -replace "(.+_unstable)(\.\d+)", '$1'
$virtualMachineName = "${cleanBuildNumber}.$(System.JobAttempt)"
echo "##vso[task.setvariable variable=VirtualMachineName;]$virtualMachineName"
echo "##vso[build.updatebuildnumber]$virtualMachineName"
displayName: Update BuildNumber
- checkout: self
clean: true
fetchDepth: 1
- task: PowerShell@2
displayName: 'Validate contributor permissions'
condition: startsWith(variables['Build.SourceBranch'], 'refs/pull/')
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/validate-contributor.ps1
pwsh: true
arguments: -RepositoryName "$(Build.Repository.Name)" `
-AccessToken "$(github-feed-token)" `
-SourceBranch "$(Build.SourceBranch)" `
-ContributorAllowList "$(CONTRIBUTOR_ALLOWLIST)"
- task: PowerShell@2
displayName: 'Download custom repository'
condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], ''))
inputs:
targetType: 'filePath'
filePath: ./images.CI/download-repo.ps1
arguments: -RepoUrl $(CUSTOM_REPOSITORY_URL) `
-RepoBranch $(CUSTOM_REPOSITORY_BRANCH)
- task: DeleteFiles@1
displayName: Clean up self-hosted machine
inputs:
SourceFolder: 'images/macos/provision/log/'
RemoveSourceFolder: true
- task: PowerShell@2
displayName: 'Select datastore'
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/select-datastore.ps1
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)' `
-Cluster "$(esxi-cluster-v2)"
- pwsh: |
$SensitiveData = @(
'IP address:',
'Using ssh communicator to connect:'
)
packer init ${{ parameters.template_path }}
packer build -on-error=abort `
-var="vcenter_server=$(vcenter-server-v2)" `
-var="vcenter_username=$(vcenter-username-v2)" `
-var='vcenter_password=$(vcenter-password-v2)' `
-var="vcenter_datacenter=$(vcenter-datacenter-v2)" `
-var="cluster_or_esxi_host=$(esxi-cluster-v2)" `
-var="esxi_datastore=$(buildDatastore)" `
-var="output_folder=$(output-folder)" `
-var="vm_username=$(vm-username)" `
-var="vm_password=$(vm-password)" `
-var="github_api_pat=$(github_api_pat)" `
-var="build_id=$(VirtualMachineName)" `
-var="baseimage_name=${{ parameters.base_image_name }}" `
-var="xcode_install_storage_url=$(xcode_install_storage_url)" `
-var="xcode_install_sas=$(xcode_install_sas)" `
-color=false `
${{ parameters.template_path }} `
| Where-Object {
#Filter sensitive data from Packer logs
$currentString = $_
$sensitiveString = $SensitiveData | Where-Object { $currentString -match $_ }
$sensitiveString -eq $null
}
displayName: 'Build VM'
workingDirectory: 'images/macos'
env:
PACKER_LOG: 1
PACKER_LOG_PATH: $(Agent.TempDirectory)/packer-log.txt
- bash: |
echo "Copy software report files"
cp -vR "images/image-output/software-report/." "$(Build.ArtifactStagingDirectory)/"
echo "Put VM name to 'VM_Done_Name' file"
echo "$(VirtualMachineName)" > "$(Build.ArtifactStagingDirectory)/VM_Done_Name"
displayName: Prepare artifact
- bash: |
cat "$(Build.ArtifactStagingDirectory)/systeminfo.md"
displayName: Print markdown software report
- bash: |
cat "$(Build.ArtifactStagingDirectory)/systeminfo.json"
displayName: Print json software report
- task: PublishBuildArtifacts@1
inputs:
ArtifactName: 'Built_VM_Artifacts'
displayName: Publish Artifacts
- task: PowerShell@2
displayName: 'Print provisioners duration'
inputs:
targetType: 'filePath'
filePath: ./images.CI/measure-provisioners-duration.ps1
arguments: -PackerLogPath "$(Agent.TempDirectory)/packer-log.txt" `
-PrintTopNLongest 25
- task: PowerShell@2
displayName: 'Move vm to cold storage and clear datastore tag'
condition: always()
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/move-vm.ps1
arguments: -VMName "$(VirtualMachineName)" `
-TargetDataStore "${{ parameters.target_datastore }}" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)' `
-CpuCount "$(cpu-count)" `
-CoresPerSocketCount "$(cores-per-socket-count)" `
-Memory "$(memory)"
- task: PowerShell@2
displayName: 'Destroy VM (if build canceled only)'
condition: eq(variables['Agent.JobStatus'], 'Canceled')
inputs:
targetType: 'filePath'
filePath: ./images.CI/macos/destroy-vm.ps1
arguments: -VMName "$(VirtualMachineName)" `
-VIServer "$(vcenter-server-v2)" `
-VIUserName "$(vcenter-username-v2)" `
-VIPassword '$(vcenter-password-v2)'

View File

@@ -1,28 +0,0 @@
name: macOS-11_$(date:yyyyMMdd)$(rev:.r)_unstable
schedules:
- cron: '45 0 * * *'
displayName: Daily
branches:
include:
- main
always: true
trigger: none
pr:
autoCancel: true
branches:
include:
- main
variables:
- group: Mac-Cloud Image Generation
jobs:
- template: image-generation.yml
parameters:
image_label: 'macOS Big Sur'
base_image_name: 'clean-macOS-11-380Gb-runner'
template_path: 'templates/macOS-11.pkr.hcl'
target_datastore: 'ds-image'
variable_group_name: 'Mac-Cloud Image Generation'
primary_agent: 'true'

View File

@@ -1,28 +0,0 @@
name: macOS-12_$(date:yyyyMMdd)$(rev:.r)_unstable
schedules:
- cron: "0 0 * * *"
displayName: Daily
branches:
include:
- main
always: true
trigger: none
pr:
autoCancel: true
branches:
include:
- main
variables:
- group: Mac-Cloud Image Generation
jobs:
- template: image-generation.yml
parameters:
image_label: 'macOS Monterey'
base_image_name: 'clean-macOS-12-380Gb-runner'
template_path: 'templates/macOS-12.pkr.hcl'
target_datastore: 'ds-image'
variable_group_name: 'Mac-Cloud Image Generation'
primary_agent: 'true'

View File

@@ -1,23 +0,0 @@
name: macOS-11_$(date:yyyyMMdd)$(rev:.r)_unstable
schedules:
- cron: '45 0 * * 1'
displayName: Weekly
branches:
include:
- main
always: true
trigger: none
variables:
- group: Mac-Cloud Image Generation
jobs:
- template: image-generation.yml
parameters:
image_label: 'macOS Big Sur'
base_image_name: 'clean-macOS-11-380Gb-runner'
template_path: 'templates/macOS-11.pkr.hcl'
target_datastore: 'ds-image'
variable_group_name: 'Mac-Cloud Secondary Image Generation'
primary_agent: 'false'

View File

@@ -1,23 +0,0 @@
name: macOS-12_$(date:yyyyMMdd)$(rev:.r)_unstable
schedules:
- cron: '45 1 * * 1'
displayName: Weekly
branches:
include:
- main
always: true
trigger: none
variables:
- group: Mac-Cloud Image Generation
jobs:
- template: image-generation.yml
parameters:
image_label: 'macOS Monterey'
base_image_name: 'clean-macOS-12-380Gb-runner'
template_path: 'templates/macOS-12.pkr.hcl'
target_datastore: 'ds-image'
variable_group_name: 'Mac-Cloud Secondary Image Generation'
primary_agent: 'false'

View File

@@ -1,95 +0,0 @@
<#
.SYNOPSIS
This script deletes vm from vCenter
.PARAMETER VMName
VM name to delete (Example "macOS-10.15_20201012.4")
.PARAMETER VIServer
vCenter address (Example "10.0.1.16")
.PARAMETER VIUserName
vCenter username (Example "Administrator")
.PARAMETER VIPassword
vCenter password (Example "12345678")
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VMName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIServer,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIUserName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIPassword
)
# Import helpers module
Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking
# Connection to a vCenter Server system
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
# Check vm clone status
$chainId = (Get-VIEvent -Entity $VMName).ChainId
if ($chainId)
{
$task = Get-Task -Status Running | Where-Object { ($_.Name -eq 'CloneVM_Task') -and ($_.ExtensionData.Info.EventChainId -in $chainId) }
if ($task)
{
try
{
Stop-Task -Task $task -Confirm:$false -ErrorAction Stop
Write-Host "The vm '$VMName' clone task has been canceled"
}
catch
{
Write-Host "##vso[task.LogIssue type=error;]Failed to cancel the task"
}
}
}
# Remove a vm
$vm = Get-VM -Name $VMName -ErrorAction SilentlyContinue
if ($vm)
{
$vmState = $vm.PowerState
if ($vmState -ne "PoweredOff")
{
try
{
$null = Stop-VM -VM $vm -Confirm:$false -ErrorAction Stop
Write-Host "The vm '$VMName' has been powered off"
}
catch
{
Write-Host "##vso[task.LogIssue type=error;]Failed to shutdown '$VMName'"
}
}
try
{
Remove-VM -VM $vm -DeletePermanently -Confirm:$false -ErrorAction Stop
Write-Host "The vm '$VMName' has been removed"
}
catch
{
Write-Host "##vso[task.LogIssue type=error;]Failed to remove '$VMName'"
}
}
else
{
Write-Host "VM '$VMName' not found"
}

View File

@@ -1,38 +0,0 @@
<#
.SYNOPSIS
Helper functions to use in images.CI scripts
#>
Function Connect-VCServer
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[System.String]$VIUserName,
[Parameter(Mandatory)]
[System.String]$VIPassword,
[Parameter(Mandatory)]
[System.String]$VIServer
)
try
{
# Preference
$global:ProgressPreference = 'SilentlyContinue'
$global:WarningPreference = 'SilentlyContinue'
# Ignore SSL
$null = Set-PowerCLIConfiguration -Scope Session -InvalidCertificateAction Ignore -ParticipateInCEIP $false -Confirm:$false -WebOperationTimeoutSeconds 600
$securePassword = ConvertTo-SecureString -String $VIPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($VIUserName, $securePassword)
$null = Connect-VIServer -Server $VIServer -Credential $cred -ErrorAction Stop
Write-Host "Connection to the vSphere server has been established"
}
catch
{
Write-Host "##vso[task.LogIssue type=error;]Failed to connect to the vSphere server"
exit 1
}
}

View File

@@ -1,86 +0,0 @@
<#
.SYNOPSIS
This script migrates given VM to another datastore
.PARAMETER VMName
VM name to migrate (Example "macOS-10.15_20201012.4")
.PARAMETER TargetDataStore
Target datastore (Example "ds-image")
.PARAMETER VIServer
vCenter address (Example "10.0.1.16")
.PARAMETER VIUserName
vCenter username (Example "Administrator")
.PARAMETER VIPassword
vCenter password (Example "12345678")
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VMName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$TargetDataStore,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIServer,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIUserName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIPassword,
[string]$JobStatus,
[int32]$CpuCount,
[int32]$CoresPerSocketCount,
[int64]$Memory
)
# Import helpers module
Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking
# Connection to a vCenter Server system
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
# Clear previously assigned tag with VM Name
try {
Remove-Tag $VMName -Confirm:$false
} catch {
Write-Host "Tag with $VMName doesn't exist"
}
$vm = Get-VM $VMName
if (($env:AGENT_JOBSTATUS -and $env:AGENT_JOBSTATUS -eq 'Failed') -or ($JobStatus -and $JobStatus -eq 'failure')) {
try {
if ($vm.PowerState -ne "PoweredOff") {
Stop-VM -VM $vm -Confirm:$false -ErrorAction Stop | Out-Null
}
Set-VM -VM $vm -Name "${VMName}_failed" -Confirm:$false -ErrorAction Stop | Out-Null
Write-Host "VM has been successfully powered off and renamed to [${VMName}_failed]"
} catch {
Write-Host "##vso[task.LogIssue type=error;]Failed to power off and rename VM '$VMName'"
exit 1
}
}
try {
Move-VM -Vm $vm -Datastore $TargetDataStore -ErrorAction Stop | Out-Null
Write-Host "VM has been moved successfully to target datastore '$TargetDataStore'"
} catch {
Write-Host "##vso[task.LogIssue type=error;]Failed to move VM '$VMName' to target datastore '$TargetDataStore'"
exit 1
}

View File

@@ -1,117 +0,0 @@
<#
.SYNOPSIS
This script selects local datastore based on the following rules:
- Name starts with ds-local-Datastore
- Datastore FreespaceGB > 400 Gb
- VM count on the datastore < 2
.PARAMETER VIServer
vCenter address (Example "10.0.1.16")
.PARAMETER VIUserName
vCenter username (Example "Administrator")
.PARAMETER VIPassword
vCenter password (Example "12345678")
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VMName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIServer,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIUserName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIPassword,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Cluster,
[string]$TagCategory = "Busy"
)
# Import helpers module
Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking
function Select-DataStore {
param (
[string]$VMName,
[string]$TagCategory,
[string]$TemplateDatastore = "ds-local-Datastore-*",
[string]$Cluster,
[int]$ThresholdInGb = 400,
[int]$VMCount = 2,
[int]$Retries = 5
)
# 1. Name starts with ds-local-Datastore
# 2. FreespaceGB > 400 Gb
# 3. Choose a datastore with the minimal VM count < 2
Write-Host "Start Datastore selection process..."
$clusterHosts = Get-Cluster -Name $Cluster | Get-VMHost
$availableClusterDatastores = $clusterHosts | Get-Datastore -Name $TemplateDatastore | Where-Object -Property State -eq "Available"
$availableDatastores = $availableClusterDatastores `
| Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } `
| Where-Object {
$vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch '(^\.|vmkdump)').Count
$vmOnDatastore -lt $vmCount } `
| Group-Object -Property { $vmOnDatastore }
$datastore = $availableDatastores | Select-Object @{n="VmCount";e={$_.Name}},@{n="DatastoreName";e={$_.Group | Get-Random}} -First 1
$buildDatastore = $datastore.DatastoreName
$tag = Get-Tag -Category $TagCategory -Name $VMName -ErrorAction Ignore
if (-not $tag)
{
$tag = New-Tag -Name $VMName -Category $TagCategory
}
New-TagAssignment -Tag $tag -Entity $buildDatastore | Out-Null
# Wait for 60 seconds to check if any other tags are assigned to the same datastore
Start-Sleep -Seconds 60
# If there are no datastores with 0 VMs, take a datastore with 1 VM (index 1 if datastore has 0 VMs and 2 if 1 VM)
$index = 1 + [int]$datastore.VmCount
$tagAssignments = (Get-TagAssignment -Entity $buildDatastore).Tag.Name | Select-Object -First $index
$isAllow = $tagAssignments -contains $VMName
if ($isAllow)
{
Write-Host "Datastore selected successfully"
Write-Host "##vso[task.setvariable variable=buildDatastore;issecret=true]$buildDatastore"
return
}
# Remove the tag if datastore wasn't selected
Remove-Tag $tag -Confirm:$false
$retries--
if ($retries -le 0)
{
Write-Host "##vso[task.LogIssue type=error;]No datastores found for the condition"
exit 1
}
Write-Host "Datastore select failed, $retries left"
Select-DataStore -VMName $VMName -Cluster $Cluster -TagCategory $TagCategory -Retries $retries
}
# Connection to a vCenter Server system
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
# Get a target datastore for current deployment
Select-DataStore -VMName $VMName -Cluster $Cluster -TagCategory $TagCategory

View File

@@ -1,73 +0,0 @@
<#
.SYNOPSIS
This script sets resources for VM
.PARAMETER VMName
VM name to resize (Example "macOS-10.15_20201012.4")
.PARAMETER VIServer
vCenter address (Example "10.0.1.16")
.PARAMETER VIUserName
vCenter username (Example "Administrator")
.PARAMETER VIPassword
vCenter password (Example "12345678")
.PARAMETER CpuCount
Target number of CPUs (Example "3")
.PARAMETER CoresPerSocketCount
Target number of cores per socket (Example "3")
.PARAMETER Memory
Target amount of memory in MB (Example "14336")
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VMName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIServer,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIUserName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$VIPassword,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[int32]$CpuCount,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[int32]$CoresPerSocketCount,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[int64]$Memory
)
# Import helpers module
Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking
# Connection to a vCenter Server system
Connect-VCServer -VIServer $VIServer -VIUserName $VIUserName -VIPassword $VIPassword
$vm = Get-VM $VMName
try {
Write-Host "Change CPU count to $CpuCount, cores count to $CoresPerSocketCount, amount of RAM to $Memory"
$vm | Set-VM -NumCPU $CpuCount -CoresPerSocket $CoresPerSocketCount -MemoryMB $Memory -Confirm:$false -ErrorAction Stop | Out-Null
} catch {
Write-Host "##vso[task.LogIssue type=error;]Failed to change specs for VM '$VMName'"
exit 1
}

View File

@@ -1,63 +0,0 @@
param(
[Parameter(Mandatory)] [string] $RepositoryName,
[Parameter(Mandatory)] [string] $AccessToken,
[Parameter(Mandatory)] [string] $SourceBranch,
[Parameter(Mandatory)] [string] $ContributorAllowList
)
function Build-AuthHeader {
param(
[Parameter(Mandatory)] [string] $AccessToken
)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("'':${AccessToken}"))
return "Basic ${base64AuthInfo}"
}
function Get-PullRequest {
param(
[Parameter(Mandatory)] [string] $RepositoryName,
[Parameter(Mandatory)] [string] $AccessToken,
[Parameter(Mandatory)] [UInt32] $PullRequestNumber
)
$requestUrl = "https://api.github.com/repos/$RepositoryName/pulls/$PullRequestNumber"
$authHeader = Build-AuthHeader -AccessToken $AccessToken
$params = @{
Method = "GET"
ContentType = "application/json"
Uri = $requestUrl
Headers = @{ Authorization = $authHeader }
}
return Invoke-RestMethod @params
}
function Validate-ContributorPermissions {
param(
[Parameter(Mandatory)] [string] $ContributorAllowList,
[Parameter(Mandatory)] [string] $ContributorName
)
$allowedContributors = $ContributorAllowList.Split(",").Trim()
$validСontributor = $allowedContributors | Where-Object { $_ -eq $ContributorName } `
| Select-Object -First 1
if (-not $validСontributor) {
Write-Host "Failed to start this build. '$ContributorName' is an unknown contributor"
Write-Host "Please add '$ContributorName' to the allowed list to run builds"
exit 1
}
}
$pullRequestNumber = $SourceBranch.Split("/")[2]
$pullRequestInfo = Get-PullRequest -RepositoryName $RepositoryName `
-AccessToken $AccessToken `
-PullRequestNumber $pullRequestNumber
$contributorName = $pullRequestInfo.user.login
Validate-ContributorPermissions -ContributorAllowList $ContributorAllowList `
-ContributorName $contributorName