-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #34 - Windows based docker images for maven (jdk8 and jdk11 supported) #119
Changes from all commits
f370e1c
edbfbb7
5f50f0c
0243415
7da4320
1a7112d
e483302
188e9f1
6d4f058
2d1ce89
87864fb
336b312
297328d
2ee9fff
929e16b
5f26db8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# escape=` | ||
ARG WINDOWS_DOCKER_TAG=ltsc2019 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_DOCKER_TAG | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
ARG zip=amazon-corretto-11.0.4.11.1-windows-x64.zip | ||
ARG uri=https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/ | ||
ARG hash=707c839c3f56645454b8c8d31f255161 | ||
|
||
RUN Invoke-WebRequest -Uri $('{0}{1}' -f $env:uri,$env:zip) -OutFile C:/$env:zip ; ` | ||
if((Get-FileHash C:/$env:zip -Algorithm MD5).Hash.ToLower() -ne $env:hash) { exit 1 } ; ` | ||
Expand-Archive -Path C:/$env:zip -Destination C:/ProgramData ; ` | ||
Remove-Item C:/${env:zip} | ||
|
||
ENV JAVA_HOME=C:/ProgramData/jdk11.0.4_10 | ||
|
||
|
||
ARG MAVEN_VERSION=3.6.1 | ||
ARG USER_HOME_DIR="C:/Users/ContainerAdministrator" | ||
ARG SHA=51169366d7269ed316bad013d9cbfebe3a4ef1fda393ac4982d6dbc9af2d5cc359ee12838b8041cb998f236486e988b9c05372f4fdb29a96c1139f63c991e90e | ||
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries | ||
|
||
RUN Invoke-WebRequest -Uri ${env:BASE_URL}/apache-maven-${env:MAVEN_VERSION}-bin.zip -OutFile ${env:TEMP}/apache-maven.zip ; ` | ||
if((Get-FileHash -Algorithm SHA512 -Path ${env:TEMP}/apache-maven.zip).Hash.ToLower() -ne ${env:SHA}) { exit 1 } ; ` | ||
Expand-Archive -Path ${env:TEMP}/apache-maven.zip -Destination C:/ProgramData ; ` | ||
Move-Item C:/ProgramData/apache-maven-${env:MAVEN_VERSION} C:/ProgramData/Maven ; ` | ||
New-Item -ItemType Directory -Path C:/ProgramData/Maven/Reference | Out-Null ; ` | ||
Remove-Item ${env:TEMP}/apache-maven.zip | ||
|
||
ENV MAVEN_HOME C:/ProgramData/Maven | ||
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" | ||
|
||
# Workaround https://github.com/corretto/corretto-8-docker/pull/32 | ||
#ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto | ||
|
||
COPY mvn-entrypoint.ps1 C:/ProgramData/Maven/mvn-entrypoint.ps1 | ||
COPY settings-docker.xml C:/ProgramData/Maven/Reference/settings-docker.xml | ||
RUN $content = Get-Content "C:/ProgramData/Maven/Reference/settings-docker.xml" ; ` | ||
$content | ForEach-Object { $_ -replace '/usr/share/maven/ref/repository','C:\ProgramData\Maven\Reference\repository' } | ` | ||
Set-Content -Path "C:/ProgramData/Maven/Reference/settings-docker.xml" | ||
|
||
RUN setx /M PATH $('{0};{1}' -f $env:PATH,'C:\ProgramData\Maven\bin') | Out-Null | ||
|
||
ENTRYPOINT ["powershell.exe", "-f", "C:/ProgramData/Maven/mvn-entrypoint.ps1"] | ||
CMD ["mvn"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
# Copy files from C:/ProgramData/Maven/Reference into ${MAVEN_CONFIG} | ||
# So the initial ~/.m2 is set with expected content. | ||
# Don't override, as this is just a reference setup | ||
|
||
function Copy-ReferenceFiles() { | ||
$log = "${env:MAVEN_CONFIG}/copy_reference_file.log" | ||
$ref = "C:/ProgramData/Maven/Reference" | ||
|
||
$repo = Join-Path $env:MAVEN_CONFIG 'repository' | ||
|
||
New-Item -Path $repo -ItemType Directory -Force | Out-Null | ||
Write-Output $null > $log | ||
if((Test-Path $repo) -and (Test-Path $log)) { | ||
$count = (Get-ChildItem $repo | Measure-Object).Count | ||
if($count -eq 0) { | ||
# destination is empty... | ||
Add-Content -Path $log -Value "--- Copying all files to ${env:MAVEN_CONFIG} at $(Get-Date)" | ||
Copy-Item -Path "$ref\*" -Destination $env:MAVEN_CONFIG -Force -Recurse | Add-Content -Path $log | ||
} else { | ||
# destination is non-empty, copy file-by-file | ||
Add-Content -Path $log -Value "--- Copying individual files to ${MAVEN_CONFIG} at $(Get-Date)" | ||
Get-ChildItem -Path $ref -File | ForEach-Object { | ||
Push-Location $ref | ||
$rel = Resolve-Path -Path $($_.FullName) -Relative | ||
Pop-Location | ||
if(!(Test-Path (Join-Path $env:MAVEN_CONFIG $rel)) -or (Test-Path $('{0}.override' -f $_.FullName))) { | ||
$dir = Join-Path $env:MAVEN_CONFIG $($rel.DirectoryName) | ||
if(!(Test-Path $dir)) { | ||
New-Item -Path $dir -ItemType Directory | Out-Null | ||
} | ||
Copy-Item -Path $_.FullName -Destination (Join-Path $env:MAVEN_CONFIG $rel) | Add-Content -Path $log | ||
} | ||
} | ||
} | ||
Add-Content -Path $log -Value "" | ||
} else { | ||
Write-Warning "Can not write to ${log}. Wrong volume permissions? Carrying on ..." | ||
} | ||
} | ||
|
||
Push-Location -StackName 'maven-entrypoint' | ||
Copy-ReferenceFiles | ||
Pop-Location -StackName 'maven-entrypoint' | ||
|
||
Remove-Item Env:\MAVEN_CONFIG | ||
|
||
Invoke-Expression "$args" | ||
exit $lastExitCode |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# escape=` | ||
ARG WINDOWS_DOCKER_TAG=ltsc2019 | ||
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_DOCKER_TAG | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
ARG zip=amazon-corretto-8.222.10.3-windows-x64-jdk.zip | ||
ARG uri=https://d3pxv6yz143wms.cloudfront.net/8.222.10.1/ | ||
ARG hash=9879a7f69c0bd7d8c1bbb916df7b5f82 | ||
|
||
RUN Invoke-WebRequest -Uri $('{0}{1}' -f $env:uri,$env:zip) -OutFile C:/$env:zip ; ` | ||
if((Get-FileHash C:/$env:zip -Algorithm MD5).Hash.ToLower() -ne $env:hash) { exit 1 } ; ` | ||
Expand-Archive -Path C:/$env:zip -Destination C:/ProgramData ; ` | ||
Remove-Item C:/${env:zip} | ||
|
||
ENV JAVA_HOME=C:/ProgramData/jdk1.8.0_222 | ||
|
||
|
||
ARG MAVEN_VERSION=3.6.1 | ||
ARG USER_HOME_DIR="C:/Users/ContainerAdministrator" | ||
ARG SHA=51169366d7269ed316bad013d9cbfebe3a4ef1fda393ac4982d6dbc9af2d5cc359ee12838b8041cb998f236486e988b9c05372f4fdb29a96c1139f63c991e90e | ||
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries | ||
|
||
RUN Invoke-WebRequest -Uri ${env:BASE_URL}/apache-maven-${env:MAVEN_VERSION}-bin.zip -OutFile ${env:TEMP}/apache-maven.zip ; ` | ||
if((Get-FileHash -Algorithm SHA512 -Path ${env:TEMP}/apache-maven.zip).Hash.ToLower() -ne ${env:SHA}) { exit 1 } ; ` | ||
Expand-Archive -Path ${env:TEMP}/apache-maven.zip -Destination C:/ProgramData ; ` | ||
Move-Item C:/ProgramData/apache-maven-${env:MAVEN_VERSION} C:/ProgramData/Maven ; ` | ||
New-Item -ItemType Directory -Path C:/ProgramData/Maven/Reference | Out-Null ; ` | ||
Remove-Item ${env:TEMP}/apache-maven.zip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yow, a lot of duplicated content between images. Is there a straightforward way to share some of these steps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. I am not a super user with docker, so I am not aware of any tricks for sharing content. I based my implementation on the existing image setup. |
||
|
||
ENV MAVEN_HOME C:/ProgramData/Maven | ||
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" | ||
|
||
# Workaround https://github.com/corretto/corretto-8-docker/pull/32 | ||
#ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto | ||
|
||
COPY mvn-entrypoint.ps1 C:/ProgramData/Maven/mvn-entrypoint.ps1 | ||
COPY settings-docker.xml C:/ProgramData/Maven/Reference/settings-docker.xml | ||
RUN $content = Get-Content "C:/ProgramData/Maven/Reference/settings-docker.xml" ; ` | ||
$content | ForEach-Object { $_ -replace '/usr/share/maven/ref/repository','C:\ProgramData\Maven\Reference\repository' } | ` | ||
Set-Content -Path "C:/ProgramData/Maven/Reference/settings-docker.xml" | ||
|
||
RUN setx /M PATH $('{0};{1}' -f $env:PATH,'C:\ProgramData\Maven\bin') | Out-Null | ||
|
||
ENTRYPOINT ["powershell.exe", "-f", "C:/ProgramData/Maven/mvn-entrypoint.ps1"] | ||
CMD ["mvn"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
# Copy files from C:/ProgramData/Maven/Reference into ${MAVEN_CONFIG} | ||
# So the initial ~/.m2 is set with expected content. | ||
# Don't override, as this is just a reference setup | ||
|
||
function Copy-ReferenceFiles() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, we should not have a dozen copies of the same script. Perhaps it would be better to refactor the repository layout to use a flat structure, so that any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the mvn-entrypoint.sh is copied across the various image directories as well, this is because Docker doesn't support COPY from outside the current directory (and children) into the image. I'm sure there could be some refactoring to take that into account, but I didn't want to make that part of this changset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaning up an existing situation is indeed something that should be deferred to a separate PR. I mentioned this here because this PR introduces a lot of duplication. Perhaps we could start by introducing a single directory with all the Windows images, and leave the Linux images untouched for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm definitely open to that method if that is desired. I'd also like to know if that would work for @carlossg to have that method. |
||
$log = "${env:MAVEN_CONFIG}/copy_reference_file.log" | ||
$ref = "C:/ProgramData/Maven/Reference" | ||
|
||
$repo = Join-Path $env:MAVEN_CONFIG 'repository' | ||
|
||
New-Item -Path $repo -ItemType Directory -Force | Out-Null | ||
Write-Output $null > $log | ||
if((Test-Path $repo) -and (Test-Path $log)) { | ||
$count = (Get-ChildItem $repo | Measure-Object).Count | ||
if($count -eq 0) { | ||
# destination is empty... | ||
Add-Content -Path $log -Value "--- Copying all files to ${env:MAVEN_CONFIG} at $(Get-Date)" | ||
Copy-Item -Path "$ref\*" -Destination $env:MAVEN_CONFIG -Force -Recurse | Add-Content -Path $log | ||
} else { | ||
# destination is non-empty, copy file-by-file | ||
Add-Content -Path $log -Value "--- Copying individual files to ${MAVEN_CONFIG} at $(Get-Date)" | ||
Get-ChildItem -Path $ref -File | ForEach-Object { | ||
Push-Location $ref | ||
$rel = Resolve-Path -Path $($_.FullName) -Relative | ||
Pop-Location | ||
if(!(Test-Path (Join-Path $env:MAVEN_CONFIG $rel)) -or (Test-Path $('{0}.override' -f $_.FullName))) { | ||
$dir = Join-Path $env:MAVEN_CONFIG $($rel.DirectoryName) | ||
if(!(Test-Path $dir)) { | ||
New-Item -Path $dir -ItemType Directory | Out-Null | ||
} | ||
Copy-Item -Path $_.FullName -Destination (Join-Path $env:MAVEN_CONFIG $rel) | Add-Content -Path $log | ||
} | ||
} | ||
} | ||
Add-Content -Path $log -Value "" | ||
} else { | ||
Write-Warning "Can not write to ${log}. Wrong volume permissions? Carrying on ..." | ||
} | ||
} | ||
|
||
Push-Location -StackName 'maven-entrypoint' | ||
Copy-ReferenceFiles | ||
Pop-Location -StackName 'maven-entrypoint' | ||
|
||
Remove-Item Env:\MAVEN_CONFIG | ||
|
||
Invoke-Expression "$args" | ||
exit $lastExitCode |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# escape=` | ||
ARG WINDOWS_DOCKER_TAG=ltsc2019 | ||
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_DOCKER_TAG | ||
|
||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
ARG zip=zulu11.33.15-ca-jdk11.0.4-win_x64.zip | ||
ARG uri=https://cdn.azul.com/zulu/bin/ | ||
ARG hash=ae13f3de1e7be9b3aa8d0afbfd5f2f9d6aba356276a39ccfcaf3511feb860f05 | ||
|
||
RUN Invoke-WebRequest -Uri $('{0}{1}' -f $env:uri,$env:zip) -OutFile C:/$env:zip ; ` | ||
if((Get-FileHash C:/$env:zip -Algorithm SHA256).Hash.ToLower() -ne $env:hash) { exit 1 } ; ` | ||
Expand-Archive -Path C:/$env:zip -Destination C:/ProgramData ; ` | ||
Remove-Item C:/${env:zip} | ||
|
||
ENV JAVA_HOME=C:/ProgramData/zulu11.33.15-ca-jdk11.0.4-win_x64 | ||
|
||
|
||
ARG MAVEN_VERSION=3.6.1 | ||
ARG USER_HOME_DIR="C:/Users/ContainerAdministrator" | ||
ARG SHA=51169366d7269ed316bad013d9cbfebe3a4ef1fda393ac4982d6dbc9af2d5cc359ee12838b8041cb998f236486e988b9c05372f4fdb29a96c1139f63c991e90e | ||
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries | ||
|
||
RUN Invoke-WebRequest -Uri ${env:BASE_URL}/apache-maven-${env:MAVEN_VERSION}-bin.zip -OutFile ${env:TEMP}/apache-maven.zip ; ` | ||
if((Get-FileHash -Algorithm SHA512 -Path ${env:TEMP}/apache-maven.zip).Hash.ToLower() -ne ${env:SHA}) { exit 1 } ; ` | ||
Expand-Archive -Path ${env:TEMP}/apache-maven.zip -Destination C:/ProgramData ; ` | ||
Move-Item C:/ProgramData/apache-maven-${env:MAVEN_VERSION} C:/ProgramData/Maven ; ` | ||
New-Item -ItemType Directory -Path C:/ProgramData/Maven/Reference | Out-Null ; ` | ||
Remove-Item ${env:TEMP}/apache-maven.zip | ||
|
||
ENV MAVEN_HOME C:/ProgramData/Maven | ||
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" | ||
|
||
# Workaround https://github.com/corretto/corretto-8-docker/pull/32 | ||
#ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto | ||
|
||
COPY mvn-entrypoint.ps1 C:/ProgramData/Maven/mvn-entrypoint.ps1 | ||
COPY settings-docker.xml C:/ProgramData/Maven/Reference/settings-docker.xml | ||
RUN $content = Get-Content "C:/ProgramData/Maven/Reference/settings-docker.xml" ; ` | ||
$content | ForEach-Object { $_ -replace '/usr/share/maven/ref/repository','C:\ProgramData\Maven\Reference\repository' } | ` | ||
Set-Content -Path "C:/ProgramData/Maven/Reference/settings-docker.xml" | ||
|
||
RUN setx /M PATH $('{0};{1}' -f $env:PATH,'C:\ProgramData\Maven\bin') | Out-Null | ||
|
||
ENTRYPOINT ["powershell.exe", "-f", "C:/ProgramData/Maven/mvn-entrypoint.ps1"] | ||
CMD ["mvn"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For lack of highlighting, see github-linguist/linguist#4566 (comment).