From 451671cd88aee6971b9f89cde885c2fbb2f5edc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BChnel?= Date: Wed, 18 Dec 2019 17:29:21 +0000 Subject: [PATCH] tweaks for docker on windows --- containers/agent-windows-jenkins/Dockerfile | 45 ++++++------ .../agent-windows-jenkins/start_agent.bat | 7 +- containers/build_run.ps1 | 68 +++++++++---------- scripts/windows_agent_start.ps1 | 5 ++ 4 files changed, 70 insertions(+), 55 deletions(-) diff --git a/containers/agent-windows-jenkins/Dockerfile b/containers/agent-windows-jenkins/Dockerfile index 697cc24..0a84853 100644 --- a/containers/agent-windows-jenkins/Dockerfile +++ b/containers/agent-windows-jenkins/Dockerfile @@ -1,21 +1,26 @@ -# escape=` - -# use windows server core image -FROM gcr.io/llvm-premerge-checks/agent-windows - -# install java -RUN choco install -y openjdk - -# get Jenkins swarm plugin -ENV SWARM_PLUGIN_URL="https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/3.17/swarm-client-3.17.jar" -ENV SWARM_PLUGIN_JAR="C:\jenkins\swarm-client.jar" -RUN powershell -NoProfile -InputFormat None -Command ` - mkdir c:\jenkins ; ` - Invoke-WebRequest -Uri %SWARM_PLUGIN_URL% -OutFile %SWARM_PLUGIN_JAR% - -# network storage for build results -VOLUME C:\results - -# start swarm plugin -COPY start_agent.bat c:\jenkins +# escape=` + +# use windows server core image +FROM gcr.io/llvm-premerge-checks/agent-windows + +# install java +RUN choco install -y openjdk + +# get Jenkins swarm plugin +ENV SWARM_PLUGIN_URL="https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/3.17/swarm-client-3.17.jar" +ENV SWARM_PLUGIN_JAR="C:\jenkins\swarm-client.jar" +RUN powershell -NoProfile -InputFormat None -Command ` + mkdir c:\jenkins ; ` + Invoke-WebRequest -Uri %SWARM_PLUGIN_URL% -OutFile %SWARM_PLUGIN_JAR% + +# install gsutils to access Google Cloud Storage +RUN powershell -NoProfile -InputFormat None -Command ` + (New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe") ; ` + & $env:Temp\GoogleCloudSDKInstaller.exe ; ` + del $env:Temp\GoogleCloudSDKInstaller.exe +VOLUME C:\credentials +VOLUME C:\Temp + +# start swarm plugin +COPY start_agent.bat c:\jenkins CMD c:\jenkins\start_agent.bat \ No newline at end of file diff --git a/containers/agent-windows-jenkins/start_agent.bat b/containers/agent-windows-jenkins/start_agent.bat index bf7a308..ef39ff2 100644 --- a/containers/agent-windows-jenkins/start_agent.bat +++ b/containers/agent-windows-jenkins/start_agent.bat @@ -16,6 +16,11 @@ set JENKINS_SERVER=jenkins.local set AGENT_ROOT=C:\ws set WORKSPACE=%AGENT_ROOT%\workspace -if not exist "%WORKSPACE%" mkdir "%WORKSPACE%" + +@rem authenticate gsutil +gcloud auth activate-service-account --key-file C:\credentials\build-agent-results_key.json + +set TEMP=C:\TEMP +set TMP=%TEMP% java -jar %SWARM_PLUGIN_JAR% -master http://%JENKINS_SERVER%:8080 -executors 1 -fsroot %AGENT_ROOT% -labels windows \ No newline at end of file diff --git a/containers/build_run.ps1 b/containers/build_run.ps1 index 5bcd2c2..b0b3175 100644 --- a/containers/build_run.ps1 +++ b/containers/build_run.ps1 @@ -1,35 +1,35 @@ -# 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. - -# define command line arguments -param( - [Parameter(Mandatory=$true)][string]$IMAGE_NAME, - [Parameter(Mandatory=$false)][string]$CMD="", - [string]$token -) - -# set script to stop on first error -$ErrorActionPreference = "Stop" - -# some docs recommend setting 2GB memory limit - docker build --memory 2GB -t $IMAGE_NAME --build-arg token=$token "$PSScriptRoot\$IMAGE_NAME" -If ($LastExitCode -ne 0) { - exit -} - -# mount a persistent workspace for experiments -docker run -it -v D:\:C:\ws $IMAGE_NAME $CMD -If ($LastExitCode -ne 0) { - exit +# 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. + +# define command line arguments +param( + [Parameter(Mandatory=$true)][string]$IMAGE_NAME, + [Parameter(Mandatory=$false)][string]$CMD="", + [string]$token +) + +# set script to stop on first error +$ErrorActionPreference = "Stop" + +# some docs recommend setting 2GB memory limit + docker build --memory 2GB -t $IMAGE_NAME --build-arg token=$token "$PSScriptRoot\$IMAGE_NAME" +If ($LastExitCode -ne 0) { + exit +} + +# mount a persistent workspace for experiments +docker run -it -v D:\:C:\ws -v C:\credentials:C:\credentials $IMAGE_NAME $CMD +If ($LastExitCode -ne 0) { + exit } \ No newline at end of file diff --git a/scripts/windows_agent_start.ps1 b/scripts/windows_agent_start.ps1 index cfea116..3a218d9 100644 --- a/scripts/windows_agent_start.ps1 +++ b/scripts/windows_agent_start.ps1 @@ -19,6 +19,11 @@ $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 `