1
0
Fork 0

Merge pull request #189 from google/win

Update docs and script for installing win machines
This commit is contained in:
Mikhail Goncharov 2020-05-28 08:03:09 +02:00 committed by GitHub
commit d2b981a07e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 227 additions and 188 deletions

View file

@ -1,14 +1,8 @@
# escape=` # escape=`
# use windows server core image # use windows server core image
ARG agent_windows_version ARG agent_windows_version=latest
FROM gcr.io/llvm-premerge-checks/agent-windows:${agent_windows_version} FROM gcr.io/llvm-premerge-checks/agent-windows-vs2019:${agent_windows_version}
# install buildkite agent as described in the documentation
# https://buildkite.com/docs/agent/v3/windows
# Supply your agent token via the arguement "-token <mytoken" when building the image
ARG token
ENV BUILDKITE_BUILD_PATH=C:\ws\bk
COPY start_agent.ps1 C:\scripts\ COPY start_agent.ps1 C:\scripts\
CMD "powershell C:\scripts\start_agent.ps1" CMD "powershell C:\scripts\start_agent.ps1"

View file

@ -1,9 +1,4 @@
$Env:buildkiteAgentToken = [IO.File]::ReadAllText("C:\credentials\buildkite-token.txt") c:\credentials\buildkite-env.ps1
# Install Buildkite agent.
#Set-ExecutionPolicy Bypass -Scope Process -Force
iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/buildkite/agent/master/install.ps1')) iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/buildkite/agent/master/install.ps1'))
C:\buildkite-agent\bin\buildkite-agent.exe start
# use the name of the host machine as name for the agent in buildkite
$env:BUILDKITE_AGENT_NAME="win-vs17 $env:PARENT_HOSTNAME"
C:\buildkite-agent\bin\buildkite-agent.exe start --tags "os=windows"

View file

