1
0
Fork 0

Pre-checkout for windows

Kill all running processes in BUILDKITE_BUILD_PATH and force unlock git
folder.
This commit is contained in:
Mikhail Goncharov 2021-06-01 15:26:00 +02:00
parent 7ca96eee86
commit 8960ff7dc9
9 changed files with 154 additions and 83 deletions

View file

@ -7,5 +7,4 @@ FROM gcr.io/llvm-premerge-checks/agent-windows-vs2019:${agent_windows_version}
RUN choco install -y handle --checksum 524E61547C8E26608CDA1B11B6E9471616CCCC48530F6E7EC9131EABF839357E RUN choco install -y handle --checksum 524E61547C8E26608CDA1B11B6E9471616CCCC48530F6E7EC9131EABF839357E
COPY start_agent.ps1 C:\scripts\ COPY start_agent.ps1 C:\scripts\
COPY pre-checkout.bat c:\buildkite-agent\hooks\ COPY pre-checkout.bat c:\buildkite-agent\hooks\
COPY unlock_path.ps1 c:\scripts
CMD "powershell C:\scripts\start_agent.ps1" CMD "powershell C:\scripts\start_agent.ps1"

View file

@ -1,2 +1,5 @@
handle -nobanner %BUILDKITE_BUILD_CHECKOUT_PATH% echo "pre-checkout: update scripts"
powershell c:\scripts\unlock_path.ps1 %BUILDKITE_BUILD_CHECKOUT_PATH% cd c:\llvm-premerge-checks
git pull
git rev-parse HEAD
powershell c:\llvm-premerge-checks\scripts\windows\pre-checkout.ps1

View file

@ -1,7 +1,7 @@
c:\credentials\buildkite-env.ps1 c:\credentials\buildkite-env.ps1
git clone https://github.com/google/llvm-premerge-checks.git c:\llvm-premerge-checks
# Install Buildkite agent. # Install Buildkite agent.
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'))
$env:SCCACHE_DIR="C:\ws\sccache" $env:SCCACHE_DIR="C:\ws\sccache"
$env:SCCACHE_IDLE_TIMEOUT="0" $env:SCCACHE_IDLE_TIMEOUT="0"
Remove-Item -Recurse -Force -ErrorAction Ignore $env:SCCACHE_DIR Remove-Item -Recurse -Force -ErrorAction Ignore $env:SCCACHE_DIR

View file

