From 9b2ccc74839068d2f69200f79634c0397d91127a Mon Sep 17 00:00:00 2001 From: Pranav Singh Date: Sat, 23 Nov 2024 15:39:34 +0530 Subject: [PATCH 1/3] fix plugin version Signed-off-by: Pranav Singh --- plugin.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yaml b/plugin.yaml index 63fbb225f1..455d5cb0f3 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "helm-kanvas-snapshot" -version: "0.2.0" +version: "0.3.7" usage: "Generate a visual snapshot of your Helm chart as a Meshery Design" description: "A Helm plugin to generate Meshery designs from Helm charts and snapshot their visual representation." useTunnel: true From 7b229ceb012d1942f6ad8e0fcea22af29fbf69cc Mon Sep 17 00:00:00 2001 From: Pranav Singh Date: Sat, 23 Nov 2024 15:39:51 +0530 Subject: [PATCH 2/3] fix install script Signed-off-by: Pranav Singh --- install-binary.sh | 216 ++++++++++++++++++++++++++++------------------ 1 file changed, 133 insertions(+), 83 deletions(-) diff --git a/install-binary.sh b/install-binary.sh index 4fe7c5f0fc..c247fa4951 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -1,100 +1,150 @@ -#! /bin/bash -e - -function handle_exit() { - result=$? - if [ "$result" != "0" ]; then - printf "Failed to install helm-kanvas-snapshot plugin\n" - fi - exit $result +#!/usr/bin/env bash + +PROJECT_NAME="helm-kanvas-snapshot" +PROJECT_GH="meshery/$PROJECT_NAME" + +# Convert the HELM_PLUGIN_PATH to unix if cygpath is +# 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/$PROJECT_NAME"}" + +if [ "$SKIP_BIN_INSTALL" = "1" ]; then + echo "Skipping binary install" + exit +fi + + +# initArch discovers the architecture for this system. +initArch() { + ARCH=$(uname -m) + case $ARCH in + armv5*) ARCH="arm";; + armv6*) ARCH="arm";; + armv7*) ARCH="arm";; + aarch64) ARCH="arm64";; + x86) ARCH="386";; + x86_64) ARCH="x86_64";; + i686) ARCH="i386";; + i386) ARCH="i386";; + esac } -function normalize_architecture() { - arch=$1 - - case "$arch" in - "aarch64") - echo "arm64" - ;; - *) - echo $arch - ;; - esac +# initOS discovers the operating system for this system. +initOS() { + OS=$(uname -s) + + case "$OS" in + Windows_NT) OS='windows' ;; + # Msys support + MSYS*) OS='windows' ;; + # Minimalist GNU for Windows + MINGW*) OS='windows' ;; + CYGWIN*) OS='windows' ;; + Darwin) OS='darwin' ;; + Linux) OS='linux' ;; + esac } -function download_plugin() { - OUTPUT_BASENAME=helm-kanvas-snapshot - - if [[ -n "$LOCAL_FILE_PATH" ]]; then - OUTPUT_BASENAME_WITH_POSTFIX="$LOCAL_FILE_PATH" - echo -e "Using local archive at ${OUTPUT_BASENAME_WITH_POSTFIX}\n" - else - version=$(grep version "$HELM_PLUGIN_DIR/plugin.yaml" | cut -d'"' -f2) - DOWNLOAD_URL="https://github.com/meshery/helm-kanvas-snapshot/releases/download/v$version/helm-kanvas-snapshot_${version}_${os_name}_${os_arch}.tar.gz" - OUTPUT_BASENAME_WITH_POSTFIX="$HELM_PLUGIN_DIR/$OUTPUT_BASENAME.tar.gz" - - echo -e "Download URL set to ${DOWNLOAD_URL}\n" - echo -e "Artifact path: ${OUTPUT_BASENAME_WITH_POSTFIX}\n" - - if [[ -n $(command -v curl) ]]; then - if curl --fail -L "${DOWNLOAD_URL}" -o "${OUTPUT_BASENAME_WITH_POSTFIX}"; then - echo -e "Successfully downloaded the archive, proceeding to install\n" - else - echo -e "Failed while downloading helm-kanvas-snapshot archive\n" - exit 1 - fi - else - echo "curl is required to download the plugin" - exit -1 - fi +# verifySupported checks that the os/arch combination is supported for +# binary builds. +verifySupported() { + local supported="" + for os in darwin freebsd linux windows; do + for arch in arm arm64 i386 x86_64 386 amd64; do + supported+="${os}-${arch}\n" + done + done + echo "supported: ${supported[@]}" + if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then + echo "No prebuild binary for ${OS}-${ARCH}." + exit 1 fi -} - - -function install_plugin() { - local HELM_PLUGIN_ARTIFACT_PATH=${OUTPUT_BASENAME_WITH_POSTFIX} - local PROJECT_NAME="helm-kanvas-snapshot" - local HELM_PLUGIN_TEMP_PATH="/tmp/$PROJECT_NAME" - echo -n "HELM_PLUGIN_ARTIFACT_PATH: ${HELM_PLUGIN_ARTIFACT_PATH}" - rm -rf "${HELM_PLUGIN_TEMP_PATH}" - - echo -e "Preparing to install into ${HELM_PLUGIN_DIR}\n" - mkdir -p "${HELM_PLUGIN_TEMP_PATH}" - tar -xvf "${HELM_PLUGIN_ARTIFACT_PATH}" -C "${HELM_PLUGIN_TEMP_PATH}" - mkdir -p "$HELM_PLUGIN_DIR/bin" - mv "${HELM_PLUGIN_TEMP_PATH}/helm-kanvas-snapshot" "${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot" - rm -rf "${HELM_PLUGIN_TEMP_PATH}" - rm -rf "${HELM_PLUGIN_ARTIFACT_PATH}" + if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then + echo "Either curl or wget is required" + exit 1 + fi } -function install() { - echo "Installing helm-kanvas-snapshot..." - - download_plugin - status=$? - if [ $status -ne 0 ]; then - echo -e "Downloading plugin failed\n" +# getDownloadURL checks the latest available version. +getDownloadURL() { + version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --abbrev=0 2> /dev/null) + # remove the 'v' at the beginning of the version + version_without_v=$(git -C "$HELM_PLUGIN_DIR" describe --tags --abbrev=0 2> /dev/null | sed 's/^v//') + PROJECT_NAME_WITH_VERSION="${PROJECT_NAME}_${version_without_v}_${OS}_${ARCH}" + if [ -n "$version" ]; then + DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/$version/$PROJECT_NAME_WITH_VERSION.tar.gz" + else + echo "No release found. " exit 1 fi +} - set +e - install_plugin - local install_status=$? - set -e +# downloadFile downloads the latest binary package and also the checksum +# for that binary. +downloadFile() { + PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tar.gz" + echo "Downloading $DOWNLOAD_URL" + if type "curl" > /dev/null; then + echo "curl -L $DOWNLOAD_URL -o $PLUGIN_TMP_FILE" + curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE" + elif type "wget" > /dev/null; then + echo "wget -q -O $PLUGIN_TMP_FILE $DOWNLOAD_URL" + wget -q -O "$PLUGIN_TMP_FILE" "$DOWNLOAD_URL" + fi +} - if [ "$install_status" != "0" ]; then - echo "Installing helm-kanvas-snapshot plugin failed with error code: ${install_status}" - exit 1 +# installFile verifies the SHA256 for the file, then unpacks and +# installs it. +installFile() { + HELM_TMP="/tmp/$PROJECT_NAME" + HELM_TMP_BIN="/tmp/$PROJECT_NAME/$PROJECT_NAME_WITH_VERSION/$PROJECT_NAME" + mkdir -p "$HELM_TMP" + tar xzf "$PLUGIN_TMP_FILE" -C "$HELM_TMP" + if [ "${OS}" = "windows" ]; then + HELM_TMP_BIN="$HELM_TMP_BIN.exe" fi + echo "Preparing to install into ${HELM_PLUGIN_DIR}" + mkdir -p "$HELM_PLUGIN_DIR/bin" + cp "$HELM_TMP_BIN" "$HELM_PLUGIN_DIR/bin" +} - echo - echo "helm-kanvas-snapshot is installed." - echo - "${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot" -h - echo - echo "See https://github.com/meshery/helm-kanvas-snapshot#readme for more information on getting started." +# fail_trap is executed if an error occurs. +fail_trap() { + result=$? + if [ "$result" != "0" ]; then + echo "Failed to install $PROJECT_NAME" + echo "\tFor support, open issue at https://github.com/$PROJECT_GH." + fi + exit $result } -trap "handle_exit" EXIT +# Execution + +#Stop execution on any error +trap "fail_trap" EXIT +set -e +initArch +initOS +verifySupported +getDownloadURL +downloadFile +installFile +echo +echo "helm-kanvas-snapshot is installed." +echo "${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot" -h +echo +echo "See https://github.com/$PROJECT_GH#readme for more information on getting started." -install "$@" From 331a41a8da28cf7e86fb155dfc3df583c98075fc Mon Sep 17 00:00:00 2001 From: Pranav Singh Date: Sat, 23 Nov 2024 15:53:45 +0530 Subject: [PATCH 3/3] fix logs; add update support Signed-off-by: Pranav Singh --- install-binary.sh | 7 +------ plugin.yaml | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/install-binary.sh b/install-binary.sh index c247fa4951..0058013e19 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -25,7 +25,6 @@ if [ "$SKIP_BIN_INSTALL" = "1" ]; then exit fi - # initArch discovers the architecture for this system. initArch() { ARCH=$(uname -m) @@ -66,7 +65,6 @@ verifySupported() { supported+="${os}-${arch}\n" done done - echo "supported: ${supported[@]}" if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then echo "No prebuild binary for ${OS}-${ARCH}." exit 1 @@ -98,10 +96,8 @@ downloadFile() { PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tar.gz" echo "Downloading $DOWNLOAD_URL" if type "curl" > /dev/null; then - echo "curl -L $DOWNLOAD_URL -o $PLUGIN_TMP_FILE" curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE" elif type "wget" > /dev/null; then - echo "wget -q -O $PLUGIN_TMP_FILE $DOWNLOAD_URL" wget -q -O "$PLUGIN_TMP_FILE" "$DOWNLOAD_URL" fi } @@ -143,8 +139,7 @@ getDownloadURL downloadFile installFile echo -echo "helm-kanvas-snapshot is installed." -echo "${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot" -h +echo "helm-kanvas-snapshot is installed at ${HELM_PLUGIN_DIR}/bin/helm-kanvas-snapshot" echo echo "See https://github.com/$PROJECT_GH#readme for more information on getting started." diff --git a/plugin.yaml b/plugin.yaml index 455d5cb0f3..67965cd6ef 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -6,9 +6,8 @@ useTunnel: true command: "$HELM_PLUGIN_DIR/bin/helm-kanvas-snapshot" hooks: install: | - echo "Snapshot plugin installed." $HELM_PLUGIN_DIR/install-binary.sh update: | - echo "Snapshot plugin updated." + $HELM_PLUGIN_DIR/install-binary.sh uninstall: | echo "Snapshot plugin uninstalled."