From ad07d91de7d5ee2ba7902f2a89b3299b88e2ab0e Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 16 Aug 2018 16:11:52 -0700 Subject: [PATCH 1/3] Fix typo in environment checker --- build.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 57e56a06197..722b2cdb812 100644 --- a/build.psm1 +++ b/build.psm1 @@ -158,7 +158,7 @@ function Get-EnvironmentInformation $environment.IsDebian -or $environment.IsUbuntu -or $environmment.IsRedHatFamily -or - $environmment.IsSUSEFamily) + $environment.IsSUSEFamily) ) { throw "The current OS : $($LinuxInfo.ID) is not supported for building PowerShell." } From ddb02a1d7982384b27991b6c4dae5ba64ca1daef Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 26 Nov 2018 14:07:27 -0800 Subject: [PATCH 2/3] Enable building Alpine through docker based build --- build.psm1 | 16 ++++++++++++---- tools/packaging/packaging.psm1 | 18 +++++++++--------- .../GenericLinuxFiles/PowerShellPackage.ps1 | 7 ++++++- .../microsoft_powershell_alpine3/Dockerfile | 8 +++++--- tools/releaseBuild/build.json | 4 ++-- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/build.psm1 b/build.psm1 index b8b6eb4dc5e..dee4eb69298 100644 --- a/build.psm1 +++ b/build.psm1 @@ -148,6 +148,7 @@ function Get-EnvironmentInformation $environment += @{'IsOpenSUSE42.1' = $Environment.IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '42.1'} $environment += @{'IsRedHatFamily' = $Environment.IsCentOS -or $Environment.IsFedora -or $Environment.IsRedHat} $environment += @{'IsSUSEFamily' = $Environment.IsSLES -or $Environment.IsOpenSUSE} + $environment += @{'IsAlpine' = $LinuxInfo.ID -match 'alpine'} # Workaround for temporary LD_LIBRARY_PATH hack for Fedora 24 # https://github.com/PowerShell/PowerShell/issues/2511 @@ -160,7 +161,8 @@ function Get-EnvironmentInformation $environment.IsDebian -or $environment.IsUbuntu -or $environment.IsRedHatFamily -or - $environment.IsSUSEFamily) + $environment.IsSUSEFamily -or + $environment.IsAlpine) ) { throw "The current OS : $($LinuxInfo.ID) is not supported for building PowerShell." } @@ -224,7 +226,7 @@ function Start-PSBuild { # If this parameter is not provided it will get determined automatically. [ValidateSet("fxdependent", "linux-arm", - "linux-musl-x64", + "alpine-x64", "linux-x64", "osx-x64", "win-arm", @@ -594,7 +596,7 @@ function New-PSOptions { [ValidateSet("", "fxdependent", "linux-arm", - "linux-musl-x64", + "alpine-x64", "linux-x64", "osx-x64", "win-arm", @@ -1633,6 +1635,12 @@ function Start-PSBootstrap { # Install patched version of curl Start-NativeExecution { brew install curl --with-openssl --with-gssapi } -IgnoreExitcode + } elseif ($Environment.IsAlpine) { + $Deps += 'libunwind', 'libcurl', 'bash', 'cmake', 'clang', 'build-base', 'git', 'curl' + + Start-NativeExecution { + Invoke-Expression "apk add $Deps" + } } # Install [fpm](https://github.com/jordansissel/fpm) and [ronn](https://github.com/rtomayko/ronn) @@ -2054,7 +2062,7 @@ function Start-CrossGen { [Parameter(Mandatory=$true)] [ValidateSet("linux-arm", - "linux-musl-x64", + "alpine-x64", "linux-x64", "osx-x64", "win-arm", diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index f6637569fa9..611bc96db67 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -25,7 +25,7 @@ function Start-PSPackage { [string]$Name = "powershell", # Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported - [ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg", "tar", "tar-arm", 'tar-musl', 'fxdependent')] + [ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg", "tar", "tar-arm", 'tar-alpine', 'fxdependent')] [string[]]$Type, # Generate windows downlevel package @@ -67,8 +67,8 @@ function Start-PSPackage { $WindowsRuntime, "Release" } elseif ($Type -eq "tar-arm") { New-PSOptions -Configuration "Release" -Runtime "Linux-ARM" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } - } elseif ($Type -eq "tar-musl") { - New-PSOptions -Configuration "Release" -Runtime "Linux-musl-x64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } + } elseif ($Type -eq "tar-alpine") { + New-PSOptions -Configuration "Release" -Runtime "alpine-x64" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } else { New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration } } @@ -112,7 +112,7 @@ function Start-PSPackage { $PSModuleRestoreCorrect = $true } - $precheckFailed = if ($Type -eq 'fxdependent') { + $precheckFailed = if ($Type -eq 'fxdependent' -or $Type -eq 'tar-alpine') { ## We do not check for runtime and crossgen for framework dependent package. -not $Script:Options -or ## Start-PSBuild hasn't been executed yet -not $PSModuleRestoreCorrect -or ## Last build didn't specify '-PSModuleRestore' correctly @@ -376,13 +376,13 @@ function Start-PSPackage { New-TarballPackage @Arguments } } - "tar-musl" { + "tar-alpine" { $Arguments = @{ PackageSourcePath = $Source Name = $Name Version = $Version Force = $Force - Architecture = "musl-x64" + Architecture = "alpine-x64" } if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { @@ -1499,7 +1499,7 @@ function New-UnifiedNugetPackage [string] $LinuxArm32BinPath, [Parameter(Mandatory = $false)] - [string] $LinuxMuslBinPath, + [string] $LinuxAlpineBinPath, [Parameter(Mandatory = $true)] [string] $LinuxBinPath, @@ -1568,9 +1568,9 @@ function New-UnifiedNugetPackage { CreateNugetPlatformFolder -Platform 'linux-arm' -PackageRuntimesFolder $packageRuntimesFolderPath -PlatformBinPath $linuxArm32BinPath - if ($linuxMuslBinPath) + if ($linuxAlpineBinPath) { - CreateNugetPlatformFolder -Platform 'linux-musl-x64' -PackageRuntimesFolder $packageRuntimesFolderPath -PlatformBinPath $linuxMuslBinPath + CreateNugetPlatformFolder -Platform 'alpine-x64' -PackageRuntimesFolder $packageRuntimesFolderPath -PlatformBinPath $LinuxAlpineBinPath } CreateNugetPlatformFolder -Platform 'linux-x64' -PackageRuntimesFolder $packageRuntimesFolderPath -PlatformBinPath $linuxBinPath diff --git a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 index 67a6992a257..377ad694058 100644 --- a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 @@ -18,7 +18,8 @@ param ( [switch]$AppImage, [switch]$TarX64, [switch]$TarArm, - [switch]$FxDependent + [switch]$FxDependent, + [switch]$Alpine ) $releaseTagParam = @{} @@ -39,6 +40,8 @@ try { if($FxDependent.IsPresent) { $buildParams.Add("Runtime", "fxdependent") + } elseif ($Alpine.IsPresent) { + $buildParams.Add("Runtime", 'alpine-x64') } else { $buildParams.Add("Crossgen", $true) } @@ -47,6 +50,8 @@ try { if($FxDependent) { Start-PSPackage -Type 'fxdependent' @releaseTagParam + } elseif ($Alpine) { + Start-PSPackage -Type 'tar-alpine' @releaseTagParam } else { Start-PSPackage @releaseTagParam } diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile b/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile index 4bdbd2a0afd..af7ec8229be 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile @@ -1,12 +1,14 @@ # Docker image file that describes an Centos7 image with PowerShell installed from Microsoft YUM Repo -FROM microsoft/dotnet:2.1-sdk-alpine +FROM mcr.microsoft.com/powershell:6.1.0-alpine-3.8 LABEL maintainer="PowerShell Team " # Install dependencies and clean up RUN apk update \ - && apk add cmake clang build-base git bash + && apk add libunwind libcurl cmake clang build-base git bash curl + +COPY PowerShellPackage.ps1 / ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 -COPY build-and-run-pwsh.sh / +ENTRYPOINT [ "pwsh" ] diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index 214ee44c413..1785bce8971 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -288,8 +288,8 @@ { "Name": "alpine.3", "RepoDestinationPath": "/PowerShell", - "BuildCommand": "/build-and-run-pwsh.sh _RepoDestinationPath_ _DockerVolume_ _ReleaseTag_", - "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh"], + "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -Alpine", + "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"], "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile", "DockerImageName": "ps-alpine-3", "BinaryBucket": "release" From 6bd563fbfdf54139e3528ed21072b84b24b7e498 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 26 Nov 2018 14:09:04 -0800 Subject: [PATCH 3/3] Remove build-and-run-pwsh.sh file --- .../build-and-run-pwsh.sh | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100755 tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh deleted file mode 100755 index e7144c9c505..00000000000 --- a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh - -set -e - -# this script needs to be run from within Alpine with dotnet 2.1 SDK installed, example: -# docker run -it -v ~/repos/PowerShell:/PowerShell microsoft/dotnet:2.1-sdk-alpine - -# build tools required: -# apk update -# apk add build-base gcc abuild binutils git python bash cmake - -# run from root of PowerShell repo: -# tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh /PowerShell /PowerShell 6.1.0 - -repoRoot=$1 -destination=$2 -releaseTag=$3 - -# in Alpine, the currently supported architectures are: - -# x86_64 -# x86 -# aarch64 -# armhf -# ppc64le -# s390x - -# from https://pkgs.alpinelinux.org/packages (Arch dropdown menu) - -arch=`uname -m` - -case $arch in - x86_64) - arch=x64 - ;; - aarch64) - arch=arm64 - ;; - armhf) - arch=arm - ;; - *) - echo "Error: Unsupported OS architecture $arch detected" - exit 1 - ;; -esac - -# set variables depending on releaseTag -# remove v from release tag (v3.5 => 3.5) -if [ "${releaseTag:0:1}" = "v" ]; then - releaseTag=${releaseTag:1} - tarName=$destination/powershell-$releaseTag-linux-musl-$arch.tar.gz - dotnetArguments=/p:ReleaseTag=$releaseTag; -else - tarName=$destination/powershell-linux-musl-$arch.tar.gz -fi - -# Build libpsl-native -cd $repoRoot/src/libpsl-native - -cmake -DCMAKE_BUILD_TYPE=Debug . -make -j - -# Restore packages -cd ../.. -dotnet restore $dotnetArguments - -# run ResGen -cd src/ResGen -dotnet run - -# Create typeCatalog -cd .. -targetFile="Microsoft.PowerShell.SDK/obj/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets" -cat > $targetFile <<-"EOF" - - - - <_RefAssemblyPath Include="%(_ReferencesFromRAR.HintPath)%3B" Condition=" '%(_ReferencesFromRAR.NuGetPackageId)' != 'Microsoft.Management.Infrastructure' "/> - - - - -EOF - -dotnet msbuild Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$(pwd)/TypeCatalogGen/powershell.inc" /nologo - -cd TypeCatalogGen -dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc - -# build PowerShell -cd ../powershell-unix -dotnet publish --configuration Release --runtime linux-musl-x64 $dotnetArguments - -# add libpsl-native to build -mv libpsl-native.so bin/Release/netcoreapp2.1/linux-musl-x64/publish - -# tar build for output -cd bin/Release/netcoreapp2.1/linux-musl-x64/publish - -tar -czvf $tarName . - -echo "Created $tarName"