Build Alpine tar.gz package in release builds (#8340)

Enable building tar.gz package for Alpine in release builds.

## PR Checklist

- [x] [PR has a meaningful title](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
    - Use the present tense and imperative mood when describing your changes
- [x] [Summarized changes](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
- [x] [Change is not breaking](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#making-breaking-changes)
- [x] [Make sure all `.h`, `.cpp`, `.cs`, `.ps1` and `.psm1` files have the correct copyright header](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
- [x] This PR is ready to merge and is not [Work in Progress](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---work-in-progress).
    - If the PR is work in progress, please add the prefix `WIP:` to the beginning of the title and remove the prefix when the PR is ready.
- **User-facing changes**
    - [x] Not Applicable
    - **OR**
    - [ ] User-facing [Documentation needed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)
        - [ ] Issue filed - Issue link:
- **Testing - New and feature**
    - [x] Not Applicable or can only be tested interactively
    - **OR**
    - [ ] [Make sure you've added a new test if existing tests do not effectively test the code changed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#before-submitting)
        - [ ] [Add `[feature]` if the change is significant or affects feature tests](https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/testing-guidelines.md#requesting-additional-tests-for-a-pr)
This commit is contained in:
Aditya Patwardhan 2018-11-27 10:45:49 -08:00 committed by Travis Plunk
parent 58bbfe8396
commit b0daa1e724
6 changed files with 34 additions and 123 deletions

View file

@ -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",

View file

@ -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

View file

@ -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
}

View file

@ -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 <powershellteam@hotmail.com>"
# 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" ]

View file

@ -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"
<Project>
<Target Name="_GetDependencies"
DependsOnTargets="ResolveAssemblyReferencesDesignTime">
<ItemGroup>
<_RefAssemblyPath Include="%(_ReferencesFromRAR.HintPath)%3B" Condition=" '%(_ReferencesFromRAR.NuGetPackageId)' != 'Microsoft.Management.Infrastructure' "/>
</ItemGroup>
<WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" />
</Target>
</Project>
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"

View file

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