From 440eba3cae6ba0730f6f671777998bb602c9857e Mon Sep 17 00:00:00 2001 From: Riff Date: Mon, 2 Aug 2021 22:45:34 -0700 Subject: [PATCH] Adding debian package generation support during build. (#74) --- azure-pipelines.yml | 74 +++++++++++++++++++++++++++++- build/pack/PackReleasePackages.ps1 | 14 +++++- build/templates/debian/control | 5 ++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 build/templates/debian/control diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 04cc6f8..05e4be5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,6 +46,7 @@ stages: is_cross_compile: true gcc_prefix: gcc_suffix: + deb_arch: windows-x64: poolName: Azure Pipelines imageName: 'windows-latest' @@ -55,6 +56,7 @@ stages: is_cross_compile: false gcc_prefix: gcc_suffix: + deb_arch: windows-arm64: poolName: Azure Pipelines imageName: 'windows-latest' @@ -64,6 +66,7 @@ stages: is_cross_compile: true gcc_prefix: gcc_suffix: + deb_arch: linux-x86: poolName: Azure Pipelines imageName: 'ubuntu-latest' @@ -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' @@ -82,6 +86,7 @@ stages: is_cross_compile: false gcc_prefix: gcc_suffix: + deb_arch: amd64 linux-arm: poolName: Azure Pipelines imageName: 'ubuntu-latest' @@ -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' @@ -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' @@ -109,6 +116,7 @@ stages: is_cross_compile: false gcc_prefix: gcc_suffix: + deb_arch: pool: name: $(poolName) @@ -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 # @@ -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) @@ -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: diff --git a/build/pack/PackReleasePackages.ps1 b/build/pack/PackReleasePackages.ps1 index be05929..53ec12a 100644 --- a/build/pack/PackReleasePackages.ps1 +++ b/build/pack/PackReleasePackages.ps1 @@ -33,6 +33,7 @@ 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]@{ @@ -40,48 +41,56 @@ function PackPerFlavorReleases() { "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; }; } @@ -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) { @@ -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 } } diff --git a/build/templates/debian/control b/build/templates/debian/control new file mode 100644 index 0000000..c686a55 --- /dev/null +++ b/build/templates/debian/control @@ -0,0 +1,5 @@ +Package: Rnp +Version: {build_version} +Architecture: {deb_arch} +Maintainer: r12f +Description: A simple layer 4 ping tool for cloud.