Skip to content

Commit 414d561

Browse files
TravisEz13adityapatwardhan
authored andcommitted
Move release build definition into PowerShell (PowerShell#4884)
* Add docker related files from PSRelease base release docker builds on PowerShell release docker images * ignore the PSRelease folder * Add vstsbuild.sh wrapper of vstsbuild.ps1 * add vstsbuild.ps1 * Add build.json * address PR feedbock
1 parent dd02aac commit 414d561

File tree

10 files changed

+384
-0
lines changed

10 files changed

+384
-0
lines changed

tools/releaseBuild/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PSRelease/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# PowerShell Script to build and package PowerShell from specified form and branch
2+
# Script is intented to use in Docker containers
3+
# Ensure PowerShell is available in the provided image
4+
5+
param (
6+
[string] $location = "/powershell",
7+
8+
# Destination location of the package on docker host
9+
[string] $destination = '/mnt',
10+
11+
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")]
12+
[ValidateNotNullOrEmpty()]
13+
[string]$ReleaseTag,
14+
[switch]$AppImage
15+
)
16+
17+
$releaseTagParam = @{}
18+
if($ReleaseTag)
19+
{
20+
$releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag }
21+
}
22+
23+
Push-Location
24+
try {
25+
Set-Location $location
26+
Import-Module "$location/build.psm1"
27+
Import-Module "$location/tools/packaging"
28+
29+
Start-PSBootstrap -Package -NoSudo
30+
Start-PSBuild -Crossgen -PSModuleRestore @releaseTagParam
31+
32+
Start-PSPackage @releaseTagParam
33+
if($AppImage.IsPresent)
34+
{
35+
Start-PSPackage -Type AppImage @releaseTagParam
36+
}
37+
}
38+
finally
39+
{
40+
Pop-Location
41+
}
42+
43+
$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm
44+
45+
foreach($linuxPackage in $linuxPackages)
46+
{
47+
Copy-Item -Path $linuxPackage.FullName -Destination $destination -force
48+
}
49+
50+
if($AppImage.IsPresent)
51+
{
52+
$appImages = Get-ChildItem -Path $location -Filter '*.AppImage'
53+
foreach($appImageFile in $appImages)
54+
{
55+
Copy-Item -Path $appImageFile.FullName -Destination $destination -force
56+
}
57+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Docker image file that describes an Centos7 image with PowerShell installed from Microsoft YUM Repo
2+
3+
FROM microsoft/powershell:centos7
4+
LABEL maintainer="PowerShell Team <[email protected]>"
5+
6+
# Install dependencies and clean up
7+
RUN yum install -y \
8+
glibc \
9+
libcurl \
10+
ca-certificates \
11+
libgcc \
12+
libicu \
13+
openssl \
14+
libstdc++ \
15+
ncurses-base \
16+
libunwind \
17+
uuid \
18+
zlib \
19+
which \
20+
curl \
21+
git \
22+
&& yum clean all
23+
24+
COPY PowerShellPackage.ps1 /
25+
26+
# Use PowerShell as the default shell
27+
ENTRYPOINT [ "powershell" ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Docker image file that describes an Ubuntu14.04 image with PowerShell installed from Microsoft APT Repo
2+
3+
FROM microsoft/powershell:ubuntu14.04
4+
LABEL maintainer="PowerShell Team <[email protected]>"
5+
6+
# Install dependencies and clean up
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
apt-utils \
10+
libc6 \
11+
libcurl3 \
12+
ca-certificates \
13+
libgcc1 \
14+
libicu52 \
15+
libssl1.0.0 \
16+
libstdc++6 \
17+
libtinfo5 \
18+
libunwind8 \
19+
libuuid1 \
20+
libcroco3 \
21+
libgraphite2-3 \
22+
zlib1g \
23+
curl \
24+
git \
25+
apt-transport-https \
26+
wget \
27+
dpkg-dev \
28+
libfuse-dev \
29+
fuse \
30+
python \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
COPY PowerShellPackage.ps1 /
34+
35+
# Use PowerShell as the default shell
36+
ENTRYPOINT [ "powershell" ]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Docker image file that describes an Ubuntu16.04 image with PowerShell installed from Microsoft APT Repo
2+
3+
FROM microsoft/powershell:ubuntu16.04
4+
LABEL maintainer="PowerShell Team <[email protected]>"
5+
6+
# Install dependencies and clean up
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
apt-utils \
10+
apt-utils \
11+
libc6 \
12+
libcurl3 \
13+
ca-certificates \
14+
libgcc1 \
15+
libicu55 \
16+
libssl1.0.0 \
17+
libstdc++6 \
18+
libtinfo5 \
19+
libunwind8 \
20+
libuuid1 \
21+
libcroco3 \
22+
libgraphite2-3 \
23+
zlib1g \
24+
curl \
25+
git \
26+
apt-transport-https \
27+
locales \
28+
wget \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
COPY PowerShellPackage.ps1 /
32+
33+
# Use PowerShell as the default shell
34+
ENTRYPOINT [ "powershell" ]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# escape=`
2+
#0.3.6 (no powershell 6)
3+
FROM travisez13/microsoft.windowsservercore.build-tools:latest
4+
LABEL maintainer='PowerShell Team <[email protected]>'
5+
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."
6+
7+
SHELL ["powershell"]
8+
9+
COPY PowerShellPackage.ps1 /
10+
11+
ENTRYPOINT ["powershell"]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[cmdletbinding()]
2+
# PowerShell Script to clone, build and package PowerShell from specified fork and branch
3+
param (
4+
[string] $fork = 'powershell',
5+
[string] $branch = 'master',
6+
[string] $location = "$pwd\powershell",
7+
[string] $destination = "$env:WORKSPACE",
8+
[ValidateSet("win7-x64", "win81-x64", "win10-x64", "win7-x86")]
9+
[string]$Runtime = 'win10-x64',
10+
[switch] $Wait,
11+
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")]
12+
[ValidateNotNullOrEmpty()]
13+
[string]$ReleaseTag
14+
)
15+
16+
$releaseTagParam = @{}
17+
if($ReleaseTag)
18+
{
19+
$releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag }
20+
}
21+
22+
if(-not $env:homedrive)
23+
{
24+
Write-Verbose "fixing empty home paths..." -Verbose
25+
$profileParts = $env:userprofile -split ':'
26+
$env:homedrive = $profileParts[0]+':'
27+
$env:homepath = $profileParts[1]
28+
}
29+
30+
if(! (Test-Path $destination))
31+
{
32+
Write-Verbose "Creating destination $destination" -Verbose
33+
$null = New-Item -Path $destination -ItemType Directory
34+
}
35+
36+
Write-Verbose "homedrive : ${env:homedrive}"
37+
Write-Verbose "homepath : ${env:homepath}"
38+
39+
# Don't use CIM_PhysicalMemory, docker containers may cache old values
40+
$memoryMB = (Get-CimInstance win32_computersystem).TotalPhysicalMemory /1MB
41+
$requiredMemoryMB = 2048
42+
if($memoryMB -lt $requiredMemoryMB)
43+
{
44+
throw "Building powershell requires at least $requiredMemoryMB MiB of memory and only $memoryMB MiB is present."
45+
}
46+
Write-Verbose "Running with $memoryMB MB memory." -Verbose
47+
48+
try{
49+
Set-Location $location
50+
51+
Import-Module "$location\build.psm1" -Force
52+
Import-Module "$location\tools\packaging" -Force
53+
$env:platform = $null
54+
Write-Verbose "Bootstrapping powershell build..." -verbose
55+
Start-PSBootstrap -Force -Package
56+
57+
Write-Verbose "Starting powershell build for RID: $Runtime and ReleaseTag: $ReleaseTag ..." -verbose
58+
Start-PSBuild -Clean -CrossGen -PSModuleRestore -Runtime $Runtime -Configuration Release @releaseTagParam
59+
60+
$pspackageParams = @{'Type'='msi'}
61+
if ($Runtime -ne 'win10-x64')
62+
{
63+
$pspackageParams += @{'WindowsRuntime'=$Runtime}
64+
}
65+
66+
Write-Verbose "Starting powershell packaging(msi)..." -verbose
67+
Start-PSPackage @pspackageParams @releaseTagParam
68+
69+
$pspackageParams['Type']='zip'
70+
Write-Verbose "Starting powershell packaging(zip)..." -verbose
71+
Start-PSPackage @pspackageParams @releaseTagParam
72+
73+
Write-Verbose "Exporting packages ..." -verbose
74+
75+
Get-ChildItem $location\*.msi,$location\*.zip | Select-Object -ExpandProperty FullName | ForEach-Object {
76+
$file = $_
77+
Write-Verbose "Copying $file to $destination" -verbose
78+
Copy-Item -Path $file -Destination "$destination\" -Force
79+
}
80+
}
81+
finally
82+
{
83+
Write-Verbose "Beginning build clean-up..." -verbose
84+
if($Wait.IsPresent)
85+
{
86+
$path = Join-Path $PSScriptRoot -ChildPath 'delete-to-continue.txt'
87+
$null = New-Item -Path $path -ItemType File
88+
Write-Verbose "Computer name: $env:COMPUTERNAME" -Verbose
89+
Write-Verbose "Delete $path to exit." -Verbose
90+
while(Test-Path -LiteralPath $path)
91+
{
92+
Start-Sleep -Seconds 60
93+
}
94+
}
95+
}

tools/releaseBuild/build.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"Windows": [
3+
{
4+
"Name": "win7-x64",
5+
"RepoDestinationPath": "C:\\PowerShell",
6+
"BuildCommand": "C:\\PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -Runtime win7-x64 -ReleaseTag _ReleaseTag_",
7+
"BuildDockerOptions": [
8+
"-m",
9+
"3968m"
10+
],
11+
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
12+
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
13+
"DockerImageName": "ps-winsrvcore"
14+
},
15+
{
16+
"Name": "win7-x86",
17+
"RepoDestinationPath": "C:\\PowerShell",
18+
"BuildCommand": "C:\\PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -Runtime win7-x86 -ReleaseTag _ReleaseTag_",
19+
"BuildDockerOptions": [
20+
"-m",
21+
"3968m"
22+
],
23+
"DockerFile": ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\DockerFile",
24+
"AdditionalContextFiles" :[ ".\\tools\\releaseBuild\\Images\\microsoft_powershell_windowsservercore\\PowerShellPackage.ps1"],
25+
"DockerImageName": "ps-winsrvcore"
26+
}
27+
],
28+
"Linux": [
29+
{
30+
"Name": "ubuntu.14.04",
31+
"RepoDestinationPath": "/PowerShell",
32+
"BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -AppImage",
33+
"BuildDockerOptions": [
34+
"--cap-add",
35+
"SYS_ADMIN",
36+
"--cap-add",
37+
"MKNOD",
38+
"--device=/dev/fuse",
39+
"--security-opt",
40+
"apparmor:unconfined"
41+
],
42+
"DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_ubuntu14.04/Dockerfile",
43+
"AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"],
44+
"DockerImageName": "ps-ubunutu-14-04"
45+
},
46+
{
47+
"Name": "ubuntu.16.04",
48+
"RepoDestinationPath": "/PowerShell",
49+
"BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_",
50+
"AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"],
51+
"DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_ubuntu16.04/Dockerfile",
52+
"DockerImageName": "ps-ubunutu-16-04"
53+
},
54+
{
55+
"Name": "centos.7",
56+
"RepoDestinationPath": "/PowerShell",
57+
"BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_",
58+
"AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"],
59+
"DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_centos7/Dockerfile",
60+
"DockerImageName": "ps-centos-7"
61+
}
62+
]
63+
}