@ -32,10 +32,13 @@ If ($LastExitCode -ne 0) {
exit exit
} }
$DIGEST=$(docker image inspect --format "{{range .RepoDigests}}{{.}}{{end}}" $IMAGE_NAME) -replace ".*@sha256:(.{6})(.*)$","`$1"
# mount a persistent workspace for experiments # mount a persistent workspace for experiments
docker run -it ` docker run -it `
-v C:/ws:C:/ws ` -v C:/ws:C:/ws `
-v C:/credentials:C:/credentials ` -v C:/credentials:C:/credentials `
-e BUILDKITE_BUILD_PATH=C:\ws `
-e IMAGE_DIGEST=${DIGEST} `
-e PARENT_HOSTNAME=$env:computername ` -e PARENT_HOSTNAME=$env:computername `
$IMAGE_NAME $CMD $IMAGE_NAME $CMD
If ($LastExitCode -ne 0) { If ($LastExitCode -ne 0) {

View file

@ -110,7 +110,7 @@ def generic_windows(projects: str) -> List:
], ],
'artifact_paths': ['artifacts/**/*', '*_result.json', 'build/test-results.xml'], 'artifact_paths': ['artifacts/**/*', '*_result.json', 'build/test-results.xml'],
'agents': win_agents, 'agents': win_agents,
'timeout_in_minutes': 120, 'timeout_in_minutes': 150,
'retry': {'automatic': [ 'retry': {'automatic': [
{'exit_status': -1, 'limit': 2}, # Agent lost {'exit_status': -1, 'limit': 2}, # Agent lost
{'exit_status': 255, 'limit': 2}, # Forced agent shutdown {'exit_status': 255, 'limit': 2}, # Forced agent shutdown

View file

@ -0,0 +1,26 @@
# Copyright 2021 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.
echo "BUILDKITE_BUILD_CHECKOUT_PATH: $env:BUILDKITE_BUILD_CHECKOUT_PATH"
echo "unlocking git"
taskkill /F /IM git.exe
rm -Force "$env:BUILDKITE_BUILD_CHECKOUT_PATH/.git/index.lock"
echo "BUILDKITE_BUILD_PATH: $env:BUILDKITE_BUILD_PATH"
echo 'running processes (before)'
Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_PATH*"} | Select-Object -ExpandProperty Path
echo "unlocking $env:BUILDKITE_BUILD_PATH"
handle -nobanner $env:BUILDKITE_BUILD_CHECKOUT_PATH
c:\llvm-premerge-checks\scripts\windows\unlock_path.ps1 $env:BUILDKITE_BUILD_CHECKOUT_PATH
echo 'running processes (after)'
Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_PATH*"} | Select-Object -ExpandProperty Path

View file

@ -0,0 +1,53 @@
# Copyright 2021 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 = "stable",
[switch]$testing = $false,
[string]$workdir = "c:\ws"
)
$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 '${IMAGE}'..."
docker pull ${IMAGE}
$DIGEST=$(docker image inspect --format "{{range .RepoDigests}}{{.}}{{end}}" $IMAGE) -replace ".*@sha256:(.{6})(.*)$","`$1"
Write-Output "Image digest ${DIGEST}"
Write-Output "Stopping old container..."
docker stop ${NAME}
docker rm ${NAME}
Write-Output "Starting container..."
if (${testing}) {
docker run -it `
-v ${workdir}:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_BUILD_PATH=C:\ws `
-e IMAGE_DIGEST=${DIGEST} `
${IMAGE} powershell
} else {
docker run -d `
-v ${workdir}:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_BUILD_PATH=C:\ws `
-e IMAGE_DIGEST=${DIGEST} `
--name ${NAME} `
${IMAGE}
}

View file

@ -1,12 +1,25 @@
# Copyright 2021 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.
# Based ob https://dandraka.com/2019/08/13/find-and-kill-processes-that-lock-a-file-or-directory/ # Based ob https://dandraka.com/2019/08/13/find-and-kill-processes-that-lock-a-file-or-directory/
$path = $args[0] $path = $args[0]
$handleOutput = & handle -a $path $handleOutput = & handle -a $path
Write-Host "Unlocking path" $path
if ($handleOutput -match "no matching handles found") { if ($handleOutput -match "no matching handles found") {
Write-Host "Nothing to kill, exiting" Write-Host "Nothing to kill, exiting"
exit exit
} }
$pidList = New-Object System.Collections.ArrayList $pidList = New-Object System.Collections.ArrayList
$lines = $handleOutput -split "`n" $lines = $handleOutput -split "`n"
foreach($line in $lines) { foreach($line in $lines) {

View file

@ -12,42 +12,16 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Pull and start the Docker container for a Windows agent. # Invoked at startup of windows machine. This indirection allows to simply
# To setup a Windows agent see docs/playbooks.md # restart a machine and it will pick up all script changes and will use the
# latest stable image.
param( param(
[string]$version = "latest", [string]$version = "stable",
[switch]$testing = $false, [switch]$testing = $false,
[string]$workdir = "c:\ws" [string]$workdir = "c:\ws"
) )
$NAME="agent-windows-buildkite" cd c:\llvm-premerge-checks
$IMAGE="gcr.io/llvm-premerge-checks/${NAME}:${version}" git pull
c:\llvm-premerge-checks\scripts\windows\start_container.ps1 -version $version -testing $testing -workdir $workdir
Write-Output "Authenticating docker..."
Write-Output "y`n" | gcloud auth configure-docker
Write-Output "Pulling new image '${IMAGE}'..."
docker pull ${IMAGE}
$DIGEST=$(docker image inspect --format "{{range .RepoDigests}}{{.}}{{end}}" $IMAGE) -replace ".*@sha256:(.{6})(.*)$","`$1"
Write-Output "Image digest ${DIGEST}"
Write-Output "Stopping old container..."
docker stop ${NAME}
docker rm ${NAME}
Write-Output "Starting container..."
if (${testing}) {
docker run -it `
-v ${workdir}:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_BUILD_PATH=C:\ws `
-e IMAGE_DIGEST=${DIGEST} `
${IMAGE} powershell
} else {
docker run -d `
-v ${workdir}:C:\ws `
-v C:\credentials:C:\credentials `
-e BUILDKITE_BUILD_PATH=C:\ws `
-e IMAGE_DIGEST=${DIGEST} `
--name ${NAME} `
${IMAGE}
}