forked from JetBrains/teamcity-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
92 lines (72 loc) · 3.77 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Default arguments
ARG jdkWindowsComponent='https://corretto.aws/downloads/resources/8.272.10.3/amazon-corretto-8.272.10.3-windows-x64-jdk.zip'
ARG jdkWindowsComponentMD5SUM='244b50667ef3b040191ae4083e3438e7'
ARG jreWindowsComponent='https://corretto.aws/downloads/resources/8.272.10.3/amazon-corretto-8.272.10.3-windows-x64-jre.zip'
ARG jreWindowsComponentMD5SUM='9f63d24e072072b2e7ec94ddb3f594e2'
ARG nanoserverImage='mcr.microsoft.com/windows/nanoserver:1809'
ARG powershellImage='mcr.microsoft.com/powershell:nanoserver-1809'
# The list of required arguments
# ARG jreWindowsComponent
# ARG jreWindowsComponentMD5SUM
# ARG jdkWindowsComponent
# ARG jdkWindowsComponentMD5SUM
# ARG nanoserverImage
# ARG powershellImage
FROM ${powershellImage} AS base
COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Prepare build agent distribution
COPY TeamCity/buildAgent C:/BuildAgent
COPY run-agent.ps1 /BuildAgent/run-agent.ps1
ARG jreWindowsComponent
ARG jreWindowsComponentMD5SUM
ARG jdkWindowsComponent
ARG jdkWindowsComponentMD5SUM
RUN [Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11, tls' ; \
$code = Get-Content -Path "scripts/Web.cs" -Raw ; \
Add-Type -TypeDefinition "$code" -Language CSharp ; \
$downloadScript = [Scripts.Web]::DownloadFiles($Env:jreWindowsComponent + '#MD5#' + $Env:jreWindowsComponentMD5SUM, 'jre.zip', $Env:jdkWindowsComponent + '#MD5#' + $Env:jdkWindowsComponentMD5SUM, 'jdk.zip') ; \
iex $downloadScript ; \
Expand-Archive jre.zip -DestinationPath $Env:ProgramFiles\Java ; \
Get-ChildItem $Env:ProgramFiles\Java | Rename-Item -NewName "OpenJDK" ; \
Remove-Item -Force jre.zip ; \
Expand-Archive jdk.zip -DestinationPath $Env:Temp\JDK ; \
Get-ChildItem $Env:Temp\JDK | Rename-Item -NewName "OpenJDK" ; \
('jar.exe', 'jcmd.exe', 'jconsole.exe', 'jmap.exe', 'jstack.exe', 'jps.exe') | foreach { \
Copy-Item $Env:Temp\JDK\OpenJDK\bin\$_ $Env:ProgramFiles\Java\OpenJDK\bin\ \
} ; \
Remove-Item -Force -Recurse $Env:Temp\JDK ; \
Remove-Item -Force jdk.zip ; \
(Get-Content /BuildAgent/system/.teamcity-agent/unpacked-plugins.xml).replace('/', '\\') | Set-Content /BuildAgent/system/.teamcity-agent/unpacked-plugins.xml
# Workaround for https://github.com/PowerShell/PowerShell-Docker/issues/164
ARG nanoserverImage
FROM ${nanoserverImage}
ENV ProgramFiles="C:\Program Files" \
# set a fixed location for the Module analysis cache
PSModuleAnalysisCachePath="C:\Users\ContainerUser\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" \
# Persist %PSCORE% ENV variable for user convenience
PSCORE="$ProgramFiles\PowerShell\pwsh.exe"
COPY --from=base ["C:/Program Files/PowerShell", "C:/Program Files/PowerShell"]
# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;%ProgramFiles%\PowerShell"
USER ContainerUser
# intialize powershell module cache
RUN pwsh -NoLogo -NoProfile -Command " \
$stopTime = (get-date).AddMinutes(15); \
$ErrorActionPreference = 'Stop' ; \
$ProgressPreference = 'SilentlyContinue' ; \
while(!(Test-Path -Path $env:PSModuleAnalysisCachePath)) { \
Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \
if((get-date) -gt $stopTime) { throw 'timout expired'} \
Start-Sleep -Seconds 6 ; \
}"
COPY --from=base ["C:/Program Files/Java/OpenJDK", "C:/Program Files/Java/OpenJDK"]
ENV JRE_HOME="C:\Program Files\Java\OpenJDK" \
CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties"
COPY --chown=ContainerUser --from=base /BuildAgent /BuildAgent
VOLUME C:/BuildAgent/conf
VOLUME C:/BuildAgent/work
VOLUME C:/BuildAgent/temp
VOLUME C:/BuildAgent/logs
CMD pwsh ./BuildAgent/run-agent.ps1