From 275c2f81b1ea07d048ff67c569557d2a389351af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BChnel?= Date: Wed, 22 Jan 2020 17:02:05 +0100 Subject: [PATCH] Updated boot strapping of windows agents --- docs/playbooks.md | 10 +++++- scripts/windows_agent_bootstrap.ps1 | 27 +++++++++++---- scripts/windows_agent_install.ps1 | 51 ----------------------------- scripts/windows_agent_start.ps1 | 28 +++++----------- 4 files changed, 37 insertions(+), 79 deletions(-) delete mode 100644 scripts/windows_agent_install.ps1 diff --git a/docs/playbooks.md b/docs/playbooks.md index 94d0c88..ec94176 100644 --- a/docs/playbooks.md +++ b/docs/playbooks.md @@ -120,7 +120,15 @@ To spawn a new windows agent: 1. In the RDP session: run these commands in the CMD window to start the docker container: ```cmd powershell -Invoke-WebRequest -uri 'https://raw.githubusercontent.com/google/llvm-premerge-checks/master/kubernetes/windows_agent_bootstrap.ps1' -OutFile windows_agent_bootstrap.ps1 +Invoke-WebRequest -uri 'https://raw.githubusercontent.com/google/llvm-premerge-checks/master/scripts/windows_agent_bootstrap.ps1' -OutFile windows_agent_bootstrap.ps1 +.\windows_agent_bootstrap.ps1 +``` +1. Wait for the machine to reboot, then login again and store the `gsutil` credentials in `build-agent-results_key`. +TODO: add documentation on how to create these. +1. run this script to start containers: +```cmd +powershell +Invoke-WebRequest -uri 'https://raw.githubusercontent.com/google/llvm-premerge-checks/master/scripts/windows_agent_start.ps1' -OutFile windows_agent_bootstrap.ps1 .\windows_agent_bootstrap.ps1 ``` diff --git a/scripts/windows_agent_bootstrap.ps1 b/scripts/windows_agent_bootstrap.ps1 index 276f3a5..7303644 100644 --- a/scripts/windows_agent_bootstrap.ps1 +++ b/scripts/windows_agent_bootstrap.ps1 @@ -12,10 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +# 1st stage of the installation process. +# This script only needs to be run once per machine. + Write-Host "Initializing local SSD..." New-Variable -Name diskid -Value (Get-Disk -FriendlyName "Google EphemeralDisk").Number # TODO: check if machine has an SSD -# TODO: only do this, if SSD is not yet usable +# TODO: only do this, if SSD is not yet partioned and formatted Initialize-Disk -Number $diskid New-Partition -DiskNumber $diskid -UseMaximumSize -AssignDriveLetter Format-Volume -DriveLetter D @@ -23,11 +26,21 @@ Format-Volume -DriveLetter D Write-Host "install chocolately as package manager..." iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) choco feature disable --name showDownloadProgress -choco install git +choco install -y git -Write-Host "Mounting result storage..." -Install-WindowsFeature NFS-Client -net use E: \\results.local\exports /PERSISTENT:YES +# install Docker +Install-PackageProvider -Name NuGet -Force +Install-Module -Name DockerMsftProvider -Repository PSGallery -Force +Install-Package -Name docker -ProviderName DockerMsftProvider -Force +Set-Service -Name docker -StartupType Automatic -Set-Location D:\ -git clone https://github.com/google/llvm-premerge-checks +# install gcloud and authenticate access to gcr.io registry +# TODO: find a better way to install the Google Cloud SDK, avoid ingoring the checksum +choco install -y gcloudsdk --ignore-checksums +gcloud auth docker + +# move docker folder to SSD to get better IO performance +cmd /C "mklink /j C:\ProgramData\Docker D:\docker" + +# Reboot +Restart-Computer -Force diff --git a/scripts/windows_agent_install.ps1 b/scripts/windows_agent_install.ps1 deleted file mode 100644 index 46c3b40..0000000 --- a/scripts/windows_agent_install.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2019 Google LLC - -# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# https://llvm.org/LICENSE.txt - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -. ${PSScriptRoot}\common.ps1 - -Write-Host "Installing Visual Studio build tools..." -choco install -y visualcpp-build-tools --version 15.0.26228.20170424 -y --params "'/IncludeOptional'" -Write-Host 'Waiting for Visual C++ Build Tools to finish' -Wait-Process -Name vs_installer - -Write-Host "Installing misc tools" -# install other tools as described in https://llvm.org/docs/GettingStartedVS.html -# and a few more that were not documented... -choco install -y git python2 ninja gnuwin cmake -pip install psutil - -Write-Host "Setting environment variables..." -[System.Environment]::SetEnvironmentVariable('PYTHONIOENCODING', 'UTF-8', [System.EnvironmentVariableTarget]::User) -$oldpath=[System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::User) -[System.Environment]::SetEnvironmentVariable('path', $oldpath + 'c:\Program Files (x86)\GnuWin32\bin;C:\Program Files\CMake\bin', [System.EnvironmentVariableTarget]::User) -# support long file names during git checkout -Write-Host "Setting git config..." -git config --system core.longpaths true -git config --global core.autocrlf false - -# Above: genric LLVM-related things -#------------- -# Below: Jenkins specific things - -Write-Host "Installing openjdk..." -choco install -y openjdk - -Write-Host "Installing Jenkins swarm agent..." -$SWARM_PLUGIN_URL="https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/3.17/swarm-client-3.17.jar" -$SWARM_PLUGIN_JAR="C:\jenkins\swarm-client.jar" -mkdir c:\jenkins -Invoke-WebRequest -Uri $SWARM_PLUGIN_URL -OutFile $SWARM_PLUGIN_JAR - -# TODO: put build-agent-results_key.json on the machine somehow -gcloud auth activate-service-account --key-file C:\jenkins\build-agent-results_key.json \ No newline at end of file diff --git a/scripts/windows_agent_start.ps1 b/scripts/windows_agent_start.ps1 index 3a218d9..bb98577 100644 --- a/scripts/windows_agent_start.ps1 +++ b/scripts/windows_agent_start.ps1 @@ -1,32 +1,20 @@ # Copyright 2019 Google LLC -# + # Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# + # https://llvm.org/LICENSE.txt -# + # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +$IMAGE="gcr.io/llvm-premerge-checks/agent-windows-jenkins" -. ${PSScriptRoot}\common.ps1 - -$JENKINS_SERVER="jenkins.local" -$AGENT_ROOT="D:\" -$SWARM_PLUGIN_JAR="C:\jenkins\swarm-client.jar" - -# move temp dir to local SSD -mkdir D:\temp -$env:temp="D:\temp" -$env:tmp=$env:temp - -java -jar ${SWARM_PLUGIN_JAR} ` - -master http://${JENKINS_SERVER}:8080 ` - -executors 1 ` - -fsroot ${AGENT_ROOT} ` - -labels windows ` - -name $env:computername \ No newline at end of file +# check for new images on every start +docker pull $IMAGE:latest +docker run $IMAGE +docker run -v D:\:C:\ws -v C:\credentials:C:\credentials -e PARENT_HOSTNAME=$env:computername $IMAGE