Update docker file for windows build (#5459)

reducing the base image size should make the build a little faster
Also, remove the duplicate upload of a file
This commit is contained in:
Travis Plunk 2017-11-28 15:36:25 -08:00 committed by GitHub
parent 910c5a4780
commit 9bedef0c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 188 additions and 12 deletions

View File

@ -1,11 +1,28 @@
# escape=`
#0.3.6 (no powershell 6)
FROM travisez13/microsoft.windowsservercore.build-tools:latest
FROM microsoft/windowsservercore
LABEL maintainer='PowerShell Team <powershellteam@hotmail.com>'
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."
SHELL ["powershell"]
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
# Install Git, and NuGet
# Git installs to C:\Program Files\Git
# nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe
COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
Install-ChocolateyPackage -PackageName git -Executable git.exe; `
Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup
# Install WIX
ADD https://github.com/wixtoolset/wix3/releases/download/wix311rtm/wix311-binaries.zip /wix.zip
COPY wix.psm1 containerFiles/wix.psm1
RUN Import-Module ./containerFiles/wix.psm1; `
Install-WixZip -zipPath \wix.Zip
COPY PowerShellPackage.ps1 /
ENTRYPOINT ["powershell"]
ADD https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1 \install-powershell.ps1
RUN new-item -Path 'C:\Program Files\PowerShell\latest' -ItemType Directory; `
\install-powershell.ps1 -AddToPath -Destination 'C:\Program Files\PowerShell\latest'
ENTRYPOINT ["C:\\Program Files\\PowerShell\\latest\\pwsh.exe", "-command"]

View File

@ -0,0 +1,113 @@
function Install-ChocolateyPackage
{
param(
[Parameter(Mandatory=$true)]
[string]
$PackageName,
[Parameter(Mandatory=$false)]
[string]
$Executable,
[string[]]
$ArgumentList,
[switch]
$Cleanup,
[int]
$ExecutionTimeout = 2700,
[string]
$Version
)
if(-not(Get-Command -name Choco -ErrorAction SilentlyContinue))
{
Write-Verbose "Installing Chocolatey provider..." -Verbose
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
}
Write-Verbose "Installing $PackageName..." -Verbose
$extraCommand = @()
if($Version)
{
$extraCommand += '--version', $version
}
choco install -y $PackageName --no-progress --execution-timeout=$ExecutionTimeout $ArgumentList $extraCommands
if($executable)
{
Write-Verbose "Verifing $Executable is in path..." -Verbose
$exeSource = $null
$exeSource = Get-ChildItem -path "$env:ProgramFiles\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
if(!$exeSource)
{
Write-Verbose "Falling back to x86 program files..." -Verbose
$exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
# Don't search the chocolatey program data until more official locations have been searched
if(!$exeSource)
{
Write-Verbose "Falling back to chocolatey..." -Verbose
$exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
# all obvious locations are exhausted, use brute force and search from the root of the filesystem
if(!$exeSource)
{
Write-Verbose "Falling back to the root of the drive..." -Verbose
$exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
if(!$exeSource)
{
throw "$Executable not found"
}
$exePath = Split-Path -Path $exeSource
Append-Path -path $exePath
}
if($Cleanup.IsPresent)
{
Remove-Folder -Folder "$env:temp\chocolatey"
}
}
function Append-Path
{
param
(
$path
)
$machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine)
$machinePath = $machinePathString -split ';'
if($machinePath -inotcontains $path)
{
$newPath = "$machinePathString;$path"
Write-Verbose "Adding $path to path..." -Verbose
[System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine)
Write-Verbose "Added $path to path." -Verbose
}
else
{
Write-Verbose "$path already in path." -Verbose
}
}
function Remove-Folder
{
param(
[string]
$Folder
)
Write-Verbose "Cleaning up $Folder..." -Verbose
$filter = Join-Path -Path $Folder -ChildPath *
[int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue
Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose
}

View File

@ -0,0 +1,22 @@
Import-Module "$PSScriptRoot\dockerInstall.psm1"
# Install using Wix Zip because the MSI requires an older version of dotnet
# which was large and unstable in docker
function Install-WixZip
{
param($zipPath)
$targetRoot = "${env:ProgramFiles(x86)}\WiX Toolset xcopy"
$binPath = Join-Path -Path $targetRoot -ChildPath 'bin'
Write-Verbose "Expanding $zipPath to $binPath ..." -Verbose
Expand-Archive -Path $zipPath -DestinationPath $binPath -Force
$docExpandPath = Join-Path -Path $binPath -ChildPath 'doc'
$sdkExpandPath = Join-Path -Path $binPath -ChildPath 'sdk'
$docTargetPath = Join-Path -Path $targetRoot -ChildPath 'doc'
$sdkTargetPath = Join-Path -Path $targetRoot -ChildPath 'sdk'
Write-Verbose "Fixing folder structure ..." -Verbose
Move-Item -Path $docExpandPath -Destination $docTargetPath
Move-Item -Path $sdkExpandPath -Destination $sdkTargetPath
Append-Path -path $binPath
Write-Verbose "Done installing WIX!"
}

View File

@ -9,7 +9,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "release"
},
@ -22,7 +26,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "release"
},
@ -35,7 +43,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "symbols",
"BinariesExpected": 1,
@ -50,7 +62,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "symbols",
"BinariesExpected": 1,
@ -65,7 +81,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "signed",
"BinariesExpected": 2
@ -79,7 +99,11 @@
"3968m"
],
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
"AdditionalContextFiles" :[
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\wix.psm1",
".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\dockerInstall.psm1"
],
"DockerImageName": "ps-winsrvcore",
"BinaryBucket": "signed",
"BinariesExpected": 2

View File

@ -42,11 +42,11 @@ function New-FileElement
if(Test-Path -Path $file)
{
$name = Split-Path -Leaf -Path $File
$null = $fileElement = $XmlDoc.CreateElement("file")
$fileElement = $XmlDoc.CreateElement("file")
New-Attribute -Name 'src' -value $file -Element $fileElement
New-Attribute -Name 'signType' -value $SignType -Element $fileElement
New-Attribute -Name 'dest' -value "__OUTPATHROOT__\$name" -Element $fileElement
$null = $job.AppendChild($fileElement)
$null = $job.AppendChild($fileElement)
}
else
{
@ -69,4 +69,4 @@ foreach($file in $AuthenticodeFiles)
$signingXml.Save($path)
$updateScriptPath = Join-Path -Path $PSScriptRoot -ChildPath 'updateSigning.ps1'
& $updateScriptPath -SigningXmlPath $path
& $updateScriptPath -SigningXmlPath $path