diff --git a/.github/.goreleaser.yml b/.github/.goreleaser.yml index 4e91fc1656..866e03f783 100644 --- a/.github/.goreleaser.yml +++ b/.github/.goreleaser.yml @@ -1,56 +1,50 @@ -project_name: kanvas-snapshot +project_name: helm-kanvas-snapshot version: 2 before: hooks: - go mod tidy builds: - - main: cmd/kanvas-snapshot/main.go - - env: + - env: - CGO_ENABLED=0 - ldflags: - -s -w - - -X main.providerToken={{.Env.PROVIDER_TOKEN}} + - -X main.providerToken={{.Env.PROVIDER_TOKEN}} - -X main.MesheryCloudApiBaseUrl="https://meshery.layer5.io" - -X main.MesheryApiBaseUrl="https://playground.meshery.io" - goos: - - darwin - linux + - darwin + - freebsd - windows - goarch: - - 386 - amd64 + - '386' - arm - arm64 - - ignore: - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 + binary: '{{ .ProjectName }}' archives: - - id: stable + - format: tar.gz + wrap_in_directory: true name_template: >- - {{ .ProjectName }}_{{.Version}}_ - {{- title .Os }}_ + {{- .ProjectName }}_ + {{- .Version }}_ + {{- .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} - format: tar.gz - # format_overrides: - # - goos: windows - # format: zip - -checksum: - name_template: 'checksums.txt' + files: + - plugin.yaml + - LICENSE + - install-binary.sh snapshot: - version_template: "{{ .Tag }}-next" + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Runtime.Goos }}_{{ .Runtime.Goarch }}" + +checksum: + name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + algorithm: sha256 changelog: sort: asc diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 5bab64554f..a1a28a3271 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,4 +1,4 @@ -name-template: 'Meshery v$NEXT_PATCH_VERSION' +name-template: 'Helm Kanvas Snapshot v$NEXT_PATCH_VERSION' tag-template: 'v$NEXT_PATCH_VERSION' categories: - title: '🚀 Features' diff --git a/.github/workflows/build-and-release-snapshot-plugin.yml b/.github/workflows/build-and-release-snapshot-plugin.yml index 1d0ac77840..ed9e2636c9 100644 --- a/.github/workflows/build-and-release-snapshot-plugin.yml +++ b/.github/workflows/build-and-release-snapshot-plugin.yml @@ -5,11 +5,11 @@ on: types: [published] workflow_dispatch: - inputs: - branch: - description: "Branch to deploy in the staging environment. If not provided, master branch of the repository will be used." - default: "master" - type: string + + pull_request: # Add this to trigger on PR events + branches: + - install-script-enhancement + jobs: release: if: github.repository == 'meshery/helm-kanvas-snapshot' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'patch') && !contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') @@ -26,21 +26,21 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.21" - - - name: golangci-lint + + - name: Run golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.59 - working-directory: ./cmd/kanvas-snapshot + working-directory: . args: --timeout 10m --verbose skip-cache: true - name: Run GoReleaser with tag uses: goreleaser/goreleaser-action@v6 + with: + version: latest # Use latest GoReleaser action version + args: release --clean --skip-validate -f goreleaser.yml # Corrected filename to root env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_CHANNEL: "stable" PROVIDER_TOKEN: ${{ secrets.PROVIDER_TOKEN }} - with: - version: 2 - args: release --clean --skip validate -f .github/.goreleaser.yml diff --git a/.github/workflows/error-codes-updater.yaml b/.github/workflows/error-codes-updater.yaml index 132ba0ffc5..f283a0284c 100644 --- a/.github/workflows/error-codes-updater.yaml +++ b/.github/workflows/error-codes-updater.yaml @@ -39,13 +39,12 @@ jobs: - name: Run Utility For Plugin run: | - cd ./cmd ~/errorutil update -d . -i ./helpers -o ./helpers output=$(~/errorutil -d . analyze -i ./helpers -o ./helpers | wc -c) if [ "$output" -ne 0 ]; then exit 1 fi - echo '{ "errors_export": "" }' | jq --slurpfile export ../server/helpers/errorutil_errors_export.json '.errors_export = $export[0]' > ../docs/_data/errorref/mesheryctl_errors_export.json + echo '{ "errors_export": "" }' | jq --slurpfile export ./helpers/errorutil_errors_export.json '.errors_export = $export[0]' > ./helpers/errorutil_errors_export.json - name: Pull changes from remote run: git pull origin master @@ -54,7 +53,7 @@ jobs: if: ${{ github.event_name != 'pull_request' }} # Skip for pull requests uses: stefanzweifel/git-auto-commit-action@v5 with: - file_pattern: mesheryctl/helpers server/helpers/ **.go docs/ + file_pattern: helpers commit_user_name: l5io commit_user_email: ci@layer5.io commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> diff --git a/Makefile b/Makefile index 9288ead354..289d5fa46f 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -include build/Makefile.core.mk +# include build/Makefile.core.mk .PHONY: all all: dep-check build -## Lint check +## Lint check golangci: error dep-check golangci-lint run --exclude-use-default @@ -29,11 +29,9 @@ error: dep-check error-util: go run github.com/layer5io/meshkit/cmd/errorutil -d . update -i ./build -o ./build - - -#----------------------------------------------------------------------------- -# Dependencies -#----------------------------------------------------------------------------- +# #----------------------------------------------------------------------------- +# # Dependencies +# #----------------------------------------------------------------------------- .PHONY: dep-check #.SILENT: dep-check @@ -48,47 +46,66 @@ ifeq (,$(findstring $(GOVERSION), $(INSTALLED_GO_VERSION))) @echo "INSTALLED_GO_VERSION: " $(INSTALLED_GO_VERSION) endif +GOFMT_FILES?=$(shell find . -type f -name '*.go' -not -path "./vendor/*") +APP_NAME?=helm-kanvas-snapshot +APP_DIR?=$(shell git rev-parse --show-toplevel) +DEV?=${DEVBOX_TRUE} +SRC_PACKAGES=$(shell go list ./... | grep -v "mocks") +BUILD_ENVIRONMENT?=${ENVIRONMENT} +VERSION?=0.1.0 +REVISION?=$(shell git rev-parse --verify HEAD) +DATE?=$(shell date) +PLATFORM?=$(shell go env GOOS) +ARCHITECTURE?=$(shell go env GOARCH) +GOVERSION?=$(shell go version | awk '{printf $$3}') +BUILD_WITH_FLAGS="-s -w -X 'github.com/meshery/helm-kanvas-snapshot/version.Version=${VERSION}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Env=${BUILD_ENVIRONMENT}' -X 'github.com/meshery/helm-kanvas-snapshot/version.BuildDate=${DATE}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Revision=${REVISION}' -X 'github.com/meshery/helm-kanvas-snapshot/version.Platform=${PLATFORM}/${ARCHITECTURE}' -X 'github.com/meshery/helm-kanvas-snapshot/version.GoVersion=${GOVERSION}' -X 'main.providerToken=$(PROVIDER_TOKEN)' -X 'main.MesheryCloudApiBaseUrl=$(MESHERY_CLOUD_API_BASE_URL)' -X 'main.MesheryApiBaseUrl=$(MESHERY_API_BASE_URL)'" + +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN=$(shell go env GOPATH)/bin +else +GOBIN=$(shell go env GOBIN) +endif + +.PHONY: help +help: ## Prints help (only for targets with comments) + @grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +local.fmt: ## Lints all the Go code in the application. + @gofmt -w $(GOFMT_FILES) + $(GOBIN)/goimports -w $(GOFMT_FILES) + $(GOBIN)/gofumpt -l -w $(GOFMT_FILES) + $(GOBIN)/gci write $(GOFMT_FILES) --skip-generated + +local.check: local.fmt ## Loads all dependencies + @go mod tidy + +local.build: local.check ## Generates the artifact with 'go build' + @go build -o $(APP_NAME) -ldflags="-s -w" + +local.snapshot: local.check ## Generates the artifact with 'go build' + GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} goreleaser build --snapshot --clean + +local.push: local.build ## Pushes built artifact to specified location + +local.run: local.build ## Builds the artifact and starts the service + ./${APP_NAME} + +print_home: + @echo ${ENVIRONMENT} + + +local.deploy: local.build ## Deploys locally built Helm plugin + @rm -rf ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot + @cp helm-images ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot + + +publish: local.check ## Builds and publishes the app + GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --snapshot --clean + +mock.publish: local.check ## Builds and mocks app release + GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip=publish --clean + -OUTDIR := ./cmd/kanvas-snapshot/bin -ARCH := amd64 - -BINNAME_DARWIN ?= kanvas-snapshot-darwin-$(ARCH) -BINNAME_LINUX ?= kanvas-snapshot-linux-$(ARCH) -BINNAME_WINDOWS ?= kanvas-snapshot-windows-$(ARCH).exe - - -LDFLAGS := "\ - -X 'main.providerToken=$(PROVIDER_TOKEN)' \ - -X 'main.MesheryCloudApiBaseUrl=$(MESHERY_CLOUD_API_BASE_URL)' \ - -X 'main.MesheryApiBaseUrl=$(MESHERY_API_BASE_URL)'" - -.PHONY: build -build: - @echo "Building for all platforms..." - @$(MAKE) $(BINNAME_DARWIN) - @$(MAKE) $(BINNAME_LINUX) - @$(MAKE) $(BINNAME_WINDOWS) - -# Build Helm plugin for Darwin (macOS) -.PHONY: $(BINNAME_DARWIN) -$(BINNAME_DARWIN): - @echo "Building for Darwin..." - CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_DARWIN) ./cmd/kanvas-snapshot/main.go - -# Build Helm plugin for Linux -.PHONY: $(BINNAME_LINUX) -$(BINNAME_LINUX): - @echo "Building for Linux..." - CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_LINUX) ./cmd/kanvas-snapshot/main.go - -# Build Helm plugin for Windows -.PHONY: $(BINNAME_WINDOWS) -$(BINNAME_WINDOWS): - @echo "Building for Windows..." - CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_WINDOWS) ./cmd/kanvas-snapshot/main.go - -# Clean up binaries -.PHONY: clean -clean: - @echo "Cleaning up..." - rm -rf $(OUTDIR) +install.hooks: ## Installs pre-push hooks for the repository + ${APP_DIR}/scripts/hook.sh ${APP_DIR} diff --git a/artifacthub-repo.yml b/artifacthub-repo.yml new file mode 100644 index 0000000000..00691b697e --- /dev/null +++ b/artifacthub-repo.yml @@ -0,0 +1,19 @@ +# Artifact Hub repository metadata file +# +# Some settings like the verified publisher flag or the ignored packages won't +# be applied until the next time the repository is processed. Please keep in +# mind that the repository won't be processed if it has not changed since the +# last time it was processed. Depending on the repository kind, this is checked +# in a different way. For Helm http based repositories, we consider it has +# changed if the `index.yaml` file changes. For git based repositories, it does +# when the hash of the last commit in the branch you set up changes. This does +# NOT apply to ownership claim operations, which are processed immediately. +# +repositoryID: 1b4e2e51-4979-43c4-a164-c26426c196b2 +owners: # (optional, used to claim repository ownership) + - name: meshery + email: maintainers@meshery.io +#ignore: # (optional, packages that should not be indexed by Artifact Hub) +# - name: package1 +# - name: package2 # Exact match +# version: beta # Regular expression (when omitted, all versions are ignored) \ No newline at end of file diff --git a/build/component_info.json b/build/component_info.json index 7a79de0273..17b71b91fe 100644 --- a/build/component_info.json +++ b/build/component_info.json @@ -1,5 +1,5 @@ { - "name": "kanvas-snapshot", + "name": "helm-kanvas-snapshot", "type": "component", - "next_error_code": 1006 -} \ No newline at end of file + "next_error_code": 1000 +} diff --git a/cmd/kanvas-snapshot/main.go b/cmd/kanvas-snapshot/cmd.go similarity index 94% rename from cmd/kanvas-snapshot/main.go rename to cmd/kanvas-snapshot/cmd.go index fcfea0b04b..ddc2df000a 100644 --- a/cmd/kanvas-snapshot/main.go +++ b/cmd/kanvas-snapshot/cmd.go @@ -1,4 +1,4 @@ -package main +package cmd import ( "bytes" @@ -9,6 +9,7 @@ import ( "net/url" "os" "path/filepath" + "regexp" "strings" "time" @@ -31,11 +32,13 @@ var ( designName string ) +var emailRegex = regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,}$`) + var generateKanvasSnapshotCmd = &cobra.Command{ Use: "kanvas", Short: "Generate a Kanvas snapshot using a Helm chart", Long: `Generate a Kanvas snapshot by providing a Helm chart URI. - + This command allows you to generate a snapshot in Meshery using a Helm chart. Example usage: @@ -45,17 +48,18 @@ var generateKanvasSnapshotCmd = &cobra.Command{ Flags: -f, --file string URI to Helm chart (required) -n, --name string (optional name for the Meshery design - -e, --email string (optional) email address to notify when snapshot is ready + -e, --email string email address to notify when snapshot is ready (required) -h Help for Helm Kanvas Snapshot plugin`, RunE: func(cmd *cobra.Command, args []string) error { - Log = log.SetupMeshkitLogger("helm-kanvas-snapshot", false, os.Stdout) // Use the extracted name from URI if not provided if designName == "" { designName = ExtractNameFromURI(chartURI) Log.Warnf("No design name provided. Using extracted name: %s", designName) } - + if email != "" && !isValidEmail(email) { + handleError(errors.ErrInvalidEmailFormat(email)) + } // Create Meshery Snapshot designID, err := CreateMesheryDesign(chartURI, designName, email) if err != nil { @@ -202,7 +206,6 @@ func CreateMesheryDesign(uri, name, email string) (string, error) { } func GenerateSnapshot(designID, chartURI, email, assetLocation string) error { - payload := map[string]interface{}{ "Payload": map[string]string{ "application_type": "Helm Chart", @@ -256,8 +259,11 @@ func GenerateSnapshot(designID, chartURI, email, assetLocation string) error { return nil } -func main() { +func isValidEmail(email string) bool { + return emailRegex.MatchString(email) +} +func Main() { generateKanvasSnapshotCmd.Flags().StringVarP(&chartURI, "file", "f", "", "URI to Helm chart (required)") generateKanvasSnapshotCmd.Flags().StringVarP(&designName, "design-name", "n", "", "Optional name for the Meshery design") generateKanvasSnapshotCmd.Flags().StringVarP(&email, "email", "e", "", "Optional email to associate with the Meshery design") @@ -269,5 +275,10 @@ func main() { Log.Error(err) os.Exit(1) } +} +func init() { + cobra.OnInitialize(func() { + Log = log.SetupMeshkitLogger("helm-kanvas-snapshot", false, os.Stdout) + }) } diff --git a/go.mod b/go.mod index a61a694817..eeacfa263a 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/meshery/helm-kanvas-snapshot go 1.21.8 require ( - github.com/layer5io/meshkit v0.7.78 + github.com/layer5io/meshkit v0.7.84 github.com/sirupsen/logrus v1.9.3 + github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 ) @@ -21,7 +22,6 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect - github.com/spf13/cobra v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -30,5 +30,5 @@ require ( golang.org/x/text v0.16.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/gorm v1.25.11 // indirect + gorm.io/gorm v1.25.12 // indirect ) diff --git a/go.sum b/go.sum index f87fa4889e..0213abdbe8 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/layer5io/meshkit v0.7.78 h1:zjYRLvM+X9nLqkYtsReCKLuG5Jc9cEPC8WWSp3DwYQw= -github.com/layer5io/meshkit v0.7.78/go.mod h1:fK7eqynmZm/2+JSOIM/UIfPt4KfwzM8C3HPlNd67iRo= +github.com/layer5io/meshkit v0.7.84 h1:BGedXw44ns+7+eiSST8zkEo0l4hJsbdaXV09IWcszvk= +github.com/layer5io/meshkit v0.7.84/go.mod h1:Yvcd6dKXqw05lmlYjH1cTq83Gh6T2/3XGyCO1X9k5js= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -82,5 +82,5 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= -gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= diff --git a/helm-kanvas-snapshot b/helm-kanvas-snapshot new file mode 100755 index 0000000000..b3c332405b Binary files /dev/null and b/helm-kanvas-snapshot differ diff --git a/build/Makefile.core.mk b/helpers/Makefile.core.mk similarity index 100% rename from build/Makefile.core.mk rename to helpers/Makefile.core.mk diff --git a/helpers/component_info.json b/helpers/component_info.json new file mode 100644 index 0000000000..7a79de0273 --- /dev/null +++ b/helpers/component_info.json @@ -0,0 +1,5 @@ +{ + "name": "kanvas-snapshot", + "type": "component", + "next_error_code": 1006 +} \ No newline at end of file diff --git a/install-binary.sh b/install-binary.sh new file mode 100644 index 0000000000..4fe7c5f0fc --- /dev/null +++ b/install-binary.sh @@ -0,0 +1,100 @@ +#! /bin/bash -e + +function handle_exit() { + result=$? + if [ "$result" != "0" ]; then + printf "Failed to install helm-kanvas-snapshot plugin\n" + fi + exit $result +} + +function normalize_architecture() { + arch=$1 + + case "$arch" in + "aarch64") + echo "arm64" + ;; + *) + echo $arch + ;; + 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 + 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}" +} + +function install() { + echo "Installing helm-kanvas-snapshot..." + + download_plugin + status=$? + if [ $status -ne 0 ]; then + echo -e "Downloading plugin failed\n" + exit 1 + fi + + set +e + install_plugin + local install_status=$? + set -e + + if [ "$install_status" != "0" ]; then + echo "Installing helm-kanvas-snapshot plugin failed with error code: ${install_status}" + exit 1 + fi + + 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." +} + +trap "handle_exit" EXIT + +install "$@" diff --git a/internal/errors/error.go b/internal/errors/error.go index 7338417035..19cbba28bb 100644 --- a/internal/errors/error.go +++ b/internal/errors/error.go @@ -7,12 +7,14 @@ import ( ) var ( - ErrInvalidChartURICode = "kanvas-snapshot-900" - ErrCreatingMesheryDesignCode = "kanvas-snapshot-901" - ErrGeneratingSnapshotCode = "kanvas-snapshot-902" - ErrHTTPPostRequestCode = "kanvas-snapshot-903" - ErrDecodingAPICode = "kanvas-snapshot-905" - ErrUnexpectedResponseCodeCode = "kanvas-snapshot-906" + ErrInvalidChartURICode = "kanvas-snapshot-900" + ErrCreatingMesheryDesignCode = "kanvas-snapshot-901" + ErrGeneratingSnapshotCode = "kanvas-snapshot-902" + ErrHTTPPostRequestCode = "kanvas-snapshot-903" + ErrDecodingAPICode = "kanvas-snapshot-905" + ErrUnexpectedResponseCodeCode = "kanvas-snapshot-906" + ErrRequiredFieldNotProvidedCode = "kanvas-snapshot-907" + ErrInvalidEmailFormatCode = "kanvas-snapshot-908" ) func ErrInvalidChartURI(err error) error { @@ -68,3 +70,21 @@ func ErrUnexpectedResponseCode(statusCode int, body string) error { []string{"Check the request details and ensure the Meshery API is functioning correctly."}, ) } + +func ErrRequiredFieldNotProvided(err error, field string) error { + return errors.New(ErrRequiredFieldNotProvidedCode, errors.Alert, + []string{"All required flags are not passed."}, + []string{err.Error()}, + []string{"Required flag \"%s\" is not passed."}, + []string{"Ensure value for flag \"%s\" is correctly provided."}, + ) +} + +func ErrInvalidEmailFormat(email string) error { + return errors.New(ErrInvalidEmailFormatCode, errors.Alert, + []string{"Invalid email format provided."}, + []string{fmt.Sprintf("The provided email '%s' is not a valid email format.", email)}, + []string{"The email provided for the Kanvas snapshot request is not in the correct format."}, + []string{"Ensure the email address follows the correct format (e.g., user@example.com)."}, + ) +} diff --git a/internal/log/logger.go b/internal/log/logger.go index 42a96f0d61..129904dabe 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -20,7 +20,7 @@ func (f *TerminalFormatter) Format(entry *log.Entry) ([]byte, error) { // Call this function to setup logrus func SetupLogrusFormatter() { - //log formatter for improved UX + // log formatter for improved UX log.SetFormatter(new(TerminalFormatter)) } diff --git a/main.go b/main.go new file mode 100644 index 0000000000..ea24cb7621 --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + cmd "github.com/meshery/helm-kanvas-snapshot/cmd/kanvas-snapshot" +) + +func main() { + cmd.Main() +} diff --git a/plugin.yaml b/plugin.yaml index d8170ac955..c0b0b9c338 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,19 +1,14 @@ -name: "kanvas-snapshot" +name: "helm-kanvas-snapshot" version: "0.2.0" -usage: "Generate a visual snapshot of your Helm chart as a Meshery Snapshot" -description: "A Helm plugin to generate Kanvas Snapshots from Helm charts using a custom Go binary" -command: "$HELM_PLUGIN_DIR/bin/kanvas-snapshot" -platformCommand: - - os: linux - arch: amd64 - command: "$HELM_PLUGIN_DIR/bin/kanvas-snapshot" - - os: darwin - arch: amd64 - command: "$HELM_PLUGIN_DIR/bin/kanvas-snapshot" - - os: windows - arch: amd64 - command: "$HELM_PLUGIN_DIR/bin/kanvas-snapshot.exe" +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 +command: "$HELM_PLUGIN_DIR/bin/helm-kanvas-snapshot" hooks: - install: "$HELM_PLUGIN_DIR/scripts/install-binary.sh" - update: "$HELM_PLUGIN_DIR/scripts/install-binary.sh" - uninstall: echo "Snapshot plugin uninstalled." + install: | + echo "Snapshot plugin installed." + update: | + echo "Snapshot plugin updated." + $HELM_PLUGIN_DIR/install-binary.sh + uninstall: | + echo "Snapshot plugin uninstalled."