From c360d3c60e2a367f5adfcbbc570f8fce5b973772 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 26 Oct 2017 10:37:01 -0700 Subject: [PATCH 1/3] Merge nanoserver-insider to nanoserver as it has released --- docker/release/nanoserver-insider/Dockerfile | 55 --------------- docker/release/nanoserver/Dockerfile | 74 +++++++++----------- 2 files changed, 34 insertions(+), 95 deletions(-) delete mode 100755 docker/release/nanoserver-insider/Dockerfile mode change 100644 => 100755 docker/release/nanoserver/Dockerfile diff --git a/docker/release/nanoserver-insider/Dockerfile b/docker/release/nanoserver-insider/Dockerfile deleted file mode 100755 index 1146233b52a..00000000000 --- a/docker/release/nanoserver-insider/Dockerfile +++ /dev/null @@ -1,55 +0,0 @@ -# escape=` -# Args used by from statements must be defined here: -ARG NanoServerVersion=10.0.16257.1000 -ARG WindowsServerCoreVersion=10.0.16257.1000 -ARG WindowsServerCoreRepo=microsoft/windowsservercore-insider -ARG NanoServerRepo=microsoft/nanoserver-insider - -# 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}:$WindowsServerCoreVersion AS installer-env - -# Arguments for installing powershell, must be defined in the container they are used -ARG PS_VERSION=6.0.0-beta.9 - -ENV PS_DOWNLOAD_URL https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.zip - -SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -RUN Invoke-WebRequest $Env:PS_DOWNLOAD_URL -OutFile powershell.zip - -RUN Expand-Archive powershell.zip -DestinationPath \PowerShell - -# Install PowerShell into NanoServer -FROM ${NanoServerRepo}:$NanoServerVersion - -ARG VCS_REF="none" -ARG PS_VERSION=6.0.0-beta.9 -ARG IMAGE_NAME=microsoft/nanoserver-insider-powershell - -LABEL maintainer="PowerShell Team " ` - readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" ` - description="This Dockerfile will install the latest release of PS." ` - org.label-schema.usage="https://github.com/PowerShell/PowerShell/tree/master/docker#run-the-docker-image-you-built" ` - org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" ` - org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell" ` - org.label-schema.name="powershell" ` - org.label-schema.vcs-ref=${VCS_REF} ` - org.label-schema.vendor="PowerShell" ` - org.label-schema.version=${PS_VERSION} ` - org.label-schema.schema-version="1.0" ` - org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" ` - org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" ` - org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" ` - org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" - -# Copy Powershell Core from the installer containter -ENV ProgramFiles C:\Program Files -COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell"] - -# Persist %PSCORE% ENV variable for user convenience -ENV PSCORE="$ProgramFiles\PowerShell\pwsh.exe" - -# Set the path -RUN setx PATH "%PATH%;%ProgramFiles%\PowerShell" - -CMD ["pwsh.exe"] diff --git a/docker/release/nanoserver/Dockerfile b/docker/release/nanoserver/Dockerfile old mode 100644 new mode 100755 index 34f791428b2..fba2201deba --- a/docker/release/nanoserver/Dockerfile +++ b/docker/release/nanoserver/Dockerfile @@ -1,9 +1,30 @@ # escape=` -FROM microsoft/nanoserver:latest +# Args used by from statements must be defined here: +ARG NanoServerVersion=1709 +ARG WindowsServerCoreVersion=1709 +ARG WindowsServerCoreRepo=microsoft/windowsservercore +ARG NanoServerRepo=microsoft/nanoserver -ARG POWERSHELL_ZIP=https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.9/PowerShell-6.0.0-beta.9-win-x64.zip -ARG POWERSHELL_VERSION=6.0.0-beta.9 -ARG IMAGE_NAME=microsoft/powershell: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 ${WindowsServerCoreRepo}:$WindowsServerCoreVersion AS installer-env + +# Arguments for installing powershell, must be defined in the container they are used +ARG PS_VERSION=6.0.0-beta.9 + +ENV PS_DOWNLOAD_URL https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.zip + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +RUN Invoke-WebRequest $Env:PS_DOWNLOAD_URL -OutFile powershell.zip + +RUN Expand-Archive powershell.zip -DestinationPath \PowerShell + +# Install PowerShell into NanoServer +FROM ${NanoServerRepo}:$NanoServerVersion + +ARG VCS_REF="none" +ARG PS_VERSION=6.0.0-beta.9 +ARG IMAGE_NAME=microsoft/powershell LABEL maintainer="PowerShell Team " ` readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" ` @@ -12,50 +33,23 @@ LABEL maintainer="PowerShell Team " ` org.label-schema.url="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" ` org.label-schema.vcs-url="https://github.com/PowerShell/PowerShell" ` org.label-schema.name="powershell" ` + org.label-schema.vcs-ref=${VCS_REF} ` org.label-schema.vendor="PowerShell" ` - org.label-schema.version=${POWERSHELL_VERSION} ` + org.label-schema.version=${PS_VERSION} ` org.label-schema.schema-version="1.0" ` org.label-schema.docker.cmd="docker run ${IMAGE_NAME} pwsh -c '$psversiontable'" ` org.label-schema.docker.cmd.devel="docker run ${IMAGE_NAME}" ` org.label-schema.docker.cmd.test="docker run ${IMAGE_NAME} pwsh -c Invoke-Pester" ` org.label-schema.docker.cmd.help="docker run ${IMAGE_NAME} pwsh -c Get-Help" -# TODO: addd LABEL org.label-schema.vcs-ref=${VCS_REF} - -RUN setx /M PATH "%ProgramFiles%\PowerShell\latest;%PATH%" -# Setup PowerShell - Log-to > C:\Docker.log -SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"] -ADD $POWERSHELL_ZIP /powershell-win-x64.zip - -# Install PowerShell package and clean up -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-win-x64.zip ; ` - New-Item -Path $Env:ProgramFiles/PowerShell -ItemType Directory -Force | out-null ; ` - [System.IO.DirectoryInfo]$PsFolder=New-Item -Path $Env:ProgramFiles\PowerShell -ItemType Directory -Force ; ` - Add-Type -AssemblyName System.IO.Compression.ZipFile ; ` - [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile,$PsFolder) ; ` - if (Get-ChildItem -Path $PsFolder/pwsh.exe) { ` - Remove-Item -Path $ZipFile ; ` - New-Item -Type SymbolicLink -Path $PsFolder\ -Name latest -Value $PsFolder ` - } else { throw 'Installation failed! See c:\Dockerfile.log' } ; - -# Verify New pwsh.exe runs -SHELL ["C:\\Program Files\\PowerShell\\latest\\pwsh.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]!') ; ` - } ; +# Copy Powershell Core from the installer containter +ENV ProgramFiles C:\Program Files +COPY --from=installer-env ["\\PowerShell\\", "$ProgramFiles\\PowerShell"] # Persist %PSCORE% ENV variable for user convenience -ENV PSCORE='"C:\Program Files\PowerShell\latest\pwsh.exe"' +ENV PSCORE="$ProgramFiles\PowerShell\pwsh.exe" + +# Set the path +RUN setx PATH "%PATH%;%ProgramFiles%\PowerShell" CMD ["pwsh.exe"] From 84298b7643c550deb0a46f9351ec284e3391bbb1 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 26 Oct 2017 14:12:41 -0700 Subject: [PATCH 2/3] Add Arg Validation --- docker/release/nanoserver/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/release/nanoserver/Dockerfile b/docker/release/nanoserver/Dockerfile index fba2201deba..334cbaa8d5c 100755 --- a/docker/release/nanoserver/Dockerfile +++ b/docker/release/nanoserver/Dockerfile @@ -15,6 +15,8 @@ ARG PS_VERSION=6.0.0-beta.9 ENV PS_DOWNLOAD_URL https://github.com/PowerShell/PowerShell/releases/download/v$PS_VERSION/PowerShell-$PS_VERSION-win-x64.zip SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN 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)} RUN Invoke-WebRequest $Env:PS_DOWNLOAD_URL -OutFile powershell.zip RUN Expand-Archive powershell.zip -DestinationPath \PowerShell From 24a8a712b30742ef50155d059564a32ff7ebaec1 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 26 Oct 2017 15:13:18 -0700 Subject: [PATCH 3/3] update windows server core to use latest image --- docker/release/nanoserver/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/release/nanoserver/Dockerfile b/docker/release/nanoserver/Dockerfile index 334cbaa8d5c..3a7121c0617 100755 --- a/docker/release/nanoserver/Dockerfile +++ b/docker/release/nanoserver/Dockerfile @@ -1,7 +1,7 @@ # escape=` # Args used by from statements must be defined here: ARG NanoServerVersion=1709 -ARG WindowsServerCoreVersion=1709 +ARG WindowsServerCoreVersion=latest ARG WindowsServerCoreRepo=microsoft/windowsservercore ARG NanoServerRepo=microsoft/nanoserver