diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a9343f5ea..bda9ebac0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -29,7 +29,7 @@ updates: interval: "weekly" - package-ecosystem: "docker" - directory: "/release/preview/nanoserver2004/dependabot" + directory: "/release/preview/nanoserver20H2/dependabot" schedule: interval: "weekly" diff --git a/release/lts/nanoserver2004/dependabot/Dockerfile b/release/lts/nanoserver20H2/dependabot/Dockerfile similarity index 72% rename from release/lts/nanoserver2004/dependabot/Dockerfile rename to release/lts/nanoserver20H2/dependabot/Dockerfile index 863e481c7..2bb429d55 100644 --- a/release/lts/nanoserver2004/dependabot/Dockerfile +++ b/release/lts/nanoserver20H2/dependabot/Dockerfile @@ -3,4 +3,4 @@ # Dummy docker image to trigger dependabot PRs -FROM mcr.microsoft.com/windows/nanoserver:2004 +FROM mcr.microsoft.com/windows/nanoserver:20H2 diff --git a/release/lts/nanoserver20H2/docker/Dockerfile b/release/lts/nanoserver20H2/docker/Dockerfile new file mode 100644 index 000000000..777790924 --- /dev/null +++ b/release/lts/nanoserver20H2/docker/Dockerfile @@ -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"] diff --git a/release/lts/nanoserver20H2/meta.json b/release/lts/nanoserver20H2/meta.json new file mode 100644 index 000000000..7018ce5ca --- /dev/null +++ b/release/lts/nanoserver20H2/meta.json @@ -0,0 +1,20 @@ +{ + "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, + "IsBroken": true +} diff --git a/release/lts/windowsservercore2004/dependabot/Dockerfile b/release/lts/windowsservercore20H2/dependabot/Dockerfile similarity index 72% rename from release/lts/windowsservercore2004/dependabot/Dockerfile rename to release/lts/windowsservercore20H2/dependabot/Dockerfile index de415a7f7..b8c553b92 100644 --- a/release/lts/windowsservercore2004/dependabot/Dockerfile +++ b/release/lts/windowsservercore20H2/dependabot/Dockerfile @@ -3,4 +3,4 @@ # Dummy docker image to trigger dependabot PRs -FROM mcr.microsoft.com/windows/servercore:2004 +FROM mcr.microsoft.com/windows/servercore:20H2 diff --git a/release/lts/windowsservercore20H2/docker/Dockerfile b/release/lts/windowsservercore20H2/docker/Dockerfile new file mode 100644 index 000000000..15bf4270e --- /dev/null +++ b/release/lts/windowsservercore20H2/docker/Dockerfile @@ -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"] diff --git a/release/lts/windowsservercore20H2/meta.json b/release/lts/windowsservercore20H2/meta.json new file mode 100644 index 000000000..ba6d77343 --- /dev/null +++ b/release/lts/windowsservercore20H2/meta.json @@ -0,0 +1,20 @@ +{ + "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, + "IsBroken": true +} diff --git a/release/preview/nanoserver20H2/docker/Dockerfile b/release/preview/nanoserver20H2/docker/Dockerfile new file mode 100644 index 000000000..791221f67 --- /dev/null +++ b/release/preview/nanoserver20H2/docker/Dockerfile @@ -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"] diff --git a/release/preview/nanoserver20H2/meta.json b/release/preview/nanoserver20H2/meta.json new file mode 100644 index 000000000..6291b9a07 --- /dev/null +++ b/release/preview/nanoserver20H2/meta.json @@ -0,0 +1,21 @@ +{ + "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, + "IsBroken": true +} diff --git a/release/preview/windowsservercore20H2/docker/Dockerfile b/release/preview/windowsservercore20H2/docker/Dockerfile new file mode 100644 index 000000000..ffce740be --- /dev/null +++ b/release/preview/windowsservercore20H2/docker/Dockerfile @@ -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"] diff --git a/release/preview/windowsservercore20H2/meta.json b/release/preview/windowsservercore20H2/meta.json new file mode 100644 index 000000000..8e081cd19 --- /dev/null +++ b/release/preview/windowsservercore20H2/meta.json @@ -0,0 +1,21 @@ +{ + "IsLinux": false, + "PackageFormat": "PowerShell-${PS_VERSION}-win-x64.zip", + "osVersion": "Windows Server Core, version 20H2", + "shortTags": [ + { + "Tag": "20H2" + } + ], + "Base64EncodePackageUrl": true, + "tagTemplates": [ + "#psversion#-windowsservercore-#shorttag#", + "#psversion#-windowsservercore-20H2-#fulltag#", + "preview-windowsservercore-#shorttag#" + ], + "TestProperties": { + "size": 1 + }, + "UseAcr": true, + "IsBroken": true +} diff --git a/release/servicing/nanoserver1809/getLatestTag.ps1 b/release/servicing/nanoserver1809/getLatestTag.ps1 index b50d5ad3e..9eb49e8e1 100644 --- a/release/servicing/nanoserver1809/getLatestTag.ps1 +++ b/release/servicing/nanoserver1809/getLatestTag.ps1 @@ -17,5 +17,5 @@ $repoRoot = Join-Path -path (Join-Path -Path $parent -ChildPath '..') -ChildPath $modulePath = Join-Path -Path $repoRoot -ChildPath 'tools\getDockerTags' Import-Module $modulePath -Get-DockerTags -ShortTags $shortTags -Image "mcr.microsoft.com/windows/nanoserver" -FullTagFilter '\d{4}[-_]KB\d{7}([\-_]amd64)?$' -Mcr +Get-DockerTags -ShortTags $shortTags -Image "mcr.microsoft.com/windows/nanoserver" -FullTagFilter '(\d|H){4}[-_]KB\d{7}([\-_]amd64)?$' -Mcr diff --git a/release/servicing/windowsservercore/getLatestTag.ps1 b/release/servicing/windowsservercore/getLatestTag.ps1 index 4b74754eb..554e8c399 100644 --- a/release/servicing/windowsservercore/getLatestTag.ps1 +++ b/release/servicing/windowsservercore/getLatestTag.ps1 @@ -16,4 +16,4 @@ Import-Module $modulePath -Force # The versions of nanoserver we care about $shortTags = @('1809', '1903', '1909', '2004') -Get-DockerTags -ShortTags $shortTags -Image "mcr.microsoft.com/windows/servercore" -FullTagFilter '\d{4}[-_]KB\d{7}' -Mcr +Get-DockerTags -ShortTags $shortTags -Image "mcr.microsoft.com/windows/servercore" -FullTagFilter '(\d|H){4}[-_]KB\d{7}' -Mcr diff --git a/release/stable/nanoserver20H2/docker/Dockerfile b/release/stable/nanoserver20H2/docker/Dockerfile new file mode 100644 index 000000000..db84868ed --- /dev/null +++ b/release/stable/nanoserver20H2/docker/Dockerfile @@ -0,0 +1,90 @@ +# escape=` +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# 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 + +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"] diff --git a/release/stable/nanoserver20H2/meta.json b/release/stable/nanoserver20H2/meta.json new file mode 100644 index 000000000..2e712f41e --- /dev/null +++ b/release/stable/nanoserver20H2/meta.json @@ -0,0 +1,21 @@ +{ + "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#", + "nanoserver-#shorttag#" + ], + "Base64EncodePackageUrl": true, + "TestProperties": { + "size": 1 + }, + "UseAcr": true, + "IsBroken": true +} diff --git a/release/stable/windowsservercore20H2/docker/Dockerfile b/release/stable/windowsservercore20H2/docker/Dockerfile new file mode 100644 index 000000000..247cd3fef --- /dev/null +++ b/release/stable/windowsservercore20H2/docker/Dockerfile @@ -0,0 +1,70 @@ +# escape=` +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +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=6.2.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"] diff --git a/release/stable/windowsservercore20H2/meta.json b/release/stable/windowsservercore20H2/meta.json new file mode 100644 index 000000000..5a1f795bc --- /dev/null +++ b/release/stable/windowsservercore20H2/meta.json @@ -0,0 +1,21 @@ +{ + "IsLinux": false, + "PackageFormat": "PowerShell-${PS_VERSION}-win-x64.zip", + "osVersion": "Windows Server Core, version 20H2", + "shortTags": [ + { + "Tag": "20H2" + } + ], + "Base64EncodePackageUrl": true, + "tagTemplates": [ + "#psversion#-windowsservercore-#shorttag#", + "#psversion#-windowsservercore-20H2-#fulltag#", + "windowsservercore-#shorttag#" + ], + "TestProperties": { + "size": 1 + }, + "UseAcr": true, + "IsBroken": true +}