From 27361ddb4a2fbf5ee2e01f87b16d70743f4b84d9 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Mon, 19 Oct 2020 10:25:04 +0300 Subject: [PATCH 1/6] resize disk using powershell --- images/win/scripts/Installers/Initialize-VM.ps1 | 12 ++++-------- images/win/windows2019.json | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/images/win/scripts/Installers/Initialize-VM.ps1 b/images/win/scripts/Installers/Initialize-VM.ps1 index ad853bb74..a8509be00 100644 --- a/images/win/scripts/Installers/Initialize-VM.ps1 +++ b/images/win/scripts/Installers/Initialize-VM.ps1 @@ -128,11 +128,7 @@ if (Test-IsWin19) { } # Expand disk size of OS drive -New-Item -Path d:\ -Name cmds.txt -ItemType File -Force -Add-Content -Path d:\cmds.txt "SELECT VOLUME=C`r`nEXTEND" - -$expandResult = (diskpart /s 'd:\cmds.txt') -Write-Host $expandResult - -Write-Host "Disk sizes after expansion" -wmic logicaldisk get size,freespace,caption +$driveLetter = "C" +$size = Get-PartitionSupportedSize -DriveLetter $driveLetter +Resize-Partition -DriveLetter $driveLetter -Size $size.SizeMax +Get-Partition | Select-Object DriveLetter, PartitionNumber, Size \ No newline at end of file diff --git a/images/win/windows2019.json b/images/win/windows2019.json index 6609b5b38..6b9f3a868 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -13,7 +13,7 @@ "virtual_network_resource_group_name": "{{env `VNET_RESOURCE_GROUP`}}", "virtual_network_subnet_name": "{{env `VNET_SUBNET`}}", "private_virtual_network_with_public_ip": "{{env `PRIVATE_VIRTUAL_NETWORK_WITH_PUBLIC_IP`}}", - "vm_size": "Standard_D4_v2", + "vm_size": "Standard_DS4_v2", "run_scan_antivirus": "false", "root_folder": "C:", "toolset_json_path": "{{env `TEMP`}}\\toolset.json", From 3633730364c0eac3a457f0abd385e5b0d19e63f6 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Mon, 19 Oct 2020 10:33:43 +0300 Subject: [PATCH 2/6] use Get-Volume --- images/win/scripts/Installers/Initialize-VM.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Initialize-VM.ps1 b/images/win/scripts/Installers/Initialize-VM.ps1 index a8509be00..027728727 100644 --- a/images/win/scripts/Installers/Initialize-VM.ps1 +++ b/images/win/scripts/Installers/Initialize-VM.ps1 @@ -131,4 +131,4 @@ if (Test-IsWin19) { $driveLetter = "C" $size = Get-PartitionSupportedSize -DriveLetter $driveLetter Resize-Partition -DriveLetter $driveLetter -Size $size.SizeMax -Get-Partition | Select-Object DriveLetter, PartitionNumber, Size \ No newline at end of file +Get-Volume | Select-Object DriveLetter, SizeRemaining, Size | Sort-Object DriveLetter \ No newline at end of file From dee484a90ce67d42f5df91a42b618cdd14b2a8f2 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 22 Oct 2020 10:49:07 +0300 Subject: [PATCH 3/6] remove chmod --- images/linux/scripts/installers/homebrew.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/images/linux/scripts/installers/homebrew.sh b/images/linux/scripts/installers/homebrew.sh index 865923f25..dd9e8f9e5 100644 --- a/images/linux/scripts/installers/homebrew.sh +++ b/images/linux/scripts/installers/homebrew.sh @@ -12,9 +12,6 @@ source $HELPER_SCRIPTS/etc-environment.sh /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) -# Make brew files and directories writable by any user -sudo chmod -R o+w $HOMEBREW_PREFIX - # Update /etc/environemnt ## Put HOMEBREW_* variables brew shellenv|grep 'export HOMEBREW'|sed -E 's/^export (.*);$/\1/' | sudo tee -a /etc/environment From 47eaa69646becdb28d3de6b28d92a16a18972b73 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Mon, 26 Oct 2020 14:37:18 +0300 Subject: [PATCH 4/6] [macOS] Improve select datastore script (#1892) * modify script to set tages * add vmname * nitpicks * add remove tag --- .../azure-pipelines/image-generation.yml | 7 +- images.CI/macos/move-vm.ps1 | 7 ++ images.CI/macos/select-datastore.ps1 | 87 ++++++++++++++----- 3 files changed, 75 insertions(+), 26 deletions(-) diff --git a/images.CI/macos/azure-pipelines/image-generation.yml b/images.CI/macos/azure-pipelines/image-generation.yml index 89216e216..60837bc1a 100644 --- a/images.CI/macos/azure-pipelines/image-generation.yml +++ b/images.CI/macos/azure-pipelines/image-generation.yml @@ -52,7 +52,8 @@ jobs: inputs: targetType: 'filePath' filePath: ./images.CI/macos/select-datastore.ps1 - arguments: -VIServer "$(vcenter-server-v2)" ` + arguments: -VMName "$(VirtualMachineName)" ` + -VIServer "$(vcenter-server-v2)" ` -VIUserName "$(vcenter-username-v2)" ` -VIPassword "$(vcenter-password-v2)" @@ -121,8 +122,8 @@ jobs: condition: always() - task: PowerShell@2 - displayName: 'Move vm to cold storage' - condition: succeededOrFailed() + displayName: 'Move vm to cold storage and clear datastore tag' + condition: always() inputs: targetType: 'filePath' filePath: ./images.CI/macos/move-vm.ps1 diff --git a/images.CI/macos/move-vm.ps1 b/images.CI/macos/move-vm.ps1 index 698721409..37e839066 100644 --- a/images.CI/macos/move-vm.ps1 +++ b/images.CI/macos/move-vm.ps1 @@ -48,6 +48,13 @@ Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking # Connection to a vCenter Server system Connect-VCServer +# 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 -eq 'Failed') { diff --git a/images.CI/macos/select-datastore.ps1 b/images.CI/macos/select-datastore.ps1 index d6477700c..2884fdf46 100644 --- a/images.CI/macos/select-datastore.ps1 +++ b/images.CI/macos/select-datastore.ps1 @@ -20,6 +20,10 @@ vCenter password (Example "12345678") [CmdletBinding()] param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$VMName, + [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$VIServer, @@ -30,35 +34,72 @@ param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] - [string]$VIPassword + [string]$VIPassword, + + [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-*", + [int]$ThresholdInGb = 400, + [int]$VMCount = 2, + [int]$Retries = 5 + ) + + # 1. Name starts with ds-local-Datastore + # 2. FreespaceGB > 400 Gb + # 3. VM count on a datastore < 2 + + Write-Host "Start Datastore selection process..." + $allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" } + $buildDatastore = $allDatastores | Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } | Where-Object { + $vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch "^\.").Count + $vmOnDatastore -lt $vmCount + } | Select-Object -ExpandProperty Name -First 1 + + $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 + # Take only first 2 tags, all the others will go to the next round + $tagAssignments = (Get-TagAssignment -Entity $buildDatastore).Tag.Name | Select-Object -First 2 + $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 -TagCategory $TagCategory -Retries $retries +} + # Connection to a vCenter Server system Connect-VCServer # Get a target datastore for current deployment -# 1. Name starts with ds-local-Datastore -# 2. FreespaceGB > 400 Gb -# 3. VM count on a datastore < 2 -$templateDatastore = "ds-local-Datastore-*" -$thresholdInGb = 400 -$vmCount = 2 -$allDatastores = Get-Datastore -Name $templateDatastore | Where-Object { $_.State -eq "Available" } -$buildDatastore = $allDatastores | Where-Object { $_.FreeSpaceGB -ge $thresholdInGb } | Where-Object { - $vmOnDatastore = @((Get-ChildItem -Path $_.DatastoreBrowserPath).Name -notmatch "^\.").Count - $vmOnDatastore -lt $vmCount - } | Select-Object -ExpandProperty Name -First 1 - -if ($buildDatastore) -{ - Write-Host "Datastore selected successfully" - Write-Host "##vso[task.setvariable variable=buildDatastore;issecret=true]$buildDatastore" -} -else -{ - Write-Host "##vso[task.LogIssue type=error;]No datastores found for the condition" - exit 1 -} \ No newline at end of file +Select-DataStore -VMName $VMName -TagCategory $TagCategory From 48e266a55a3c4aa19b715b299ac5729fdb6379a8 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Mon, 26 Oct 2020 16:41:26 +0300 Subject: [PATCH 5/6] [macOS] remove workaround for MS edge (#1898) --- images/macos/provision/core/edge.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/images/macos/provision/core/edge.sh b/images/macos/provision/core/edge.sh index da1673e0a..bd0ffeddb 100644 --- a/images/macos/provision/core/edge.sh +++ b/images/macos/provision/core/edge.sh @@ -3,11 +3,7 @@ source ~/utils/utils.sh echo "Installing Microsoft Edge..." -# Workaround to install version 85 since webdriver is broken for 86 -cd "$(brew --repo homebrew/homebrew-cask)" -git checkout 81f9d08d2b9b7557c0178621078cf59d2c5db2bc brew cask install microsoft-edge -git checkout master EDGE_INSTALLATION_PATH="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" EDGE_VERSION=$("$EDGE_INSTALLATION_PATH" --version | cut -d' ' -f 3) From 4444dfd517ec0bc970a8c1bd8dbc2a902b9db97c Mon Sep 17 00:00:00 2001 From: MaksimZhukov Date: Mon, 26 Oct 2020 17:41:40 +0300 Subject: [PATCH 6/6] Fix Xamarin issue with Xcode symlink --- images/macos/provision/core/xamarin.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/images/macos/provision/core/xamarin.sh b/images/macos/provision/core/xamarin.sh index 86dc1a0fe..18eef3219 100755 --- a/images/macos/provision/core/xamarin.sh +++ b/images/macos/provision/core/xamarin.sh @@ -9,6 +9,7 @@ XAMARIN_MAC_VERSIONS=($(get_toolset_value '.xamarin."mac-versions" | reverse | . XAMARIN_ANDROID_VERSIONS=($(get_toolset_value '.xamarin."android-versions" | reverse | .[]')) LATEST_SDK_SYMLINK=$(get_toolset_value '.xamarin.bundles[0].symlink') CURRENT_SDK_SYMLINK=$(get_toolset_value '.xamarin."bundle-default"') +DEFAULT_XCODE_VERSION=$(get_default_xcode_from_toolset) if [ "$CURRENT_SDK_SYMLINK" == "latest" ]; then CURRENT_SDK_SYMLINK=$LATEST_SDK_SYMLINK @@ -82,3 +83,8 @@ popd echo "Clean up packages..." sudo rm -rf "$TMPMOUNT" + +# Fix Xamarin issue with Xcode symlink: https://github.com/xamarin/xamarin-macios/issues/9960 +PREFERENCES_XAMARIN_DIR="${HOME}/Library/Preferences/Xamarin" +mkdir -p $PREFERENCES_XAMARIN_DIR +/usr/libexec/PlistBuddy -c "add :AppleSdkRoot string /Applications/Xcode_${DEFAULT_XCODE_VERSION}.app" $PREFERENCES_XAMARIN_DIR/Settings.plist