Skip to content

Instantly share code, notes, and snippets.

@TheCloudScout
Created November 4, 2019 19:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheCloudScout/55f08413b86ad1dc8b1c8278538896a5 to your computer and use it in GitHub Desktop.
Save TheCloudScout/55f08413b86ad1dc8b1c8278538896a5 to your computer and use it in GitHub Desktop.
adsha-windowsservercore-ltsc2019-dotnet-4.8
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Install .NET 4.8
RUN curl -fSLo dotnet-framework-installer.exe https://download.visualstudio.microsoft.com/download/pr/7afca223-55d2-470a-8edc-6a1739ae3252/abd170b4b0ec15ad0222a809b761a036/ndp48-x86-x64-allos-enu.exe `
&& .\dotnet-framework-installer.exe /q `
&& del .\dotnet-framework-installer.exe `
&& powershell Remove-Item -Force -Recurse ${Env:TEMP}\*
# Apply latest patch
RUN curl -fSLo patch.msu http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/09/windows10.0-kb4514358-x64_b93fca9a74bb0e75ba9e878dd5f2fc537b92a32b.msu `
&& mkdir patch `
&& expand patch.msu patch -F:* `
&& del /F /Q patch.msu `
&& DISM /Online /Quiet /Add-Package /PackagePath:C:\patch\Windows10.0-kb4514358-x64.cab `
&& rmdir /S /Q patch
# ngen .NET Fx
ENV COMPLUS_NGenProtectedProcess_FeatureEnabled 0
RUN \Windows\Microsoft.NET\Framework64\v4.0.30319\ngen uninstall "Microsoft.Tpm.Commands, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=amd64" `
&& \Windows\Microsoft.NET\Framework64\v4.0.30319\ngen update `
&& \Windows\Microsoft.NET\Framework\v4.0.30319\ngen update
# Set default directory to C:\Agent
WORKDIR /agent
# Set PowerShell as default shell
SHELL [ "powershell", "-NoProfile", "-Command" ]
RUN $ProgressPreference = 'SilentlyContinue'
# Install VSTS/DevOps self-hosted Agent
ARG agentversion=2.158.0
ENV agentversion=${agentversion}
RUN Invoke-WebRequest -Uri "https://vstsagentpackage.azureedge.net/agent/$env:agentversion/vsts-agent-win-x64-$env:agentversion.zip" -OutFile "./vsts-agent-win-x64-$env:agentversion.zip" -UseBasicParsing ; `
Expand-Archive -Path "./vsts-agent-win-x64-$env:agentversion.zip" -DestinationPath . ; `
Remove-Item "./vsts-agent-win-x64-$env:agentversion.zip"
# Install PS Modules in C:\Modules
RUN New-Item -ItemType Directory -Name Modules -Path c:\ -Force | Out-Null ; `
Install-PackageProvider -Name NuGet -Force | Out-Null; `
Save-Module Az -Path c:\Modules -Confirm:$false | Out-Null; `
Save-Module Pester -Path c:\Modules -Confirm:$false | Out-Null; `
Save-Module PSScriptAnalyzer -Path c:\Modules -Confirm:$false | Out-Null
# Add C:\Modules to PSModulePatch environment variable
RUN $ModulesPath = [environment]::GetEnvironmentVariable('PSModulePath', [System.EnvironmentVariableTarget]::Machine) ; `
$NewModulesPath = 'C:\Modules;' + $ModulesPath ; `
[environment]::SetEnvironmentVariable('PSModulePath', $NewModulesPath, [System.EnvironmentVariableTarget]::Machine)
# Install Chocolately
ENV chocolateyUseWindowsCompression false
RUN Invoke-WebRequest -Uri 'https://chocolatey.org/install.ps1' -OutFile ./choco-install.ps1 ; `
.\\choco-install.ps1 | Out-Null ; `
choco feature disable --name showDownloadProgress ; `
Remove-Item ".\choco-install.ps1"
# Install Visual Studio Test Platform (vstest)
RUN Register-PackageSource -Name MyNuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet | Out-Null ; `
Install-Package Microsoft.TestPlatform -Force | Out-Null ; `
setx vstest 'c:\Program Files\PackageManagement\NuGet\Packages\Microsoft.TestPlatform.16.2.0\tools\net451\Common7\IDE\Extensions\TestPlatform'
# Install Visual Studio with dotNet workload
RUN Invoke-WebRequest "https://aka.ms/vs/16/release/vs_community.exe" -OutFile ".\vs_community.exe" -UseBasicParsing ; `
Start-Process .\vs_community.exe -ArgumentList '--add Microsoft.VisualStudio.Workload.NetWeb --quiet --norestart' -Wait ; `
Remove-Item ".\vs_community.exe" ; `
setx visualstudio 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin'
# Update PATH environment variable
RUN $machinePath = [environment]::GetEnvironmentVariable('path', [System.EnvironmentVariableTarget]::Machine) ; `
$newMachinePath = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin;' + $machinePath ; `
[environment]::SetEnvironmentVariable('path', $newMachinePath, [System.EnvironmentVariableTarget]::Machine)
# Install .NET Framework 4.6 Targeting Pack
RUN Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2099469" -OutFile ".\ndp46-targetingpack-kb3045566.exe" -UseBasicParsing ; `
Start-Process .\ndp46-targetingpack-kb3045566.exe -ArgumentList '/quiet /norestart' -Wait ; `
Remove-Item ".\ndp46-targetingpack-kb3045566.exe"
# Install Java runtime
RUN Invoke-WebRequest -Uri "https://repos.azul.com/azure-only/zulu/packages/zulu-7/7u232/zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64.zip" -OutFile ".\azulJDK7.zip" -UseBasicParsing ; `
Invoke-WebRequest -Uri "https://repos.azul.com/azure-only/zulu/packages/zulu-8/8u222/zulu-8-azure-jdk_8.40.0.25-8.0.222-win_x64.zip" -OutFile ".\azulJDK8.zip" -UseBasicParsing ; `
Invoke-WebRequest -Uri "https://repos.azul.com/azure-only/zulu/packages/zulu-11/11.0.4/zulu-11-azure-jdk_11.33.15-11.0.4-win_x64.zip" -OutFile ".\azulJDK11.zip" -UseBasicParsing ; `
# Expand the zips
Expand-Archive -Path '.\azulJDK7.zip' -DestinationPath 'C:\Program Files\Java\' -Force ; `
Expand-Archive -Path '.\azulJDK8.zip' -DestinationPath 'C:\Program Files\Java\' -Force ; `
Expand-Archive -Path '.\azulJDK11.zip' -DestinationPath 'C:\Program Files\Java\' -Force ; `
# Deleting zip folders
Remove-Item ".\azulJDK7.zip" ; `
Remove-Item ".\azulJDK8.zip" ; `
Remove-Item ".\azulJDK11.zip" ; `
# Get Java Paths
$java7Installs =Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*7*' | Sort-Object -Property Name -Descending | Select-Object -First 1 ; `
$latestJava7Install = $java7Installs.FullName ; `
$java8Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*8*' | Sort-Object -Property Name -Descending | Select-Object -First 1 ; `
$latestJava8Install = $java8Installs.FullName ; `
$java11Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*11*' | Sort-Object -Property Name -Descending | Select-Object -First 1 ; `
$latestJava11Install = $java11Installs.FullName ; `
# Set Java environet variables
setx java $latestJava8Install | Out-Null ; `
setx JAVA_HOME $latestJava8Install | Out-Null ; `
setx JAVA_HOME_7_X64 $latestJava7Install | Out-Null ; `
setx JAVA_HOME_8_X64 $latestJava8Install | Out-Null ; `
setx JAVA_HOME_11_X64 $latestJava11Install | Out-Null
# Clean up temp directory
RUN Remove-Item -Force -Recurse ${Env:TEMP}\*
# Execute VSTS/DevOps Agent configuration on startup
ENTRYPOINT [ "C:\\Windows\\system32\\cmd.exe", "/C", ".\\config.cmd --unattended --replace && .\\run.cmd" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment