From 28e4cf4201ce88befb5fe4f70fd7c6521f58acdb Mon Sep 17 00:00:00 2001 From: Matt Fletcher Date: Thu, 26 Mar 2026 11:46:29 -0500 Subject: [PATCH 1/2] adding airgap install instructions --- README.md | 7 +++++++ install-binary.ps1 | 38 +++++++++++++++++++++-------------- install-binary.sh | 49 ++++++++++++++++++++++++++++------------------ 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 42d831f9..4bb8eb5e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,13 @@ This can also be used to compare two revisions/versions of your helm release. helm plugin install https://github.com/databus23/helm-diff ``` +### Installing offline +If installing this in an offline/airgapped environment, download the bin .tgz from [releases](https://github.com/databus23/helm-diff/releases). Set $HELM_DIFF_BIN_TGZ to the absolute path to the bin .tgz. + +Now, run `helm plugin install /path/to/helm-diff/`. + +The install script will skip the github download and instead install from the .tgz. + **For Helm 4 users:** Helm 4 requires plugin verification by default. Since this plugin does not yet provide provenance artifacts, you need to use the `--verify=false` flag: diff --git a/install-binary.ps1 b/install-binary.ps1 index e182b4c3..899b4498 100644 --- a/install-binary.ps1 +++ b/install-binary.ps1 @@ -4,27 +4,22 @@ param ( function Get-Architecture { $architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture - $arch = switch ($architecture) { - "X64" { "amd64" } + "X64" { "amd64" } "Arm64" { "arm64" } Default { "" } } - if ($arch -eq "") { throw "Unsupported architecture: ${architecture}" } - return $arch } function Get-Version { param ([Parameter(Mandatory=$true)][bool] $Update) - if ($Update) { return "latest" } - return git describe --tags --exact-match 2>$null || "latest" } @@ -37,7 +32,6 @@ function New-TemporaryDirectory { function Get-Url { param ([Parameter(Mandatory=$true)][string] $Version, [Parameter(Mandatory=$true)][string] $Architecture) - if ($Version -eq "latest") { return "https://github.com/databus23/helm-diff/releases/latest/download/helm-diff-windows-${Architecture}.tgz" } @@ -46,32 +40,46 @@ function Get-Url { function Download-Plugin { param ([Parameter(Mandatory=$true)][string] $Url, [Parameter(Mandatory=$true)][string] $Output) - Invoke-WebRequest -OutFile $Output $Url } function Install-Plugin { param ([Parameter(Mandatory=$true)][string] $ArchiveDirectory, [Parameter(Mandatory=$true)][string] $ArchiveName, [Parameter(Mandatory=$true)][string] $Destination) - Push-Location $ArchiveDirectory tar -xzf $ArchiveName -C . Pop-Location - New-Item -ItemType Directory -Path $Destination -Force Copy-Item -Path (Join-Path $ArchiveDirectory "diff" "bin" "diff.exe") -Destination $Destination -Force } $ErrorActionPreference = "Stop" - $archiveName = "helm-diff.tgz" $arch = Get-Architecture $version = Get-Version -Update $Update $tmpDir = New-TemporaryDirectory - trap { Remove-Item -path $tmpDir -Recurse -Force } -$url = Get-Url -Version $version -Architecture $arch +# --- MODIFICATION START --- + $output = Join-Path $tmpDir $archiveName -Download-Plugin -Url $url -Output $output -Install-Plugin -ArchiveDirectory $tmpDir -ArchiveName $archiveName -Destination (Join-Path $env:HELM_PLUGIN_DIR "bin") \ No newline at end of file +# Check for offline installation via environment variable +if ($env:HELM_DIFF_BIN_TGZ) { + Write-Host "HELM_DIFF_BIN_TGZ is set. Using local package at: $($env:HELM_DIFF_BIN_TGZ)" + + if (-not (Test-Path $env:HELM_DIFF_BIN_TGZ -PathType Leaf)) { + throw "Offline installation failed: File not found at '$($env:HELM_DIFF_BIN_TGZ)'" + } + Copy-Item -Path $env:HELM_DIFF_BIN_TGZ -Destination $output +} +else { + # Proceed with online installation + Write-Host "HELM_DIFF_BIN_TGZ not set. Proceeding with online installation." + $url = Get-Url -Version $version -Architecture $arch + Download-Plugin -Url $url -Output $output +} + +# --- MODIFICATION END --- + +Install-Plugin -ArchiveDirectory $tmpDir -ArchiveName $archiveName -Destination (Join-Path $env:HELM_PLUGIN_DIR "bin") + diff --git a/install-binary.sh b/install-binary.sh index da8782e9..e108baba 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -10,18 +10,14 @@ export GREP_COLOR="never" # available. This is the case when using MSYS2 or Cygwin # on Windows where helm returns a Windows path but we # need a Unix path - if command -v cygpath >/dev/null 2>&1; then HELM_BIN="$(cygpath -u "${HELM_BIN}")" HELM_PLUGIN_DIR="$(cygpath -u "${HELM_PLUGIN_DIR}")" fi [ -z "$HELM_BIN" ] && HELM_BIN=$(command -v helm) - [ -z "$HELM_HOME" ] && HELM_HOME=$(helm env | grep 'HELM_DATA_HOME' | cut -d '=' -f2 | tr -d '"') - mkdir -p "$HELM_HOME" - : "${HELM_PLUGIN_DIR:="$HELM_HOME/plugins/helm-diff"}" if [ "$SKIP_BIN_INSTALL" = "1" ]; then @@ -55,7 +51,6 @@ initArch() { # initOS discovers the operating system for this system. initOS() { OS=$(uname -s) - case "$OS" in Windows_NT) OS='windows' ;; # Msys support @@ -77,16 +72,21 @@ verifySupported() { exit 1 fi - if - ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1 - then - echo "Either curl or wget is required" - exit 1 + # Skip download tool check if using local file + if [ -z "$HELM_DIFF_BIN_TGZ" ]; then + if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then + echo "Either curl or wget is required" + exit 1 + fi fi } # getDownloadURL checks the latest available version. getDownloadURL() { + # If HELM_DIFF_BIN_TGZ is set, we don't need a download URL + if [ -n "$HELM_DIFF_BIN_TGZ" ]; then + return + fi version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :) if [ "$SCRIPT_MODE" = "install" ] && [ -n "$version" ]; then DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/$version/helm-diff-$OS-$ARCH.tgz" @@ -99,6 +99,7 @@ getDownloadURL() { mkTempDir() { HELM_TMP="$(mktemp -d -t "${PROJECT_NAME}-XXXXXX")" } + rmTempDir() { if [ -d "${HELM_TMP:-/tmp/helm-diff-tmp}" ]; then rm -rf "${HELM_TMP:-/tmp/helm-diff-tmp}" @@ -109,14 +110,22 @@ rmTempDir() { # for that binary. downloadFile() { PLUGIN_TMP_FILE="${HELM_TMP}/${PROJECT_NAME}.tgz" + + # If HELM_DIFF_BIN_TGZ is set, copy the local file instead of downloading + if [ -n "$HELM_DIFF_BIN_TGZ" ]; then + echo "Using local package at $HELM_DIFF_BIN_TGZ" + if [ ! -f "$HELM_DIFF_BIN_TGZ" ]; then + echo "Error: file not found at $HELM_DIFF_BIN_TGZ" + exit 1 + fi + cp "$HELM_DIFF_BIN_TGZ" "$PLUGIN_TMP_FILE" + return + fi + echo "Downloading $DOWNLOAD_URL" - if - command -v curl >/dev/null 2>&1 - then + if command -v curl >/dev/null 2>&1; then curl -sSf -L "$DOWNLOAD_URL" >"$PLUGIN_TMP_FILE" - elif - command -v wget >/dev/null 2>&1 - then + elif command -v wget >/dev/null 2>&1; then wget -q -O - "$DOWNLOAD_URL" >"$PLUGIN_TMP_FILE" fi } @@ -124,6 +133,7 @@ downloadFile() { # installFile verifies the SHA256 for the file, then unpacks and # installs it. installFile() { + PLUGIN_TMP_FILE="${HELM_TMP}/${PROJECT_NAME}.tgz" tar xzf "$PLUGIN_TMP_FILE" -C "$HELM_TMP" HELM_TMP_BIN="$HELM_TMP/diff/bin/diff" if [ "${OS}" = "windows" ]; then @@ -145,11 +155,11 @@ exit_trap() { exit $result } -# Execution - -#Stop execution on any error +# --- Execution --- +# Stop execution on any error trap "exit_trap" EXIT set -e + initArch initOS verifySupported @@ -157,3 +167,4 @@ getDownloadURL mkTempDir downloadFile installFile + From 387dc7a2d39a4784aa0f468ffa9c0bf57e7f7081 Mon Sep 17 00:00:00 2001 From: Matt Fletcher Date: Thu, 26 Mar 2026 11:52:43 -0500 Subject: [PATCH 2/2] remove extraneous lines --- install-binary.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/install-binary.ps1 b/install-binary.ps1 index 899b4498..6f18f409 100644 --- a/install-binary.ps1 +++ b/install-binary.ps1 @@ -59,8 +59,6 @@ $version = Get-Version -Update $Update $tmpDir = New-TemporaryDirectory trap { Remove-Item -path $tmpDir -Recurse -Force } -# --- MODIFICATION START --- - $output = Join-Path $tmpDir $archiveName # Check for offline installation via environment variable @@ -79,7 +77,5 @@ else { Download-Plugin -Url $url -Output $output } -# --- MODIFICATION END --- - Install-Plugin -ArchiveDirectory $tmpDir -ArchiveName $archiveName -Destination (Join-Path $env:HELM_PLUGIN_DIR "bin")