-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vincent Boulineau <[email protected]>
- Loading branch information
1 parent
d08ed57
commit 8f1ed11
Showing
17 changed files
with
593 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# escape=` | ||
# Args used by from statements must be defined here: | ||
ARG InstallerVersion=nanoserver | ||
ARG InstallerRepo=mcr.microsoft.com/powershell | ||
ARG NanoServerRepo=mcr.microsoft.com/windows/nanoserver | ||
|
||
# Use server core as an installer container to extract PowerShell, | ||
# As this is a multi-stage build, this stage will eventually be thrown away | ||
FROM ${InstallerRepo}:$InstallerVersion AS installer-env | ||
|
||
# Arguments for installing PowerShell, must be defined in the container they are used | ||
ARG PS_VERSION=7.0.0-rc.1 | ||
|
||
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.zip | ||
|
||
# disable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="1" | ||
|
||
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
ARG PS_PACKAGE_URL_BASE64 | ||
|
||
RUN Write-host "Verifying valid Version..."; ` | ||
if (!($env:PS_VERSION -match '^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$' )) { ` | ||
throw ('PS_Version ({0}) must match the regex "^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$"' -f $env:PS_VERSION) ` | ||
} ` | ||
$ProgressPreference = 'SilentlyContinue'; ` | ||
if($env:PS_PACKAGE_URL_BASE64){ ` | ||
Write-host "decoding: $env:PS_PACKAGE_URL_BASE64" ;` | ||
$url = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:PS_PACKAGE_URL_BASE64)) ` | ||
} else { ` | ||
Write-host "using url: $env:PS_PACKAGE_URL" ;` | ||
$url = $env:PS_PACKAGE_URL ` | ||
} ` | ||
Write-host "downloading: $url"; ` | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` | ||
New-Item -ItemType Directory /installer > $null ; ` | ||
Invoke-WebRequest -Uri $url -outfile /installer/powershell.zip -verbose; ` | ||
Expand-Archive /installer/powershell.zip -DestinationPath \PowerShell | ||
|
||
# Install PowerShell into NanoServer | ||
FROM ${NanoServerRepo}:20H2 | ||
|
||
ARG IMAGE_NAME=mcr.microsoft.com/powershell | ||
|
||
# Copy PowerShell Core from the installer container | ||
ENV ProgramFiles="C:\Program Files" ` | ||
# set a fixed location for the Module analysis cache | ||
PSModuleAnalysisCachePath="C:\Users\Public\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" ` | ||
# Persist %PSCORE% ENV variable for user convenience | ||
PSCORE="$ProgramFiles\PowerShell\pwsh.exe" ` | ||
# Set the default windows path so we can use it | ||
WindowsPATH="C:\Windows\system32;C:\Windows" ` | ||
POWERSHELL_DISTRIBUTION_CHANNEL="PSDocker-NanoServer-20H2" | ||
|
||
### Begin workaround ### | ||
# Note that changing user on nanoserver is not recommended | ||
# See, https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-base-images#base-image-differences | ||
# But we are working around a bug introduced in the nanoserver image introduced in 1809 | ||
# Without this, PowerShell Direct will fail | ||
# this command sholud be like this: https://github.com/PowerShell/PowerShell-Docker/blob/f81009c42c96af46aef81eb1515efae0ef29ad5f/release/preview/nanoserver/docker/Dockerfile#L76 | ||
USER ContainerAdministrator | ||
|
||
# This is basically the correct code except for the /M | ||
RUN setx PATH "%PATH%;%ProgramFiles%\PowerShell;" /M | ||
|
||
USER ContainerUser | ||
### End workaround ### | ||
|
||
COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell"] | ||
|
||
# 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 ; ` | ||
}" | ||
|
||
# re-enable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="0" | ||
|
||
CMD ["pwsh.exe"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"IsLinux": false, | ||
"PackageFormat": "PowerShell-${PS_VERSION}-win-x64.zip", | ||
"osVersion": "Nano Server, version 20H2", | ||
"shortTags": [ | ||
{ | ||
"Tag": "20H2" | ||
} | ||
], | ||
"tagTemplates": [ | ||
"lts-nanoserver-#shorttag#", | ||
"lts-nanoserver-20H2-#fulltag#" | ||
], | ||
"Base64EncodePackageUrl": true, | ||
"TestProperties": { | ||
"size": 1 | ||
}, | ||
"UseAcr": true | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# escape=` | ||
ARG WindowsServerCoreRepo=mcr.microsoft.com/windows/servercore | ||
|
||
# Use server core as an installer container to extract PowerShell, | ||
# As this is a multi-stage build, this stage will eventually be thrown away | ||
FROM ${WindowsServerCoreRepo}:20H2 AS installer-env | ||
|
||
ARG PS_VERSION=7.0.0 | ||
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/PowerShell-${PS_VERSION}-win-x64.zip | ||
|
||
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] | ||
|
||
ARG PS_PACKAGE_URL_BASE64 | ||
|
||
RUN Write-host "Verifying valid Version..."; ` | ||
if (!($env:PS_VERSION -match '^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$' )) { ` | ||
throw ('PS_Version ({0}) must match the regex "^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$"' -f $env:PS_VERSION) ` | ||
} ` | ||
$ProgressPreference = 'SilentlyContinue'; ` | ||
if($env:PS_PACKAGE_URL_BASE64){ ` | ||
Write-host "decoding: $env:PS_PACKAGE_URL_BASE64" ;` | ||
$url = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:PS_PACKAGE_URL_BASE64)) ` | ||
} else { ` | ||
Write-host "using url: $env:PS_PACKAGE_URL" ;` | ||
$url = $env:PS_PACKAGE_URL ` | ||
} ` | ||
Write-host "downloading: $url"; ` | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` | ||
Invoke-WebRequest -Uri $url -outfile /powershell.zip -verbose; ` | ||
Expand-Archive powershell.zip -DestinationPath \PowerShell | ||
|
||
# Install PowerShell into WindowsServerCore | ||
FROM ${WindowsServerCoreRepo}:20H2 | ||
|
||
# Copy PowerShell Core from the installer container | ||
ENV ProgramFiles="C:\Program Files" ` | ||
# set a fixed location for the Module analysis cache | ||
PSModuleAnalysisCachePath="C:\Users\Public\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" ` | ||
# Persist %PSCORE% ENV variable for user convenience | ||
PSCORE="$ProgramFiles\PowerShell\pwsh.exe" ` | ||
POWERSHELL_DISTRIBUTION_CHANNEL="PSDocker-WindowsServerCore-20H2" ` | ||
POWERSHELL_TELEMETRY_OPTOUT="1" | ||
|
||
# Copy PowerShell Core from the installer container | ||
COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell\\latest"] | ||
|
||
# Set the path | ||
RUN setx /M PATH "%ProgramFiles%\PowerShell\latest;%PATH%;" | ||
|
||
# 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 ; ` | ||
}" | ||
|
||
# re-enable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="0" | ||
|
||
CMD ["pwsh.exe"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"IsLinux": false, | ||
"PackageFormat": "PowerShell-${PS_VERSION}-win-x64.zip", | ||
"osVersion": "Windows Server Core, version 20H2", | ||
"shortTags": [ | ||
{ | ||
"Tag": "20H2" | ||
} | ||
], | ||
"Base64EncodePackageUrl": true, | ||
"tagTemplates": [ | ||
"lts-windowsservercore-#shorttag#", | ||
"lts-windowsservercore-20H2-#fulltag#" | ||
], | ||
"TestProperties": { | ||
"size": 1 | ||
}, | ||
"UseAcr": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# escape=` | ||
# Args used by from statements must be defined here: | ||
ARG InstallerVersion=nanoserver | ||
ARG InstallerRepo=mcr.microsoft.com/powershell | ||
ARG NanoServerRepo=mcr.microsoft.com/windows/nanoserver | ||
|
||
# Use server core as an installer container to extract PowerShell, | ||
# As this is a multi-stage build, this stage will eventually be thrown away | ||
FROM ${InstallerRepo}:$InstallerVersion AS installer-env | ||
|
||
# Arguments for installing PowerShell, must be defined in the container they are used | ||
ARG PS_VERSION=7.0.0-rc.1 | ||
|
||
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.zip | ||
|
||
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] | ||
|
||
# disable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="1" | ||
|
||
ARG PS_PACKAGE_URL_BASE64 | ||
|
||
RUN Write-host "Verifying valid Version..."; ` | ||
if (!($env:PS_VERSION -match '^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$' )) { ` | ||
throw ('PS_Version ({0}) must match the regex "^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$"' -f $env:PS_VERSION) ` | ||
} ` | ||
$ProgressPreference = 'SilentlyContinue'; ` | ||
if($env:PS_PACKAGE_URL_BASE64){ ` | ||
Write-host "decoding: $env:PS_PACKAGE_URL_BASE64" ;` | ||
$url = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:PS_PACKAGE_URL_BASE64)) ` | ||
} else { ` | ||
Write-host "using url: $env:PS_PACKAGE_URL" ;` | ||
$url = $env:PS_PACKAGE_URL ` | ||
} ` | ||
Write-host "downloading: $url"; ` | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` | ||
New-Item -ItemType Directory /installer > $null ; ` | ||
Invoke-WebRequest -Uri $url -outfile /installer/powershell.zip -verbose; ` | ||
Expand-Archive /installer/powershell.zip -DestinationPath \PowerShell | ||
|
||
# Install PowerShell into NanoServer | ||
FROM ${NanoServerRepo}:20H2 | ||
|
||
# Copy PowerShell Core from the installer container | ||
ENV ProgramFiles="C:\Program Files" ` | ||
# set a fixed location for the Module analysis cache | ||
PSModuleAnalysisCachePath="C:\Users\Public\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" ` | ||
# Persist %PSCORE% ENV variable for user convenience | ||
PSCORE="$ProgramFiles\PowerShell\pwsh.exe" ` | ||
# Set the default windows path so we can use it | ||
WindowsPATH="C:\Windows\system32;C:\Windows" ` | ||
POWERSHELL_DISTRIBUTION_CHANNEL="PSDocker-NanoServer-20H2" | ||
|
||
### Begin workaround ### | ||
# Note that changing user on nanoserver is not recommended | ||
# See, https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-base-images#base-image-differences | ||
# But we are working around a bug introduced in the nanoserver image introduced in 1809 | ||
# Without this, PowerShell Direct will fail | ||
# this command sholud be like this: https://github.com/PowerShell/PowerShell-Docker/blob/f81009c42c96af46aef81eb1515efae0ef29ad5f/release/preview/nanoserver/docker/Dockerfile#L76 | ||
USER ContainerAdministrator | ||
|
||
# This is basically the correct code except for the /M | ||
RUN setx PATH "%PATH%;%ProgramFiles%\PowerShell;" /M | ||
|
||
USER ContainerUser | ||
### End workaround ### | ||
|
||
COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell"] | ||
|
||
# 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 ; ` | ||
}" | ||
|
||
# re-enable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="0" | ||
|
||
CMD ["pwsh.exe"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"IsLinux": false, | ||
"PackageFormat": "PowerShell-${PS_VERSION}-win-x64.zip", | ||
"osVersion": "Nano Server, version 20H2", | ||
"shortTags": [ | ||
{ | ||
"Tag": "20H2" | ||
} | ||
], | ||
"tagTemplates": [ | ||
"#psversion#-nanoserver-#shorttag#", | ||
"#psversion#-nanoserver-20H2-#fulltag#", | ||
"preview-nanoserver-#shorttag#" | ||
], | ||
"Base64EncodePackageUrl": true, | ||
"TestProperties": { | ||
"size": 1 | ||
}, | ||
"UseAcr": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# escape=` | ||
ARG WindowsServerCoreRepo=mcr.microsoft.com/windows/servercore | ||
|
||
# Use server core as an installer container to extract PowerShell, | ||
# As this is a multi-stage build, this stage will eventually be thrown away | ||
FROM ${WindowsServerCoreRepo}:20H2 AS installer-env | ||
|
||
ARG PS_VERSION=7.0.0-preview.1 | ||
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/PowerShell-${PS_VERSION}-win-x64.zip | ||
|
||
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] | ||
|
||
ARG PS_PACKAGE_URL_BASE64 | ||
|
||
RUN Write-host "Verifying valid Version..."; ` | ||
if (!($env:PS_VERSION -match '^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$' )) { ` | ||
throw ('PS_Version ({0}) must match the regex "^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$"' -f $env:PS_VERSION) ` | ||
} ` | ||
$ProgressPreference = 'SilentlyContinue'; ` | ||
if($env:PS_PACKAGE_URL_BASE64){ ` | ||
Write-host "decoding: $env:PS_PACKAGE_URL_BASE64" ;` | ||
$url = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($env:PS_PACKAGE_URL_BASE64)) ` | ||
} else { ` | ||
Write-host "using url: $env:PS_PACKAGE_URL" ;` | ||
$url = $env:PS_PACKAGE_URL ` | ||
} ` | ||
Write-host "downloading: $url"; ` | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; ` | ||
Invoke-WebRequest -Uri $url -outfile /powershell.zip -verbose; ` | ||
Expand-Archive powershell.zip -DestinationPath \PowerShell | ||
|
||
# Install PowerShell into WindowsServerCore | ||
FROM ${WindowsServerCoreRepo}:20H2 | ||
|
||
# Copy PowerShell Core from the installer container | ||
ENV ProgramFiles="C:\Program Files" ` | ||
# set a fixed location for the Module analysis cache | ||
PSModuleAnalysisCachePath="C:\Users\Public\AppData\Local\Microsoft\Windows\PowerShell\docker\ModuleAnalysisCache" ` | ||
# Persist %PSCORE% ENV variable for user convenience | ||
PSCORE="$ProgramFiles\PowerShell\pwsh.exe" ` | ||
POWERSHELL_DISTRIBUTION_CHANNEL="PSDocker-WindowsServerCore-20H2" ` | ||
POWERSHELL_TELEMETRY_OPTOUT="1" | ||
|
||
# Copy PowerShell Core from the installer container | ||
COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell\\latest"] | ||
|
||
# Set the path | ||
RUN setx /M PATH "%ProgramFiles%\PowerShell\latest;%PATH%;" | ||
|
||
# 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 ; ` | ||
}" | ||
|
||
# re-enable telemetry | ||
ENV POWERSHELL_TELEMETRY_OPTOUT="0" | ||
|
||
CMD ["pwsh.exe"] |
Oops, something went wrong.