Skip to content

Commit

Permalink
Adding debian package generation support during build. (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f authored Aug 3, 2021
1 parent 1b13e63 commit 440eba3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
74 changes: 73 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ stages:
is_cross_compile: true
gcc_prefix:
gcc_suffix:
deb_arch:
windows-x64:
poolName: Azure Pipelines
imageName: 'windows-latest'
Expand All @@ -55,6 +56,7 @@ stages:
is_cross_compile: false
gcc_prefix:
gcc_suffix:
deb_arch:
windows-arm64:
poolName: Azure Pipelines
imageName: 'windows-latest'
Expand All @@ -64,6 +66,7 @@ stages:
is_cross_compile: true
gcc_prefix:
gcc_suffix:
deb_arch:
linux-x86:
poolName: Azure Pipelines
imageName: 'ubuntu-latest'
Expand All @@ -73,6 +76,7 @@ stages:
is_cross_compile: true
gcc_prefix: x86_64-linux-gnu-
gcc_suffix: -x86_64-linux-gnu
deb_arch: x86
linux-x64:
poolName: Azure Pipelines
imageName: 'ubuntu-latest'
Expand All @@ -82,6 +86,7 @@ stages:
is_cross_compile: false
gcc_prefix:
gcc_suffix:
deb_arch: amd64
linux-arm:
poolName: Azure Pipelines
imageName: 'ubuntu-latest'
Expand All @@ -91,6 +96,7 @@ stages:
is_cross_compile: true
gcc_prefix: arm-linux-gnueabi-
gcc_suffix: -arm-linux-gnueabi
deb_arch: arm
linux-arm64:
poolName: Azure Pipelines
imageName: 'ubuntu-latest'
Expand All @@ -100,6 +106,7 @@ stages:
is_cross_compile: true
gcc_prefix: aarch64-linux-gnu-
gcc_suffix: -aarch64-linux-gnu
deb_arch: arm64
macos-x64:
poolName: Azure Pipelines
imageName: 'macos-latest'
Expand All @@ -109,6 +116,7 @@ stages:
is_cross_compile: false
gcc_prefix:
gcc_suffix:
deb_arch:

pool:
name: $(poolName)
Expand Down Expand Up @@ -314,6 +322,35 @@ stages:
sourceFolder: '$(Build.SourcesDirectory)/build/pack'
targetFolder: '$(Build.ArtifactStagingDirectory)/pack'

- bash: |
deb_pkg_name=rnp_$(build.version)-1_$(DEB_ARCH)
echo "Creating deb package: $deb_pkg_name"
echo "Copy binaries to $deb_pkg_name/usr/local/bin"
mkdir -p $deb_pkg_name/usr/local/bin
cp rnp $deb_pkg_name/usr/local/bin/
echo ""
echo "Generating deb package control file: $deb_pkg_name"
mkdir -p $deb_pkg_name/DEBIAN
cat $(Build.SourcesDirectory)/build/templates/debian/control | sed -e 's/{build_version}/$(build.version)/g' -e 's/{deb_arch}/$(DEB_ARCH)/g' > $deb_pkg_name/DEBIAN/control
echo "Deb package control file generated: $deb_pkg_name/DEBIAN/control"
cat $deb_pkg_name/DEBIAN/control
echo ""
echo "Building deb package: $deb_pkg_name"
dpkg-deb --build --root-owner-group $deb_pkg_name
if [ $? -ne 0 ]; then
echo "Build deb package failed!"
exit 1
fi
mkdir -p $(Build.ArtifactStagingDirectory)/debian
cp $deb_pkg_name.deb $(Build.ArtifactStagingDirectory)/debian/
displayName: Build debian packages
condition: and(succeeded(), ne(variables['deb_arch'], ''))
workingDirectory: $(Build.SourcesDirectory)/target/$(TARGET)/release
#
# Publish all pipeline artifacts
#
Expand Down Expand Up @@ -396,12 +433,15 @@ stages:
windows-x64:
poolName: Azure Pipelines
imageName: 'windows-latest'
target_short: windows.x64
linux-x64:
poolName: Azure Pipelines
imageName: 'ubuntu-latest'
target_short: linux.x64
macos-x64:
poolName: Azure Pipelines
imageName: 'macos-latest'
target_short: macos.x64

pool:
name: $(poolName)
Expand Down Expand Up @@ -446,7 +486,39 @@ stages:
cargo install --path .
displayName: 'Install Rnp from source package'
workingDirectory: $(System.DefaultWorkingDirectory)/Source
- bash: |
echo "Checking rnp exists before installation"
dpkg -l | grep rnp
echo ""
echo "Install rnp from debian package"
sudo dpkg -i ./rnp_$(build.version)-1_amd64.deb
if [ $? -ne 0 ]; then
echo "Failed to install rnp from debian package"
exit 1
fi
echo ""
echo "Check if rnp is successfully installed"
dpkg -l | grep rnp
echo ""
echo "Uninstall rnp"
sudo dpkg -r rnp
if [ $? -ne 0 ]; then
echo "Failed to uninstall rnp"
exit 1
fi
echo ""
echo "Check if rnp is successfully uninstalled"
dpkg -l | grep rnp
echo ""
displayName: 'Install Rnp from debian package'
condition: and(succeeded(), eq(variables['target_short'], 'linux.x64'))
workingDirectory: $(System.DefaultWorkingDirectory)/r12f.rnp/Pack.Pack/Releases/DebianPackages
- task: PublishPipelineArtifact@1
displayName: Publish pipeline artifact
inputs:
Expand Down
14 changes: 13 additions & 1 deletion build/pack/PackReleasePackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,64 @@ function PackAllReleasePackages() {
function PackPerFlavorReleases() {
New-Item -ItemType Directory -Path ".\Releases\GithubReleases"
New-Item -ItemType Directory -Path ".\Releases\NugetPackages"
New-Item -ItemType Directory -Path ".\Releases\DebianPackages"

$flavors = @{
"windows.x86" = [PsCustomObject]@{
"Root" = "Build.Build.windowsx86";
"Target" = "i686-pc-windows-msvc";
"PackZip" = $true;
"PackTar" = $false;
"CopyDebian" = $false;
};
"windows.x64" = [PsCustomObject]@{
"Root" = "Build.Build.windowsx64";
"Target" = "x86_64-pc-windows-msvc";
"PackZip" = $true;
"PackTar" = $false;
"CopyDebian" = $false;
};
"windows.arm64" = [PsCustomObject]@{
"Root" = "Build.Build.windowsarm64";
"Target" = "aarch64-pc-windows-msvc";
"PackZip" = $true;
"PackTar" = $false;
"CopyDebian" = $false;
};
"linux.x86" = [PsCustomObject]@{
"Root" = "Build.Build.linuxx86";
"Target" = "i686-unknown-linux-gnu";
"PackZip" = $false;
"PackTar" = $true;
"CopyDebian" = $true;
};
"linux.x64" = [PsCustomObject]@{
"Root" = "Build.Build.linuxx64";
"Target" = "x86_64-unknown-linux-gnu";
"PackZip" = $false;
"PackTar" = $true;
"CopyDebian" = $true;
};
"linux.arm" = [PsCustomObject]@{
"Root" = "Build.Build.linuxarm";
"Target" = "arm-unknown-linux-gnueabi";
"PackZip" = $false;
"PackTar" = $true;
"CopyDebian" = $true;
};
"linux.arm64" = [PsCustomObject]@{
"Root" = "Build.Build.linuxarm64";
"Target" = "aarch64-unknown-linux-gnu";
"PackZip" = $false;
"PackTar" = $true;
"CopyDebian" = $true;
};
"macos.x64" = [PsCustomObject]@{
"Root" = "Build.Build.macosx64";
"Target" = "x86_64-apple-darwin";
"PackZip" = $false;
"PackTar" = $true;
"CopyDebian" = $false;
};
}

Expand All @@ -90,7 +99,7 @@ function PackPerFlavorReleases() {
$settings = $_.Value
$root = $_.Value.Root
$target = $_.Value.Target
Write-Host "Processing build: Flavor = $flavor, Root = $root, Target = $target, PackZip = $($settings.PackZip), PackTar = $($settings.PackTar)"
Write-Host "Processing build: Flavor = $flavor, Root = $root, Target = $target, PackZip = $($settings.PackZip), PackTar = $($settings.PackTar), CopyDebian = $($settings.CopyDebian)"

# Create zip for github release
if ($settings.PackZip) {
Expand Down Expand Up @@ -119,6 +128,9 @@ function PackPerFlavorReleases() {
Copy-Item -Path .\$root\bin\* $nugetProjectRoot -Verbose -Force
EvaluateTemplateFile ".\Build.Build.windowsx64\templates\nuget_packages\rnp_nupkg.csproj" "$nugetProjectRoot\rnp_nupkg.csproj" $flavor $target
dotnet pack $nugetProjectRoot\rnp_nupkg.csproj -o .\Releases\NugetPackages

# Copy debian packages
Copy-Item -Path .\$root\debian\* ".\Releases\DebianPackages" -Verbose -Force
}
}

Expand Down
5 changes: 5 additions & 0 deletions build/templates/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Package: Rnp
Version: {build_version}
Architecture: {deb_arch}
Maintainer: r12f <[email protected]>
Description: A simple layer 4 ping tool for cloud.

0 comments on commit 440eba3

Please sign in to comment.