Skip to content

Commit

Permalink
Disable usage of local SSD on Windows VMs.
Browse files Browse the repository at this point in the history
Workaround for bazelbuild/bazel#5125.
  • Loading branch information
philwo authored and joeleba committed Jun 17, 2019
1 parent 8e7bbc9 commit afdfb79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
4 changes: 3 additions & 1 deletion buildkite/create_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@
'buildkite-worker-windows-java8': {
'count': 8,
'image_family': 'buildkite-worker-windows-java8',
'local_ssd': 'interface=scsi',
# We need to boost the size in order to get better IOPS and throughput.
# See: https://cloud.google.com/compute/docs/disks/performance
'boot_disk_size': '1000GB',
'metadata_from_file': 'windows-startup-script-ps1=startup-windows.ps1',
},
}
Expand Down
12 changes: 6 additions & 6 deletions buildkite/setup-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ SET BUILDKITE_ARTIFACT_UPLOAD_DESTINATION=gs://bazel-buildkite-artifacts/%BUILDK
SET BUILDKITE_GS_ACL=publicRead
SET JAVA_HOME=${env:JAVA_HOME}
SET PATH=${env:PATH}
SET TEMP=D:\temp
SET TMP=D:\temp
SET TEMP=C:\temp
SET TMP=C:\temp
"@
[System.IO.File]::WriteAllLines("${buildkite_agent_root}\hooks\environment.bat", $buildkite_environment_hook)

Expand All @@ -296,10 +296,10 @@ Write-Host "Terminating all processes belonging to the `${buildkite_username} us
& taskkill /FI "username eq `${buildkite_username}" /T /F
Start-Sleep -Seconds 1
Write-Host "Recreating fresh temporary directory D:\temp..."
Remove-Item -Recurse -Force "D:\temp"
New-Item -Type Directory "D:\temp"
Add-NTFSAccess -Path "D:\temp" -Account BUILTIN\Users -AccessRights Write
Write-Host "Recreating fresh temporary directory C:\temp..."
Remove-Item -Recurse -Force "C:\temp"
New-Item -Type Directory "C:\temp"
Add-NTFSAccess -Path "C:\temp" -Account BUILTIN\Users -AccessRights Write
Write-Host "Deleting home directory of the `${buildkite_username} user..."
Get-CimInstance Win32_UserProfile | Where LocalPath -EQ "C:\Users\`${buildkite_username}" | Remove-CimInstance
Expand Down
35 changes: 11 additions & 24 deletions buildkite/startup-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,33 @@
$ErrorActionPreference = "Stop"
$ConfirmPreference = "None"

## Initialize, partition and format the local SSD.
Write-Host "Initializing local SSD..."
if ((Get-Disk -Number 1).PartitionStyle -ne "RAW") {
Clear-Disk -Number 1 -RemoveData -RemoveOEM
}
Initialize-Disk -Number 1
New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter D
Format-Volume -DriveLetter D -ShortFileNameSupport $true
## Load PowerShell support for ZIP files.
Add-Type -AssemblyName "System.IO.Compression.FileSystem"

## Remove write access to volumes for unprivileged users.
Write-Host "Setting NTFS permissions..."
Remove-NTFSAccess "C:\" -Account BUILTIN\Users -AccessRights Write
Remove-NTFSAccess "D:\" -Account BUILTIN\Users -AccessRights Write

## Create temporary folder (D:\temp).
Write-Host "Creating temporary folder on local SSD..."
New-Item "D:\temp" -ItemType "directory"
Add-NTFSAccess "D:\temp" -Account BUILTIN\Users -AccessRights Write
Add-NTFSAccess "C:\temp" -Account BUILTIN\Users -AccessRights Write

## Redirect MSYS2's tmp folder to D:\temp
## Redirect MSYS2's tmp folder to C:\temp
Remove-Item -Recurse -Force C:\tools\msys64\tmp
New-Item -ItemType Junction -Path "C:\tools\msys64\tmp" -Value "D:\temp"
New-Item -ItemType Junction -Path "C:\tools\msys64\tmp" -Value "C:\temp"

## Create Buildkite agent working directory (D:\build).
Write-Host "Creating build folder on local SSD..."
New-Item "D:\build" -ItemType "directory"
Add-NTFSAccess "D:\build" -Account BUILTIN\Users -AccessRights Write
## Create Buildkite agent working directory (C:\build).
Write-Host "Creating build folder..."
New-Item "C:\build" -ItemType "directory"
Add-NTFSAccess "C:\build" -Account BUILTIN\Users -AccessRights Write

## Setup the TEMP and TMP environment variables.
[Environment]::SetEnvironmentVariable("TEMP", "D:\temp", "Machine")
[Environment]::SetEnvironmentVariable("TMP", "D:\temp", "Machine")
[Environment]::SetEnvironmentVariable("TEMP", "C:\temp", "Machine")
[Environment]::SetEnvironmentVariable("TMP", "C:\temp", "Machine")
$env:TEMP = [Environment]::GetEnvironmentVariable("TEMP", "Machine")
$env:TMP = [Environment]::GetEnvironmentVariable("TMP", "Machine")

## Download the Buildkite agent token.
Write-Host "Getting Buildkite Agent token from GCS..."
$buildkite_agent_token_url = "https://storage.googleapis.com/bazel-encrypted-secrets/buildkite-agent-token.enc"
$buildkite_agent_token_file = "d:\buildkite_agent_token.enc"
$buildkite_agent_token_file = "C:\buildkite_agent_token.enc"
(New-Object Net.WebClient).DownloadFile($buildkite_agent_token_url, $buildkite_agent_token_file)

## Decrypt the Buildkite agent token.
Expand All @@ -67,7 +54,7 @@ $buildkite_agent_config = @"
token="${buildkite_agent_token}"
name="%hostname-%n"
tags="kind=worker,os=windows,java=8,image-version=${image_version}"
build-path="d:\build"
build-path="c:\build"
hooks-path="c:\buildkite\hooks"
plugins-path="c:\buildkite\plugins"
git-clone-flags="-v --reference c:\buildkite\bazelbuild"
Expand Down

0 comments on commit afdfb79

Please sign in to comment.