@ -62,54 +62,49 @@ These are the steps to set up the build server on a clean infrastructure:
## Creating docker containers on Windows ## Creating docker containers on Windows
If you want to build/update/test docker container for Windows, you need to do this on a Windows machine. Here are the instructions to set up such a machine on GCP. If you want to build/update/test docker container for Windows, you need to do this on a Windows machine.
**Note**: There is an existing *windows-development* machine that you can resume and use for development. Please stop it after use.
Here are the instructions to set up such a machine on GCP.
1. Pick a GCP Windows image with Desktop Support. 1. Pick a GCP Windows image with Desktop Support.
* pick a "persistent SSD" as boot Disk. This is much faster * pick a "persistent SSD" as boot Disk. This is much faster
* Add a "local scratch SSD" and use it as you workspace. This is much faster. * (optionally) add a "local scratch SSD" and use it as you workspace. This will make builds faster, but you **will not be able to stop** this instance and will have to kill and re-create it again.
* make sure that you give enough permissions in "Identity and API access" to be able to e.g. push new docker images to GCR.
1. Format the local SSD partition and use it as workspace. 1. Format the local SSD partition and use it as workspace.
1. install [Chocolately](https://chocolatey.org/docs/installation): 1. install [Chocolately](https://chocolatey.org/docs/installation):
```bat ```powershell
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
``` ```
1. Install git: `choco install -y git` 1. Install development tools: `choco install -y git googlechrome vscode`
1. (optionally) If you want to be able to push changes to github, you need to set up your github SSH keys and user name:
```powershell
ssh-keygen
git config --global user.name <your name>
git config --global user.email <your email>
```
1. Install [Docker Enterprise](https://docs.docker.com/ee/docker-ee/windows/docker-ee/) and reboot: 1. Install [Docker Enterprise](https://docs.docker.com/ee/docker-ee/windows/docker-ee/) and reboot:
```powershell ```powershell
Install-Module DockerMsftProvider -Force Install-Module DockerMsftProvider -Force
Install-Package Docker -ProviderName DockerMsftProvider -Force Install-Package Docker -ProviderName DockerMsftProvider -Force
Restart-Computer Restart-Computer
``` ```
1. *optional:* install apps to help you work in the machine:
```powershell
choco install -y googlechrome vscode
```
1. Log out of the machine and log back in.
1. Repeat until success:
1. Start "Docker Desktop" and let it install it's dependencies.
Then reboot manually, when the error message pops up.
1. If you have trouble with the machine name: try to shorten it to 16 chars.
1. Configure the Docker credentials for GCP: 1. Configure the Docker credentials for GCP:
```powershell ```powershell
gcloud components install docker-credential-gcr gcloud init # set options according to ./k8s_config here
docker-credential-gcr configure-docker gcloud components install docker-credential-gcr
``` docker-credential-gcr configure-docker
```
1. To build and run the current agent run: 1. To build and run the current agent run:
```powershell ```powershell
git clone https://github.com/google/llvm-premerge-checks cd c:\
cd llvm-premerge-checks\containers git clone https://github.com/google/llvm-premerge-checks
powershell .\build_run.ps1 agent-windows-jenkins cd llvm-premerge-checks\containers
``` .\build_deploy.ps1 agent-windows-buildkite # or agent-windows-jenkins
1. If you want to be able to push changes to github, you need to set up your github SSH keys and user name: c:\llvm-premerge-check\scripts\windows_agent_start_buildkite.ps1 # or windows_agent_start_jenkins.ps1
```powershell ```
ssh-keygen
git config --global user.name <your name>
git config --global user.email <your email>
```
To push push a new container run in `containers`:
```powershell
powershell .\build_deploy.ps1 <container-folder>
```
## Spawning a new windows agent ## Spawning a new windows agent
@ -118,20 +113,21 @@ To spawn a new windows agent:
1. Go to the [GCP page](https://pantheon.corp.google.com/compute/instances?project=llvm-premerge-checks&instancessize=50) and pick a new number for the agent. 1. Go to the [GCP page](https://pantheon.corp.google.com/compute/instances?project=llvm-premerge-checks&instancessize=50) and pick a new number for the agent.
1. Run `kubernetes/windows_agent_create.sh agent-windows-<number>` 1. Run `kubernetes/windows_agent_create.sh agent-windows-<number>`
1. Go to the [GCP page](https://pantheon.corp.google.com/compute/instances?project=llvm-premerge-checks&instancessize=50) again 1. Go to the [GCP page](https://pantheon.corp.google.com/compute/instances?project=llvm-premerge-checks&instancessize=50) again
1. login to the new machine via RDP (you probably need to set the i). 1. login to the new machine via RDP (you will need a RDP client, e.g. Chrome app).
1. In the RDP session: run these commands in the CMD window to bootstrap the Windows machine: 1. In the RDP session: run these commands in the CMD window under Administrator to bootstrap the Windows machine:
```powershell ```powershell
Invoke-WebRequest -uri 'https://raw.githubusercontent.com/google/llvm-premerge-checks/master/scripts/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 ./windows_agent_bootstrap.ps1
``` ```
1. Ignore the pop-up to format the new disk. Ignore the pop-up to format the new disk andw wait for the machine to reboot.
1. Wait for the machine to reboot, then copy the credendials from `windows-agent-2` in `c:\credentials` to the new machine to `c:\credentials`. You can do that by mounting a folder of your host machine via RDP into the Windows VMs. 1. Create `c:\credentials` folder with the agent credentials:
1: Copy the credientals to `C:\credentials` from another Windows agent. For *Buildkite* add file `buildkite-env.ps1`:
1. Run this script to start the container: ```powershell
```powershell $Env:buildkiteAgentToken = "secret-token"
Invoke-WebRequest -uri 'https://raw.githubusercontent.com/google/llvm-premerge-checks/master/scripts/windows_agent_start.ps1' -OutFile windows_agent_start.ps1 $Env:BUILDKITE_AGENT_TAGS = "queue=premerge;os=windows"
.\windows_agent_start.ps1 jenkins ```
``` For *Jenkins*: `build-agent-results_key.json` to access cloud storage copy from one of the existing machines.
1. Start the container `C:\llvm-premerge-checks\scripts\windows_agent_start_[buildkite|jenkins].ps1 `
## Testing scripts locally ## Testing scripts locally

View file

@ -30,6 +30,6 @@ gcloud beta compute instances create "${NAME}" \
--zone="${GCP_ZONE}" \ --zone="${GCP_ZONE}" \
--machine-type=n1-standard-16 \ --machine-type=n1-standard-16 \
--local-ssd=device-name=local-ssd-0 \ --local-ssd=device-name=local-ssd-0 \
--image=windows-server-2019-dc-v20191210 \ --image=windows-server-2019-dc-for-containers-v20200512 \
--image-project=windows-cloud \ --image-project=windows-cloud \
--boot-disk-size=100GB --boot-disk-size=100GB

View file

@ -50,5 +50,8 @@ choco install -y gcloudsdk --ignore-checksums
# exclude drive d from Virus scans, to get better performance # exclude drive d from Virus scans, to get better performance
Add-MpPreference -ExclusionPath D:\ Add-MpPreference -ExclusionPath D:\
# clone scripts repo (this one)
git clone https://github.com/google/llvm-premerge-checks.git "c:\llvm-premerge-checks"
# Reboot # Reboot
Restart-Computer -Force Restart-Computer -Force

View file

@ -0,0 +1,55 @@
# 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.
# Pull and start the Docker container for a Windows agent.
# To setup a Windows agent see docs/playbooks.md
param(
[string]$version = "latest",
[switch]$testing = $false
)
$NAME="agent-windows-buildkite"
$IMAGE="gcr.io/llvm-premerge-checks/${NAME}:${version}"
Write-Output "Authenticating docker..."
Write-Output "y`n" | gcloud auth configure-docker
Write-Output "Pulling new image..."
docker pull ${IMAGE}
Write-Output "Stopping old container..."
docker stop ${NAME}
docker rm ${NAME}
Write-Output "Starting container..."
if (${testing}) {
docker run -it `
-v D:\:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_AGENT_NAME=$env:computername `
-e BUILDKITE_BUILD_PATH=C:\ws `
--restart unless-stopped `
--name ${NAME} `
${IMAGE} powershell
} else {
docker run -d `
-v D:\:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_AGENT_NAME=$env:computername `
-e BUILDKITE_BUILD_PATH=C:\ws `
--restart unless-stopped `
--name ${NAME} `
${IMAGE}
}

View file

@ -15,17 +15,13 @@
# Pull and start the Docker container for a Windows agent. # Pull and start the Docker container for a Windows agent.
# To setup a Windows agent see docs/playbooks.md # To setup a Windows agent see docs/playbooks.md
# TODO: add parameter to bootstrap buildkite or jenkins
param( param(
[Parameter(Mandatory=$true)] [string]$version = "latest",
[ValidateSet("buildkite", "jenkins")]
[string]$master,
[switch]$testing = $false [switch]$testing = $false
) )
$NAME="agent-windows-${master}" $NAME="agent-windows-jenkins"
$IMAGE="gcr.io/llvm-premerge-checks/${NAME}" $IMAGE="gcr.io/llvm-premerge-checks/${NAME}:${version}"
Write-Output "Authenticating docker..." Write-Output "Authenticating docker..."
Write-Output "y`n" | gcloud auth configure-docker Write-Output "y`n" | gcloud auth configure-docker