Updating to use Alpha-11 URLs\SHA
Updated URLs to point at Alpha 11 URLs, reduced number of intermediate stages, simplified logging code, and added a new %PSCORE% environment variable to make it easier to launch from other shells
This commit is contained in:
parent
ebc0dfe575
commit
f56806b614
|
@ -4,56 +4,48 @@ MAINTAINER brycem@microsoft.com
|
|||
LABEL Readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md"
|
||||
LABEL Description="This Dockerfile will install and build the latest reslease of PS on NanoServer."
|
||||
|
||||
ARG POWERSHELL_ZIP=https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.10/powershell-6.0.0-alpha.10-win10-x64.zip
|
||||
ARG POWERSHELL_SHA256=f394b51b6c8a865c0a1dd0c3645bb354e65339862ea95b60c9ff0226a307ded6
|
||||
ARG POWERSHELL_ZIP=https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.11/powershell-6.0.0-alpha.11-win10-x64.zip
|
||||
ARG POWERSHELL_SHA256=b41504ee24b27fb7bcbc6b495dc380d5a8a61bd0490c5920d79b90dca5dfcde5
|
||||
|
||||
# Preparing shell environment - Log-to > C:\Docker.log
|
||||
# Setup PowerShell - Log-to > C:\Docker.log
|
||||
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
|
||||
|
||||
RUN [ScriptBlock]$Prof= `
|
||||
{ `
|
||||
$ErrorActionPreference='Stop'; `
|
||||
$ConfirmPreference='None'; `
|
||||
$VerbosePreference='Continue'; `
|
||||
Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$PSVersionTable | Write-Output ; `
|
||||
$RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' ; `
|
||||
$BuildString = $(Get-ItemProperty -Path $RegPath).BuildLabEx ; `
|
||||
$EditionId = $(Get-ItemProperty -Path $RegPath).EditionId ; `
|
||||
$ProductName = $(Get-ItemProperty -Path $RegPath).ProductName ; `
|
||||
$InstallationType = $(Get-ItemProperty -Path $RegPath).InstallationType ; `
|
||||
Write-Output -InputObject $('FullBuildString: '+$BuildString) ; `
|
||||
Write-Output -InputObject $('OperatingSystem: '+$ProductName+' '+$EditionId+' '+$InstallationType) `
|
||||
} ; Write-Output $Prof | Out-File $(New-Item -Path $PROFILE -ItemType File -Force).FullName -Encoding utf8 -NoNewline ;
|
||||
|
||||
# Setup PowerShell
|
||||
ADD $POWERSHELL_ZIP /powershell-win10-x64.zip
|
||||
ENV POWERSHELL_SHA256=$POWERSHELL_SHA256
|
||||
|
||||
# Install PowerShell package and clean up
|
||||
RUN [System.IO.FileInfo]$ZipFile = Get-Item -Path ./powershell-win10-x64.zip ; `
|
||||
RUN $ErrorActionPreference='Stop'; `
|
||||
$ConfirmPreference='None'; `
|
||||
$VerbosePreference='Continue'; `
|
||||
Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$PSVersionTable | Write-Output ; `
|
||||
$VerInfo = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' ; `
|
||||
('FullBuildString: '+$VerInfo.BuildLabEx) | Write-Output ; `
|
||||
('OperatingSystem: '+$VerInfo.ProductName+' '+$VerInfo.EditionId+' '+$VerInfo.InstallationType) | Write-Output ; `
|
||||
[System.IO.FileInfo]$ZipFile = Get-Item -Path ./powershell-win10-x64.zip ; `
|
||||
[String]$ZipHash=(Get-FileHash -Path $ZipFile -Algorithm SHA256 | select -ExpandProperty Hash) ; `
|
||||
If ($ZipHash -notmatch $Env:POWERSHELL_SHA256) { `
|
||||
Throw [String]$('['+$ZipHash+'] does not match ['+$Env:POWERSHELL_SHA256+']!') `
|
||||
} ; `
|
||||
New-Item -Path $Env:ProgramFiles/PowerShell -ItemType Directory -Force | out-null ; `
|
||||
[System.IO.DirectoryInfo]$PsFolder=New-Item -Path $Env:ProgramFiles\PowerShell -ItemType Directory -Force ; `
|
||||
try { Add-Type -AssemblyName System.IO.Compression.FileSystem `
|
||||
} catch {Add-Type -AssemblyName System.IO.Compression.ZipFile `
|
||||
} finally { [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile,$PsFolder) } ; `
|
||||
Add-Type -AssemblyName System.IO.Compression.ZipFile ; `
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile,$PsFolder) ; `
|
||||
if (Get-ChildItem -Path $PsFolder/powershell.exe) { `
|
||||
Remove-Item -Path $PROFILE ; Remove-Item -Path $ZipFile ; `
|
||||
$psexe=Get-Item -Path $Env:ProgramFiles\PowerShell\powershell.exe ; `
|
||||
$psexe; `
|
||||
Remove-Item -Path $ZipFile ; `
|
||||
New-Item -Type SymbolicLink -Path $PsFolder\ -Name Core -Value $PsFolder `
|
||||
} else { throw 'Installation failed! See c:\Dockerfile.log' } ;
|
||||
|
||||
SHELL ["C:\\Program Files\\PowerShell\\Core\\PowerShell.exe", "-command"]
|
||||
# Cleanup %POWERSHELL_SHA256%
|
||||
ENV POWERSHELL_SHA256=
|
||||
|
||||
# Verify New Powershell.exe runs
|
||||
RUN $ErrorActionPreference='Stop'; `
|
||||
If ($PSVersionTable.PSEdition -Match 'Core') { `
|
||||
Write-Output $PSVersionTable `
|
||||
} else { `
|
||||
Throw [String]$('['+$PSVersionTable.PSEdition+'] is not [Core]!') `
|
||||
SHELL ["C:\\Program Files\\PowerShell\\Core\\PowerShell.exe", "-command"]
|
||||
RUN Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$ErrorActionPreference='Stop'; `
|
||||
Write-Output $PSVersionTable ; `
|
||||
If (-not($PSVersionTable.PSEdition -Match 'Core')) { `
|
||||
Throw [String]$('['+$PSVersionTable.PSEdition+'] is not [Core]!') ; `
|
||||
} ;
|
||||
|
||||
# Persist %PSCORE% ENV variable for user convenience
|
||||
ENV PSCORE='"C:\Program Files\PowerShell\Core\PowerShell.exe"'
|
||||
|
|
|
@ -4,34 +4,24 @@ MAINTAINER brycem@microsoft.com
|
|||
LABEL Readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md"
|
||||
LABEL Description="This Dockerfile will install and build the latest reslease of PS on WindowsServerCore."
|
||||
|
||||
ARG POWERSHELL_MSI=https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.10/PowerShell_6.0.0.10-alpha.10-win10-x64.msi
|
||||
ARG POWERSHELL_SHA256=f669482aeab8de04f4da5ac03a36ce6b4e9f6569401b4cc842a4cd59196756a0
|
||||
ARG POWERSHELL_MSI=https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.11/PowerShell_6.0.0.11-alpha.11-win10-x64.msi
|
||||
ARG POWERSHELL_SHA256=ad15b3a3d7eccc2c604c51b5b2262e486ee05b55c532b9bf230a8f216db9f2b3
|
||||
|
||||
# Preparing shell environment - Log-to > C:\Docker.log
|
||||
# Setup PowerShell - Log-to > C:\Docker.log
|
||||
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
|
||||
|
||||
RUN [ScriptBlock]$Prof= `
|
||||
{ `
|
||||
$ErrorActionPreference='Stop'; `
|
||||
$ConfirmPreference='None'; `
|
||||
$VerbosePreference='Continue'; `
|
||||
Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$PSVersionTable | Write-Output ; `
|
||||
$RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' ; `
|
||||
$BuildString = $(Get-ItemProperty -Path $RegPath).BuildLabEx ; `
|
||||
$EditionId = $(Get-ItemProperty -Path $RegPath).EditionId ; `
|
||||
$ProductName = $(Get-ItemProperty -Path $RegPath).ProductName ; `
|
||||
$InstallationType = $(Get-ItemProperty -Path $RegPath).InstallationType ; `
|
||||
Write-Output -InputObject $('FullBuildString: '+$BuildString) ; `
|
||||
Write-Output -InputObject $('OperatingSystem: '+$ProductName+' '+$EditionId+' '+$InstallationType) `
|
||||
} ; Write-Output $Prof | Out-File $(New-Item -Path $PROFILE -ItemType File -Force).FullName -Encoding utf8 -NoNewline ;
|
||||
|
||||
# Setup PowerShell
|
||||
ADD $POWERSHELL_MSI /PowerShell-win10-x64.msi
|
||||
ENV POWERSHELL_SHA256=$POWERSHELL_SHA256
|
||||
|
||||
# Install PowerShell package and clean up
|
||||
RUN [System.IO.FileInfo]$MsiFile = Get-Item -Path ./PowerShell-win10-x64.msi ; `
|
||||
RUN $ErrorActionPreference='Stop'; `
|
||||
$ConfirmPreference='None'; `
|
||||
$VerbosePreference='Continue'; `
|
||||
Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$PSVersionTable | Write-Output ; `
|
||||
$VerInfo = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' ; `
|
||||
('FullBuildString: '+$VerInfo.BuildLabEx) | Write-Output ; `
|
||||
('OperatingSystem: '+$VerInfo.ProductName+' '+$VerInfo.EditionId+' '+$VerInfo.InstallationType) | Write-Output ; `
|
||||
[System.IO.FileInfo]$MsiFile = Get-Item -Path ./PowerShell-win10-x64.msi ; `
|
||||
[String]$MsiHash=(Get-FileHash -Path $MSiFile -Algorithm SHA256 | select -ExpandProperty Hash) ; `
|
||||
If ($MsiHash -notmatch $Env:POWERSHELL_SHA256) { `
|
||||
Throw [String]$('['+$MsiHash+'] does not match ['+$Env:POWERSHELL_SHA256+']!') `
|
||||
|
@ -40,18 +30,22 @@ RUN [System.IO.FileInfo]$MsiFile = Get-Item -Path ./PowerShell-win10-x64.msi ; `
|
|||
'-log c:\PowerShell-win10-x64.msi.log','-norestart' -wait ; `
|
||||
$log=get-content -Path C:\PowerShell-win10-x64.msi.log -Last 10 ; `
|
||||
if ($log -match 'Installation success or error status: 0') { `
|
||||
Remove-Item -Path $PROFILE ; Remove-Item -Path $MsiFile ; `
|
||||
Remove-Item -Path $MsiFile ; `
|
||||
$psexe=Get-Item -Path $Env:ProgramFiles\PowerShell\*\powershell.exe ; `
|
||||
$psexe; `
|
||||
New-Item -Type SymbolicLink -Path $Env:ProgramFiles\PowerShell\ -Name Core -Value $psexe.DirectoryName `
|
||||
} else { throw 'Installation failed! See c:\PowerShell-win10-x64.msi.log' } ;
|
||||
|
||||
SHELL ["C:\\Program Files\\PowerShell\\Core\\PowerShell.exe", "-command"]
|
||||
# Cleanup %POWERSHELL_SHA256%
|
||||
ENV POWERSHELL_SHA256=
|
||||
|
||||
# Verify new Core Powershell.exe runs
|
||||
RUN $ErrorActionPreference='Stop'; `
|
||||
If ($PSVersionTable.PSEdition -Match 'Core') { `
|
||||
Write-Output $PSVersionTable `
|
||||
} else { `
|
||||
Throw [String]$('['+$PSVersionTable.PSEdition+'] is not [Core]!') `
|
||||
# Verify New Powershell.exe runs
|
||||
SHELL ["C:\\Program Files\\PowerShell\\Core\\PowerShell.exe", "-command"]
|
||||
RUN Start-Transcript -path C:\Dockerfile.log -append -IncludeInvocationHeader ; `
|
||||
$ErrorActionPreference='Stop'; `
|
||||
Write-Output $PSVersionTable ; `
|
||||
If (-not($PSVersionTable.PSEdition -Match 'Core')) { `
|
||||
Throw [String]$('['+$PSVersionTable.PSEdition+'] is not [Core]!') ; `
|
||||
} ;
|
||||
|
||||
# Persist %PSCORE% ENV variable for user convenience
|
||||
ENV PSCORE='"C:\Program Files\PowerShell\Core\PowerShell.exe"'
|
||||
|
|
Loading…
Reference in a new issue