Skip to content

Commit 7a1ec12

Browse files
[SHIR] Install Microsoft JDK and then delete msi to decrease image size
[SHIR] Remove SHIR msi to decrease image size
1 parent 0ac4ee4 commit 7a1ec12

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM mcr.microsoft.com/windows/servercore:ltsc2019
2+
ARG INSTALL_JDK=false
23

34
# Download the latest self-hosted integration runtime installer into the SHIR folder
45
COPY SHIR C:/SHIR/

SHIR/build.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ function Install-SHIR() {
3030
}
3131

3232
Write-Log "SHIR MSI Install Successfully"
33+
Write-Log "Will remove C:\SHIR\$MsiFileName"
34+
Remove-Item "C:\SHIR\$MsiFileName"
35+
Write-Log "Removed C:\SHIR\$MsiFileName"
36+
}
37+
38+
function Install-MSFT-JDK() {
39+
Write-Log "Install the Microsoft OpenJDK in the Windows container"
40+
41+
Write-Log "Downloading Microsoft OpenJDK 11 LTS msi"
42+
$JDKMsiFileName = 'microsoft-jdk-11-windows-x64.msi'
43+
44+
# Temporarily disable progress updates to speed up the download process. (See https://stackoverflow.com/questions/69942663/invoke-webrequest-progress-becomes-irresponsive-paused-while-downloading-the-fil)
45+
$ProgressPreference = 'SilentlyContinue'
46+
Invoke-WebRequest -Uri "https://aka.ms/download-jdk/$JDKMsiFileName" -OutFile "C:\SHIR\$JDKMsiFileName"
47+
$ProgressPreference = 'Continue'
48+
49+
Write-Log "Installing Microsoft OpenJDK"
50+
# Arguments pulled from https://learn.microsoft.com/en-us/java/openjdk/install#install-via-msi
51+
Start-Process msiexec.exe -Wait -ArgumentList "/i C:\SHIR\$JDKMsiFileName ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome INSTALLDIR=`"c:\Program Files\Microsoft\`" /quiet"
52+
if (!$?) {
53+
Write-Log "Microsoft OpenJDK MSI Install Failed"
54+
}
55+
Write-Log "Microsoft OpenJDK MSI Install Successfully"
56+
Write-Log "Will remove C:\SHIR\$JDKMsiFileName"
57+
Remove-Item "C:\SHIR\$JDKMsiFileName"
58+
Write-Log "Removed C:\SHIR\$JDKMsiFileName"
3359
}
3460

3561
function SetupEnv() {
@@ -39,5 +65,8 @@ function SetupEnv() {
3965
}
4066

4167
Install-SHIR
68+
if ([bool]::Parse($env:INSTALL_JDK)) {
69+
Install-MSFT-JDK
70+
}
4271

4372
exit 0

0 commit comments

Comments
 (0)