Skip to content

Commit 7052583

Browse files
committed
First set of files for vsts build
1 parent 0e7cca6 commit 7052583

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

tools/releaseBuild/Image/DockerFile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# escape=`
2+
#0.3.6 (no powershell 6)
3+
# FROM microsoft/windowsservercore
4+
FROM microsoft/dotnet-framework:4.7.1
5+
LABEL maintainer='PowerShell Team <[email protected]>'
6+
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."
7+
8+
SHELL ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
9+
# Install Git, and platyPS
10+
# Git installs to C:\Program Files\Git
11+
# nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe
12+
COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1
13+
RUN Import-Module PackageManagement; `
14+
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; `
15+
Import-Module ./containerFiles/dockerInstall.psm1; `
16+
Install-ChocolateyPackage -PackageName git -Executable git.exe; `
17+
Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup; `
18+
Install-Module -Force -Name platyPS; `
19+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1 -outfile C:/dotnet-install.ps1; `
20+
C:/dotnet-install.ps1 -Channel Release -Version 2.1.4; `
21+
Add-Path C:/Users/ContainerAdministrator/AppData/Local/Microsoft/dotnet;
22+
23+
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
24+
git clone https://Github.com/PowerShell/PSScriptAnalyzer; `
25+
Install-ChocolateyPackage -PackageName dotnet4.5;
26+
27+
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
28+
Install-ChocolateyPackage -PackageName netfx-4.5.1-devpack;
29+
30+
ENTRYPOINT ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
31+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
function Install-ChocolateyPackage
2+
{
3+
param(
4+
[Parameter(Mandatory=$true)]
5+
[string]
6+
$PackageName,
7+
8+
[Parameter(Mandatory=$false)]
9+
[string]
10+
$Executable,
11+
12+
[string[]]
13+
$ArgumentList,
14+
15+
[switch]
16+
$Cleanup,
17+
18+
[int]
19+
$ExecutionTimeout = 2700,
20+
21+
[string]
22+
$Version
23+
)
24+
25+
if(-not(Get-Command -name Choco -ErrorAction SilentlyContinue))
26+
{
27+
Write-Verbose "Installing Chocolatey provider..." -Verbose
28+
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
29+
}
30+
31+
Write-Verbose "Installing $PackageName..." -Verbose
32+
$extraCommand = @()
33+
if($Version)
34+
{
35+
$extraCommand += '--version', $version
36+
}
37+
choco install -y $PackageName --no-progress --execution-timeout=$ExecutionTimeout $ArgumentList $extraCommands
38+
39+
if($executable)
40+
{
41+
Write-Verbose "Verifing $Executable is in path..." -Verbose
42+
$exeSource = $null
43+
$exeSource = Get-ChildItem -path "$env:ProgramFiles\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
44+
if(!$exeSource)
45+
{
46+
Write-Verbose "Falling back to x86 program files..." -Verbose
47+
$exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
48+
}
49+
50+
# Don't search the chocolatey program data until more official locations have been searched
51+
if(!$exeSource)
52+
{
53+
Write-Verbose "Falling back to chocolatey..." -Verbose
54+
$exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
55+
}
56+
57+
# all obvious locations are exhausted, use brute force and search from the root of the filesystem
58+
if(!$exeSource)
59+
{
60+
Write-Verbose "Falling back to the root of the drive..." -Verbose
61+
$exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
62+
}
63+
64+
if(!$exeSource)
65+
{
66+
throw "$Executable not found"
67+
}
68+
69+
$exePath = Split-Path -Path $exeSource
70+
Add-Path -path $exePath
71+
}
72+
73+
if($Cleanup.IsPresent)
74+
{
75+
Remove-Folder -Folder "$env:temp\chocolatey"
76+
}
77+
}
78+
79+
function Add-Path
80+
{
81+
param
82+
(
83+
$path
84+
)
85+
$machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine)
86+
$machinePath = $machinePathString -split ';'
87+
88+
if($machinePath -inotcontains $path)
89+
{
90+
$newPath = "$machinePathString;$path"
91+
Write-Verbose "Adding $path to path..." -Verbose
92+
[System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine)
93+
Write-Verbose "Added $path to path." -Verbose
94+
$env:Path += ";$newPath"
95+
}
96+
else
97+
{
98+
Write-Verbose "$path already in path." -Verbose
99+
}
100+
}
101+
102+
function Remove-Folder
103+
{
104+
param(
105+
[string]
106+
$Folder
107+
)
108+
109+
Write-Verbose "Cleaning up $Folder..." -Verbose
110+
$filter = Join-Path -Path $Folder -ChildPath *
111+
[int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
112+
Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue
113+
Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose
114+
}

0 commit comments

Comments
 (0)