Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions docker/release/nanoserver-insider/Dockerfile

This file was deleted.

76 changes: 36 additions & 40 deletions docker/release/nanoserver/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
# escape=`
FROM microsoft/nanoserver:latest
# Args used by from statements must be defined here:
ARG NanoServerVersion=1709
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the values for these first arguments changed

ARG WindowsServerCoreVersion=latest
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 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)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was added

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 <powershellteam@hotmail.com>" `
readme.md="https://github.com/PowerShell/PowerShell/blob/master/docker/README.md" `
Expand All @@ -12,50 +35,23 @@ LABEL maintainer="PowerShell Team <powershellteam@hotmail.com>" `
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 link
Member

@mirichmo mirichmo Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are quotes needed here around c:\Program Files? A bigger question that I don't quite understand: Why are you defining it here and not using $env:ProgramFiles or %ProgramFiles%?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a tested an working file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only two changes to the file. I added comments for the two changes. The file which was deleted, otherwise replaced the older file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about my second question? I added it a little later via edit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker itself cannot use the container environment variables. This is used in docker commands.

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"]