tools/releaseBuild/vstsbuild.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
param(
2+
[Parameter(ParameterSetName='Build')]
3+
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")]
4+
[string]$ReleaseTag,
5+
6+
[ValidateSet('win7-x86','win7-x64','ubuntu.14.04','ubuntu.16.04','centos.7')]
7+
[String]
8+
$Name
9+
)
10+
$ErrorActionPreference = 'Stop'
11+
12+
13+
$psReleaseBranch = 'master'
14+
$psReleaseFork = 'PowerShell'
15+
$location = Join-Path -Path $PSScriptRoot -ChildPath 'PSRelease'
16+
if(Test-Path $location)
17+
{
18+
Remove-Item -Path $location -Recurse -Force
19+
}
20+
21+
$gitBinFullPath = (Get-Command -Name git).Source
22+
if (-not $gitBinFullPath)
23+
{
24+
throw "Git is required to proceed. Install from 'https://git-scm.com/download/win'"
25+
}
26+
27+
Write-Verbose "cloning -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git" -verbose
28+
& $gitBinFullPath clone -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git $location
29+
30+
Push-Location -Path $PWD.Path
31+
try{
32+
Set-Location $location
33+
& $gitBinFullPath submodule update --init --recursive --quiet
34+
}
35+
finally
36+
{
37+
Pop-Location
38+
}
39+
40+
$unresolvedRepoRoot = Join-Path -Path $PSScriptRoot '../..'
41+
$resolvedRepoRoot = (Resolve-Path -Path $unresolvedRepoRoot).ProviderPath
42+
43+
try
44+
{
45+
Write-Verbose "Starting build at $resolvedRepoRoot ..." -Verbose
46+
Import-Module "$location/vstsBuild" -Force
47+
Import-Module "$location/dockerBasedBuild" -Force
48+
Clear-VstsTaskState
49+
50+
Invoke-Build -RepoPath $resolvedRepoRoot -BuildJsonPath './tools/releaseBuild/build.json' -Name $Name -Parameters $PSBoundParameters
51+
}
52+
catch
53+
{
54+
Write-VstsError -Error $_
55+
}
56+
finally{
57+
Write-VstsTaskState
58+
exit 0
59+
}

tools/releaseBuild/vstsbuild.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
powershell -command ".\vstsbuild.ps1 $*"

0 commit comments

Comments
 (0)