diff --git a/containers/buildkite-windows/Dockerfile b/containers/buildkite-windows/Dockerfile index 485c7f4..2ed2944 100644 --- a/containers/buildkite-windows/Dockerfile +++ b/containers/buildkite-windows/Dockerfile @@ -98,9 +98,7 @@ RUN git config --system core.longpaths true & ` # handle for debugging of files beeing locked by some processes. RUN choco install -y handle COPY start_agent.ps1 c:\scripts\ -COPY pre-checkout.ps1 c:\scripts\ -COPY post-checkout.ps1 c:\scripts\ COPY unlock_path.ps1 c:\scripts\ +COPY pre-checkout.sh c:\scripts\ COPY pre-checkout.bat c:\buildkite-agent\hooks\ -COPY post-checkout.bat c:\buildkite-agent\hooks\ CMD ["powershell", "C:\\scripts\\start_agent.ps1"] \ No newline at end of file diff --git a/containers/buildkite-windows/post-checkout.bat b/containers/buildkite-windows/post-checkout.bat deleted file mode 100644 index 0e0f992..0000000 --- a/containers/buildkite-windows/post-checkout.bat +++ /dev/null @@ -1,2 +0,0 @@ -echo "post-checkout" -powershell c:\scripts\post-checkout.ps1 diff --git a/containers/buildkite-windows/post-checkout.ps1 b/containers/buildkite-windows/post-checkout.ps1 deleted file mode 100644 index 3cc286e..0000000 --- a/containers/buildkite-windows/post-checkout.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -# 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. - -# As git gc takes non-trivial time on windows, run it only 5% of the time. -if (( Get-Random -Maximum 100 ) -lt 10 ) { - echo "running git gc" - pwd - git gc -} - diff --git a/containers/buildkite-windows/pre-checkout.ps1 b/containers/buildkite-windows/pre-checkout.ps1 deleted file mode 100644 index 7fb149e..0000000 --- a/containers/buildkite-windows/pre-checkout.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -# $env:BUILDKITE_BUILD_CHECKOUT_PATH="$env:BUILDKITE_BUILD_PATH/src" -echo "BUILDKITE_BUILD_CHECKOUT_PATH: $env:BUILDKITE_BUILD_CHECKOUT_PATH" -echo "BUILDKITE_BUILD_PATH: $env:BUILDKITE_BUILD_PATH" -echo "unlocking git" -taskkill /F /IM git.exe -rm -Force "$env:BUILDKITE_BUILD_CHECKOUT_PATH/.git/index.lock" -echo 'running processes (before)' -Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_CHECKOUT_PATH*"} | Select-Object -ExpandProperty Path -echo "unlocking $env:BUILDKITE_BUILD_CHECKOUT_PATH" -handle -nobanner $env:BUILDKITE_BUILD_CHECKOUT_PATH -c:\scripts\unlock_path.ps1 $env:BUILDKITE_BUILD_CHECKOUT_PATH -echo 'running processes (after)' -Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_CHECKOUT_PATH*"} | Select-Object -ExpandProperty Path - -echo "BUILDKITE_REPO: $env:BUILDKITE_REPO" -if (Test-Path -Path $env:BUILDKITE_BUILD_CHECKOUT_PATH) { - Set-Location -Path $env:BUILDKITE_BUILD_CHECKOUT_PATH - $remoteUrl = git remote get-url origin - echo "current remote URL: $remoteUrl" - if ($remoteUrl -ne $env:BUILDKITE_REPO) { - Write-Host "Remote URL does not match. Deleting and recreating the directory." - Set-Location -Path "c:\" - Remove-Item -Recurse -Force -ErrorAction Ignore $env:BUILDKITE_BUILD_CHECKOUT_PATH - } -} - diff --git a/containers/buildkite-windows/pre-checkout.sh b/containers/buildkite-windows/pre-checkout.sh index aca9da0..30ffc59 100644 --- a/containers/buildkite-windows/pre-checkout.sh +++ b/containers/buildkite-windows/pre-checkout.sh @@ -3,7 +3,7 @@ echo "BUILDKITE_BUILD_CHECKOUT_PATH: $BUILDKITE_BUILD_CHECKOUT_PATH" echo "BUILDKITE_BUILD_PATH: $BUILDKITE_BUILD_PATH" echo "unlocking git" -pkill -f git.exe +taskkill -F -IM git.exe rm -f "$BUILDKITE_BUILD_CHECKOUT_PATH/.git/index.lock" echo 'running processes (before)' ps aux | grep "$BUILDKITE_BUILD_CHECKOUT_PATH" @@ -22,5 +22,15 @@ if [ -d "$BUILDKITE_BUILD_CHECKOUT_PATH" ]; then echo "Remote URL does not match. Deleting and recreating the directory." cd /c/ rm -rf "$BUILDKITE_BUILD_CHECKOUT_PATH" + rm /c/ws/git_gc_counter + else + # Run git gc from time to time to prevent repo from growing. + echo -n "x" >> /c/ws/git_gc_counter + echo "GC counter $(wc -c < /c/ws/git_gc_counter)/10" + if [ "$(wc -c < /c/ws/git_gc_counter)" -gt 10 ]; then + echo "Running 'git gc'..." + git gc + rm /c/ws/git_gc_counter + fi fi fi \ No newline at end of file diff --git a/containers/buildkite-windows/start_agent.ps1 b/containers/buildkite-windows/start_agent.ps1 index c8bee3d..4a15ef5 100644 --- a/containers/buildkite-windows/start_agent.ps1 +++ b/containers/buildkite-windows/start_agent.ps1 @@ -1,11 +1,10 @@ +# TODO: remove after migrating scripts to LLVM repo. git clone https://github.com/google/llvm-premerge-checks.git c:\llvm-premerge-checks -New-Item c:\ws -Force -ItemType Directory -$env:BUILDKITE_BUILD_PATH = "c:\ws" -$env:BUILDKITE_BUILD_CHECKOUT_PATH = "c:\ws\src" +$env:BUILDKITE_BUILD_CHECKOUT_PATH = "$env:BUILDKITE_BUILD_PATH\src" # Install Buildkite agent. 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="$env:BUILDKITE_BUILD_PATH\sccache" $env:SCCACHE_IDLE_TIMEOUT="0" Remove-Item -Recurse -Force -ErrorAction Ignore $env:SCCACHE_DIR sccache --start-server