From f8ae38c9b6d1d3162f20c65437741bec9b32ee60 Mon Sep 17 00:00:00 2001 From: Animesh Narayan Dangwal Date: Fri, 27 Mar 2020 19:12:45 +0530 Subject: [PATCH 1/3] Linkerd CLI Chocolatey Package This PR partially fixes #3063 by building a chocolatey package for Linkerd2's Windows CLI It adds the build scripts for the Linkerd chocolatey package and based on discussions in https://github.com/linkerd/linkerd2/pull/3921 The package currently exists in the `bin/win` folder The `.nuspec` script has been modified for easy integration with the workflow done by @ihcsim here: https://github.com/ihcsim/linkerd-chocolatey To build outside of workflow environment (on windows system): - Modify `linkerd.nuspec` version tag to an available stable version of Linkerd2's cli eg: stable-2.7.0 - Install chocolatey - cd into `bin/win/` - Run `choco pack` - Run `choco install linkerd -s .` (make sure cmd/ powershell is running as administrator) - Run refreshenv to add `linkerd.exe` path to system - To unistall run `choco uninstall linkerd` Tackling requirements discussed in https://github.com/linkerd/linkerd2/pull/3921 (specifically: https://github.com/linkerd/linkerd2/pull/3921#issuecomment-599634476) - Followed folder structure as described here: https://github.com/ihcsim/linkerd-chocolatey - Modified package to accept version through the metadata available in `.nuspec` file - Modified package to override install path with command line arg/ env variable To run with command line argument: - Run `choco install linkerd -s . --params="/path:"` To run with environment variable: - Run `$env:linkerdPath = ""` in powershell Uses default chocolatey install path if none of the above provided. - Modified package to accept command line args/ env variable for checksum To run with command line argument: - Run `choco install linkerd -s . --params="/checksum:"` (Keep params space seperated when specifying multiple) To run with environment variable: - Run `$env:linkerdCheckSum = ""` If no checksum provided, default null value assigned and package ignores verification step - This package is compatible in a non-administrative environment but one must install chocolatey in a non-administrative path. (Steps explained here: https://chocolatey.org/docs/installation#non-administrative-install) Further plans: This PR is part of a set of planned PRs based on the discussions in https://github.com/linkerd/linkerd2/pull/3921 (specifically: https://github.com/linkerd/linkerd2/pull/3921#issuecomment-599099615) Signed-off-by: Animesh Narayan Dangwal --- bin/win/linkerd.nuspec | 32 ++++++++++++++++++++++++++++ bin/win/tools/chocolateyinstall.ps1 | 33 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 bin/win/linkerd.nuspec create mode 100644 bin/win/tools/chocolateyinstall.ps1 diff --git a/bin/win/linkerd.nuspec b/bin/win/linkerd.nuspec new file mode 100644 index 0000000000000..1cbc7396370d9 --- /dev/null +++ b/bin/win/linkerd.nuspec @@ -0,0 +1,32 @@ + + + + linkerd + ${LINKERD_VERSION} + + Linkerd + Linkerd + Ultralight service mesh for Kubernetes and beyond + + Linkerd is an ultralight service mesh for Kubernetes. + It gives you observability, reliability, and security without requiring any code changes. + + Package Parameters + - `path`: Specify path for linkerd-cli installation. If not specified, uses environment variable `linkerdPath`. Uses default chocolatey install path if none provided. + - `checksum`: Specify the checksum for linkerd-cli. If not specified, uses environment variable `linkerdCheckSum`. Defaults to `null` if no checksum provided and skips verification. Do ensure to use the correct checksum for the version of install. + + + https://github.com/linkerd/linkerd2 + https://github.com/linkerd/linkerd2/blob/master/LICENSE + https://github.com/linkerd/linkerd2/releases + https://linkerd.io/docs + + + + + + + + + + \ No newline at end of file diff --git a/bin/win/tools/chocolateyinstall.ps1 b/bin/win/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000000..1a015329b0660 --- /dev/null +++ b/bin/win/tools/chocolateyinstall.ps1 @@ -0,0 +1,33 @@ +$ErrorActionPreference = 'Stop'; +$toolsPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" + +$version = $env:chocolateyPackageVersion +$pp = Get-PackageParameters + +if ($pp['path'] -ne $null){ + $lpath = $pp['path'] +} +elseif (Test-Path env:linkerdPath) { + $lpath = $env:linkerdPath +} +else { + $lpath = $toolsPath +} + +if ($pp['checksum'] -ne $null){ + $checksum = $pp['checksum'] +} +else{ + $checksum = $env:linkerdCheckSum +} + +$packageArgs = @{ + packageName = 'linkerd' + fileFullPath = "$lpath\linkerd.exe" + url64 = "https://github.com/linkerd/linkerd2/releases/download/$version/linkerd2-cli-$version-windows.exe" + checksum = $checksum + checksumType = 'sha256' +} + +Get-ChocolateyWebFile @packageArgs +Install-ChocolateyPath $packageArgs.fileFullPath 'User' From 05a2a9b16a4cb6656ee032e069960b6fc1b4c679 Mon Sep 17 00:00:00 2001 From: Animesh Narayan Dangwal Date: Wed, 15 Apr 2020 12:06:59 +0530 Subject: [PATCH 2/3] Adding PR Feedback Modified `chocolateyinstall.ps1` to follow the default rules in linter `PSScriptAnalyzer` Modified `static_checks.yml` to ignore `win` folder during shellcheck Signed-off-by: Animesh Narayan Dangwal --- .github/workflows/static_checks.yml | 2 ++ bin/win/tools/chocolateyinstall.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 24d152585d1a1..d595e84e27bcd 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -114,4 +114,6 @@ jobs: ! -name test-scale \ ! -name update-go-deps-shas \ ! -name web \ + ! -name *.nuspec \ + ! -name *.ps1 \ | xargs -I {} bin/shellcheck -x {} diff --git a/bin/win/tools/chocolateyinstall.ps1 b/bin/win/tools/chocolateyinstall.ps1 index 1a015329b0660..b11ec2625fb59 100644 --- a/bin/win/tools/chocolateyinstall.ps1 +++ b/bin/win/tools/chocolateyinstall.ps1 @@ -4,7 +4,7 @@ $toolsPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $version = $env:chocolateyPackageVersion $pp = Get-PackageParameters -if ($pp['path'] -ne $null){ +if ($null -ne $pp['path']){ $lpath = $pp['path'] } elseif (Test-Path env:linkerdPath) { @@ -14,7 +14,7 @@ else { $lpath = $toolsPath } -if ($pp['checksum'] -ne $null){ +if ($null -ne $pp['checksum']){ $checksum = $pp['checksum'] } else{ From 125b1929538c17add5de1d2c990ab094cb1a0241 Mon Sep 17 00:00:00 2001 From: Animesh Narayan Dangwal Date: Thu, 16 Apr 2020 22:28:46 +0530 Subject: [PATCH 3/3] Fixed version string usage Modified `chocolateyinstall.ps1` to accept version string correctly Signed-off-by: Animesh Narayan Dangwal --- bin/win/tools/chocolateyinstall.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/win/tools/chocolateyinstall.ps1 b/bin/win/tools/chocolateyinstall.ps1 index b11ec2625fb59..6c05e392471d8 100644 --- a/bin/win/tools/chocolateyinstall.ps1 +++ b/bin/win/tools/chocolateyinstall.ps1 @@ -24,7 +24,7 @@ else{ $packageArgs = @{ packageName = 'linkerd' fileFullPath = "$lpath\linkerd.exe" - url64 = "https://github.com/linkerd/linkerd2/releases/download/$version/linkerd2-cli-$version-windows.exe" + url64 = "https://github.com/linkerd/linkerd2/releases/download/stable-$version/linkerd2-cli-stable-$version-windows.exe" checksum = $checksum checksumType = 'sha256' }