Last active
September 23, 2020 01:29
-
-
Save rohancme/30f0db04f31f381309cfc436044ba5fb to your computer and use it in GitHub Desktop.
My base MSBuild image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM microsoft/windowsservercore | |
# Pass in JENKINS_SECRET and JENKINS_JNLP_URL as an environment variables | |
# Install jre and add to PATH | |
# Do not recommend pushing the image to a public repository due to Oracle's EULA: http://www.oracle.com/technetwork/java/javase/documentation/index.html | |
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | |
RUN wget 'http://javadl.oracle.com/webapps/download/AutoDL?BundleId=210185' -Outfile 'C:\jreinstaller.exe' ; \ | |
Start-Process -filepath C:\jreinstaller.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre1.8.0_91" ; \ | |
del C:\jreinstaller.exe | |
ENV JAVA_HOME c:\\Java\\jre1.8.0_91 | |
RUN setx PATH %PATH%;%JAVA_HOME%\bin | |
# Install msbuild (vs2017) and add to PATH | |
RUN Invoke-WebRequest "https://aka.ms/vs/15/release/vs_BuildTools.exe" -OutFile vs_BuildTools.exe -UseBasicParsing ; \ | |
Start-Process -FilePath 'vs_BuildTools.exe' -ArgumentList '--quiet', '--norestart', '--locale en-US' -Wait ; \ | |
Remove-Item .\vs_BuildTools.exe ; \ | |
Remove-Item -Force -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer' | |
RUN setx /M PATH $($Env:PATH + ';' + ${Env:ProgramFiles(x86)} + '\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin') | |
# Install git through chocolatey and add git to the path | |
ENV chocolateyUseWindowsCompression false | |
RUN iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); \ | |
choco install -v -y git | |
RUN setx /M PATH $($Env:PATH + ';' + 'C:\Program Files\Git\usr\bin') | |
# Pass in the base url of the master node while building | |
ARG BASE_URL | |
ENV HOME C:\Jenkins | |
# Get Jenkins slave jar | |
RUN (New-Object System.Net.WebClient).DownloadFile('{0}/jnlpJars/slave.jar' -f $env:BASE_URL, 'slave.jar') ; | |
# For some reason just using C:\Jenkins does not work - it tries to map to \ContainerVolumes in k8s. The workaround is to mount the folder as a drive and use it as the working directory for builds | |
RUN set-itemproperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'G:' -Value '\??\C:\Jenkins' -Type String | |
ENTRYPOINT C:\Java\jre1.8.0_91\bin\java.exe -jar C:\slave.jar -jnlpUrl $env:JENKINS_JNLP_URL -secret $env:JENKINS_SECRET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment