2021-01-01 21:49:51 +03:00
|
|
|
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-18 14:20:57 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
locals {
|
2021-02-08 20:25:04 +03:00
|
|
|
vsts_token = secret_resource.vsts-token.value
|
2019-04-18 14:20:57 +03:00
|
|
|
vsts_account = "digitalasset"
|
|
|
|
vsts_pool = "windows-pool"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_region_instance_group_manager" "vsts-agent-windows" {
|
2021-02-08 20:25:04 +03:00
|
|
|
provider = google-beta
|
2019-04-18 14:20:57 +03:00
|
|
|
name = "vsts-agent-windows"
|
|
|
|
|
|
|
|
# keep the name short. windows hostnames are limited to 12(?) chars.
|
|
|
|
# -5 for the random postfix:
|
|
|
|
base_instance_name = "vsts-win"
|
|
|
|
|
2020-06-27 13:20:29 +03:00
|
|
|
region = "us-east1"
|
2020-02-11 04:07:42 +03:00
|
|
|
target_size = 6
|
2019-04-18 14:20:57 +03:00
|
|
|
|
|
|
|
version {
|
|
|
|
name = "vsts-agent-windows"
|
2021-02-08 20:25:04 +03:00
|
|
|
instance_template = google_compute_instance_template.vsts-agent-windows.self_link
|
2019-04-18 14:20:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
update_policy {
|
|
|
|
type = "PROACTIVE"
|
|
|
|
minimal_action = "REPLACE"
|
|
|
|
|
|
|
|
# minimum is the number of availability zones (3)
|
|
|
|
max_surge_fixed = 3
|
|
|
|
|
|
|
|
# calculated with: serial console last timestamp after boot - VM start
|
2019-04-25 23:49:38 +03:00
|
|
|
# 09:54:28 - 09:45:55 = 513 seconds
|
|
|
|
min_ready_sec = 520
|
2019-04-18 14:20:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "vsts-agent-windows" {
|
|
|
|
name_prefix = "vsts-agent-windows-"
|
2020-06-27 13:20:29 +03:00
|
|
|
machine_type = "c2-standard-8"
|
2021-02-08 20:25:04 +03:00
|
|
|
labels = local.machine-labels
|
2019-04-18 14:20:57 +03:00
|
|
|
|
|
|
|
disk {
|
|
|
|
disk_size_gb = 200
|
|
|
|
disk_type = "pd-ssd"
|
|
|
|
|
|
|
|
# find the image name with `gcloud compute images list`
|
2019-04-25 23:49:38 +03:00
|
|
|
source_image = "windows-cloud/windows-2016"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Drive D:\ for the agent work folder
|
|
|
|
disk {
|
|
|
|
disk_size_gb = 200
|
|
|
|
disk_type = "pd-ssd"
|
2019-04-18 14:20:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
|
2021-02-08 20:25:04 +03:00
|
|
|
metadata = {
|
2019-04-18 14:20:57 +03:00
|
|
|
// Prepare the machine
|
2020-04-07 02:33:36 +03:00
|
|
|
windows-startup-script-ps1 = <<SYSPREP_SPECIALIZE
|
2019-04-18 14:20:57 +03:00
|
|
|
Set-StrictMode -Version latest
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
# Disable Windows Defender to speed up disk access
|
|
|
|
Set-MpPreference -DisableRealtimeMonitoring $true
|
|
|
|
|
|
|
|
# Enable long paths
|
|
|
|
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name LongPathsEnabled -Type DWord -Value 1
|
|
|
|
|
|
|
|
# Disable UAC
|
|
|
|
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
|
|
|
|
|
2019-05-05 01:55:52 +03:00
|
|
|
# Redirect logs to SumoLogic
|
|
|
|
|
|
|
|
cd $env:UserProfile;
|
|
|
|
Invoke-WebRequest https://dl.google.com/cloudagents/windows/StackdriverLogging-v1-9.exe -OutFile StackdriverLogging-v1-9.exe;
|
|
|
|
.\StackdriverLogging-v1-9.exe /S /D="C:\Stackdriver\Logging\"
|
|
|
|
|
2019-04-18 14:20:57 +03:00
|
|
|
# Install chocolatey
|
2020-02-04 16:37:53 +03:00
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
2019-04-18 14:20:57 +03:00
|
|
|
iex (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')
|
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
# Install git, bash
|
2021-02-08 20:25:04 +03:00
|
|
|
& choco install git --no-progress --yes 2>&1 | %%{ "$_" }
|
|
|
|
& choco install windows-sdk-10.1 --no-progress --yes 2>&1 | %%{ "$_" }
|
2019-04-18 14:20:57 +03:00
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
# Add tools to the PATH
|
2019-04-18 14:20:57 +03:00
|
|
|
$OldPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
|
2019-05-21 14:42:49 +03:00
|
|
|
$NewPath = "$OldPath;C:\Program Files\Git\bin;C:\Program Files (x86)\Windows Kits\10\App Certification Kit"
|
2019-04-18 14:20:57 +03:00
|
|
|
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $NewPath
|
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
echo "== Prepare the D:\ drive"
|
2019-04-18 14:20:57 +03:00
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
$partition = @"
|
|
|
|
select disk 1
|
|
|
|
clean
|
|
|
|
convert gpt
|
|
|
|
create partition primary
|
|
|
|
format fs=ntfs quick
|
|
|
|
assign letter="D"
|
|
|
|
"@
|
|
|
|
$partition | Set-Content C:\diskpart.txt
|
2021-02-08 20:25:04 +03:00
|
|
|
& diskpart /s C:\diskpart.txt 2>&1 | %%{ "$_" }
|
2019-04-18 14:20:57 +03:00
|
|
|
|
|
|
|
# Create a temporary and random password for the VSTS user, forget about it once this script has finished running
|
2020-06-06 16:03:15 +03:00
|
|
|
$Username = "u"
|
2019-04-18 14:20:57 +03:00
|
|
|
$Account = "$env:COMPUTERNAME\$Username"
|
|
|
|
Add-Type -AssemblyName System.Web
|
|
|
|
$Password = [System.Web.Security.Membership]::GeneratePassword(24, 0)
|
|
|
|
|
|
|
|
echo "== Creating the VSTS user"
|
|
|
|
|
2019-04-25 23:49:38 +03:00
|
|
|
#New-LocalUser $Username -Password $SecurePassword -FullName $Username
|
2019-04-18 14:20:57 +03:00
|
|
|
net user $Username $Password /add /y
|
2019-04-25 23:49:38 +03:00
|
|
|
# net localgroup administrators $Username /add
|
|
|
|
Add-LocalGroupMember -Group "Administrators" -Member $Username
|
|
|
|
|
2019-04-18 14:20:57 +03:00
|
|
|
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2048"}'
|
|
|
|
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
|
|
|
|
winrm set winrm/config/service/auth '@{Basic="true"}'
|
|
|
|
net stop winrm
|
|
|
|
sc.exe config winrm start=auto
|
|
|
|
net start winrm
|
|
|
|
|
|
|
|
echo "== Installing the VSTS agent"
|
|
|
|
|
add default machine capability (#5912)
add default machine capability
We semi-regularly need to do work that has the potential to disrupt a
machine's local cache, rendering it broken for other streams of work.
This can include upgrading nix, upgrading Bazel, debugging caching
issues, or anything related to Windows.
Right now we do not have any good solution for these situations. We can
either not do those streams of work, or we can proceed with them and
just accept that all other builds may get affected depending on which
machine they get assigned to. Debugging broken nodes is particularly
tricky as we do not have any way to force a build to run on a given
node.
This PR aims at providing a better alternative by (ab)using an Azure
Pipelines feature called
[capabilities](https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser#capabilities).
The idea behind capabilities is that you assign a set of tags to a
machine, and then a job can express its
[demands](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml),
i.e. specify a set of tags machines need to have in order to run it.
Support for this is fairly badly documented. We can gather from the
documentation that a job can specify two things about a capability
(through its `demands`): that a given tag exists, and that a given tag
has an exact specified value. In particular, a job cannot specify that a
capability should _not_ be present, meaning we cannot rely on, say,
adding a "broken" tag to broken machines.
Documentation on how to set capabilities for an agent is basically
nonexistent, but [looking at the
code](https://github.com/microsoft/azure-pipelines-agent/blob/master/src/Microsoft.VisualStudio.Services.Agent/Capabilities/UserCapabilitiesProvider.cs)
indicates that they can be set by using a simple `key=value`-formatted
text file, provided we can find the right place to put this file.
This PR adds this file to our Linux, macOS and Windows node init scripts
to define an `assignment` capability and adds a demand for a `default`
value on each job. From then on, when we hit a case where we want a PR
to run on a specific node, and to prevent other PRs from running on that
node, we can manually override the capability from the Azure UI and
update the demand in the relevant YAML file in the PR.
CHANGELOG_BEGIN
CHANGELOG_END
2020-05-09 19:21:42 +03:00
|
|
|
New-Item -ItemType Directory -Path 'C:\agent'
|
|
|
|
Set-Content -Path 'C:\agent\.capabilities' -Value 'assignment=default'
|
|
|
|
|
2020-04-07 02:33:36 +03:00
|
|
|
$MachineName = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object CSName | ForEach{ $_.CSName }
|
2020-04-14 14:58:42 +03:00
|
|
|
choco install azure-pipelines-agent --no-progress --yes --params "'/Token:${local.vsts_token} /Pool:${local.vsts_pool} /Url:https://dev.azure.com/${local.vsts_account}/ /LogonAccount:$Account /LogonPassword:$Password /Work:D:\a /AgentName:$MachineName /Replace'"
|
2019-04-18 14:20:57 +03:00
|
|
|
echo OK
|
|
|
|
SYSPREP_SPECIALIZE
|
|
|
|
|
|
|
|
windows-shutdown-script-ps1 = "c://agent/config remove --unattended --auth PAT --token '${secret_resource.vsts-token.value}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
|
|
|
|
// Ephemeral IP to get access to the Internet
|
|
|
|
access_config {}
|
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
automatic_restart = false
|
|
|
|
on_host_maintenance = "TERMINATE"
|
2020-02-11 04:07:42 +03:00
|
|
|
preemptible = false
|
2019-04-18 14:20:57 +03:00
|
|
|
}
|
|
|
|
}
|