Skip to content

Commit

Permalink
Merge pull request #51 from Aijeyomah/install-script-enhancement
Browse files Browse the repository at this point in the history
Install script enhancement
  • Loading branch information
leecalcote authored Nov 5, 2024
2 parents fc28f2e + 17b1b9c commit d66693a
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 103 deletions.
48 changes: 21 additions & 27 deletions .github/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/build-and-release-snapshot-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
types: [published]

workflow_dispatch:

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')
Expand All @@ -20,21 +25,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
117 changes: 67 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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}
19 changes: 19 additions & 0 deletions artifacthub-repo.yml
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions build/component_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "helm-kanvas-snapshot",
"type": "component",
"next_error_code": 1000
}
9 changes: 3 additions & 6 deletions cmd/kanvas-snapshot/main.go → cmd/kanvas-snapshot/cmd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"bytes"
Expand Down Expand Up @@ -38,7 +38,7 @@ 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:
Expand Down Expand Up @@ -206,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",
Expand Down Expand Up @@ -264,8 +263,7 @@ func isValidEmail(email string) bool {
return emailRegex.MatchString(email)
}

func main() {

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")
Expand All @@ -277,7 +275,6 @@ func main() {
Log.Error(err)
os.Exit(1)
}

}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.8
require (
github.com/layer5io/meshkit v0.7.78
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
)

Expand All @@ -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
Expand Down
Binary file added helm-kanvas-snapshot
Binary file not shown.
Loading

0 comments on commit d66693a

Please sign in to comment.