Skip to content

Commit d66693a

Browse files
authored
Merge pull request #51 from Aijeyomah/install-script-enhancement
Install script enhancement
2 parents fc28f2e + 17b1b9c commit d66693a

File tree

12 files changed

+244
-103
lines changed

12 files changed

+244
-103
lines changed

.github/.goreleaser.yml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,50 @@
1-
project_name: kanvas-snapshot
1+
project_name: helm-kanvas-snapshot
22
version: 2
33
before:
44
hooks:
55
- go mod tidy
66

77
builds:
8-
- main: cmd/kanvas-snapshot/main.go
9-
10-
env:
8+
- env:
119
- CGO_ENABLED=0
12-
1310
ldflags:
1411
- -s -w
15-
- -X main.providerToken={{.Env.PROVIDER_TOKEN}}
12+
- -X main.providerToken={{.Env.PROVIDER_TOKEN}}
1613
- -X main.MesheryCloudApiBaseUrl="https://meshery.layer5.io"
1714
- -X main.MesheryApiBaseUrl="https://playground.meshery.io"
18-
1915
goos:
20-
- darwin
2116
- linux
17+
- darwin
18+
- freebsd
2219
- windows
23-
2420
goarch:
25-
- 386
2621
- amd64
22+
- '386'
2723
- arm
2824
- arm64
29-
30-
ignore:
31-
- goos: windows
32-
goarch: arm
33-
- goos: windows
34-
goarch: arm64
25+
binary: '{{ .ProjectName }}'
3526

3627
archives:
37-
- id: stable
28+
- format: tar.gz
29+
wrap_in_directory: true
3830
name_template: >-
39-
{{ .ProjectName }}_{{.Version}}_
40-
{{- title .Os }}_
31+
{{- .ProjectName }}_
32+
{{- .Version }}_
33+
{{- .Os }}_
4134
{{- if eq .Arch "amd64" }}x86_64
4235
{{- else if eq .Arch "386" }}i386
4336
{{- else }}{{ .Arch }}{{ end }}
44-
format: tar.gz
45-
format_overrides:
46-
- goos: windows
47-
format: zip
48-
49-
checksum:
50-
name_template: 'checksums.txt'
37+
files:
38+
- plugin.yaml
39+
- LICENSE
40+
- install-binary.sh
5141

5242
snapshot:
53-
version_template: "{{ .Tag }}-next"
43+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Runtime.Goos }}_{{ .Runtime.Goarch }}"
44+
45+
checksum:
46+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
47+
algorithm: sha256
5448

5549
changelog:
5650
sort: asc

.github/workflows/build-and-release-snapshot-plugin.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
types: [published]
66

77
workflow_dispatch:
8+
9+
pull_request: # Add this to trigger on PR events
10+
branches:
11+
- install-script-enhancement
12+
813
jobs:
914
release:
1015
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')
@@ -20,21 +25,21 @@ jobs:
2025
uses: actions/setup-go@v5
2126
with:
2227
go-version: "1.21"
23-
24-
- name: golangci-lint
28+
29+
- name: Run golangci-lint
2530
uses: golangci/golangci-lint-action@v6
2631
with:
2732
version: v1.59
28-
working-directory: ./cmd/kanvas-snapshot
33+
working-directory: .
2934
args: --timeout 10m --verbose
3035
skip-cache: true
3136

3237
- name: Run GoReleaser with tag
3338
uses: goreleaser/goreleaser-action@v6
39+
with:
40+
version: latest # Use latest GoReleaser action version
41+
args: release --clean --skip-validate -f goreleaser.yml # Corrected filename to root
3442
env:
3543
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3644
RELEASE_CHANNEL: "stable"
3745
PROVIDER_TOKEN: ${{ secrets.PROVIDER_TOKEN }}
38-
with:
39-
version: 2
40-
args: release --clean --skip validate -f .github/.goreleaser.yml

Makefile

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
include build/Makefile.core.mk
15+
# include build/Makefile.core.mk
1616

1717

1818
.PHONY: all
1919
all: dep-check build
20-
## Lint check
20+
## Lint check
2121
golangci: error dep-check
2222
golangci-lint run --exclude-use-default
2323

@@ -29,11 +29,9 @@ error: dep-check
2929
error-util:
3030
go run github.com/layer5io/meshkit/cmd/errorutil -d . update -i ./build -o ./build
3131

32-
33-
34-
#-----------------------------------------------------------------------------
35-
# Dependencies
36-
#-----------------------------------------------------------------------------
32+
# #-----------------------------------------------------------------------------
33+
# # Dependencies
34+
# #-----------------------------------------------------------------------------
3735
.PHONY: dep-check
3836
#.SILENT: dep-check
3937

@@ -48,47 +46,66 @@ ifeq (,$(findstring $(GOVERSION), $(INSTALLED_GO_VERSION)))
4846
@echo "INSTALLED_GO_VERSION: " $(INSTALLED_GO_VERSION)
4947
endif
5048

49+
GOFMT_FILES?=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
50+
APP_NAME?=helm-kanvas-snapshot
51+
APP_DIR?=$(shell git rev-parse --show-toplevel)
52+
DEV?=${DEVBOX_TRUE}
53+
SRC_PACKAGES=$(shell go list ./... | grep -v "mocks")
54+
BUILD_ENVIRONMENT?=${ENVIRONMENT}
55+
VERSION?=0.1.0
56+
REVISION?=$(shell git rev-parse --verify HEAD)
57+
DATE?=$(shell date)
58+
PLATFORM?=$(shell go env GOOS)
59+
ARCHITECTURE?=$(shell go env GOARCH)
60+
GOVERSION?=$(shell go version | awk '{printf $$3}')
61+
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)'"
62+
63+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
64+
ifeq (,$(shell go env GOBIN))
65+
GOBIN=$(shell go env GOPATH)/bin
66+
else
67+
GOBIN=$(shell go env GOBIN)
68+
endif
69+
70+
.PHONY: help
71+
help: ## Prints help (only for targets with comments)
72+
@grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
73+
74+
local.fmt: ## Lints all the Go code in the application.
75+
@gofmt -w $(GOFMT_FILES)
76+
$(GOBIN)/goimports -w $(GOFMT_FILES)
77+
$(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
78+
$(GOBIN)/gci write $(GOFMT_FILES) --skip-generated
79+
80+
local.check: local.fmt ## Loads all dependencies
81+
@go mod tidy
82+
83+
local.build: local.check ## Generates the artifact with 'go build'
84+
@go build -o $(APP_NAME) -ldflags="-s -w"
85+
86+
local.snapshot: local.check ## Generates the artifact with 'go build'
87+
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} goreleaser build --snapshot --clean
88+
89+
local.push: local.build ## Pushes built artifact to specified location
90+
91+
local.run: local.build ## Builds the artifact and starts the service
92+
./${APP_NAME}
93+
94+
print_home:
95+
@echo ${ENVIRONMENT}
96+
97+
98+
local.deploy: local.build ## Deploys locally built Helm plugin
99+
@rm -rf ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot
100+
@cp helm-images ${HOME}/Library/helm/plugins/helm-kanvas-snapshot/bin/helm-kanvas-snapshot
101+
102+
103+
publish: local.check ## Builds and publishes the app
104+
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --snapshot --clean
105+
106+
mock.publish: local.check ## Builds and mocks app release
107+
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip=publish --clean
108+
51109

52-
OUTDIR := ./cmd/kanvas-snapshot/bin
53-
ARCH := amd64
54-
55-
BINNAME_DARWIN ?= kanvas-snapshot-darwin-$(ARCH)
56-
BINNAME_LINUX ?= kanvas-snapshot-linux-$(ARCH)
57-
BINNAME_WINDOWS ?= kanvas-snapshot-windows-$(ARCH).exe
58-
59-
60-
LDFLAGS := "\
61-
-X 'main.providerToken=$(PROVIDER_TOKEN)' \
62-
-X 'main.MesheryCloudApiBaseUrl=$(MESHERY_CLOUD_API_BASE_URL)' \
63-
-X 'main.MesheryApiBaseUrl=$(MESHERY_API_BASE_URL)'"
64-
65-
.PHONY: build
66-
build:
67-
@echo "Building for all platforms..."
68-
@$(MAKE) $(BINNAME_DARWIN)
69-
@$(MAKE) $(BINNAME_LINUX)
70-
@$(MAKE) $(BINNAME_WINDOWS)
71-
72-
# Build Helm plugin for Darwin (macOS)
73-
.PHONY: $(BINNAME_DARWIN)
74-
$(BINNAME_DARWIN):
75-
@echo "Building for Darwin..."
76-
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_DARWIN) ./cmd/kanvas-snapshot/main.go
77-
78-
# Build Helm plugin for Linux
79-
.PHONY: $(BINNAME_LINUX)
80-
$(BINNAME_LINUX):
81-
@echo "Building for Linux..."
82-
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_LINUX) ./cmd/kanvas-snapshot/main.go
83-
84-
# Build Helm plugin for Windows
85-
.PHONY: $(BINNAME_WINDOWS)
86-
$(BINNAME_WINDOWS):
87-
@echo "Building for Windows..."
88-
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/$(BINNAME_WINDOWS) ./cmd/kanvas-snapshot/main.go
89-
90-
# Clean up binaries
91-
.PHONY: clean
92-
clean:
93-
@echo "Cleaning up..."
94-
rm -rf $(OUTDIR)
110+
install.hooks: ## Installs pre-push hooks for the repository
111+
${APP_DIR}/scripts/hook.sh ${APP_DIR}

artifacthub-repo.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Artifact Hub repository metadata file
2+
#
3+
# Some settings like the verified publisher flag or the ignored packages won't
4+
# be applied until the next time the repository is processed. Please keep in
5+
# mind that the repository won't be processed if it has not changed since the
6+
# last time it was processed. Depending on the repository kind, this is checked
7+
# in a different way. For Helm http based repositories, we consider it has
8+
# changed if the `index.yaml` file changes. For git based repositories, it does
9+
# when the hash of the last commit in the branch you set up changes. This does
10+
# NOT apply to ownership claim operations, which are processed immediately.
11+
#
12+
repositoryID: 1b4e2e51-4979-43c4-a164-c26426c196b2
13+
owners: # (optional, used to claim repository ownership)
14+
- name: meshery
15+
16+
#ignore: # (optional, packages that should not be indexed by Artifact Hub)
17+
# - name: package1
18+
# - name: package2 # Exact match
19+
# version: beta # Regular expression (when omitted, all versions are ignored)

build/component_info.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "helm-kanvas-snapshot",
3+
"type": "component",
4+
"next_error_code": 1000
5+
}

cmd/kanvas-snapshot/main.go renamed to cmd/kanvas-snapshot/cmd.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"bytes"
@@ -38,7 +38,7 @@ var generateKanvasSnapshotCmd = &cobra.Command{
3838
Use: "kanvas",
3939
Short: "Generate a Kanvas snapshot using a Helm chart",
4040
Long: `Generate a Kanvas snapshot by providing a Helm chart URI.
41-
41+
4242
This command allows you to generate a snapshot in Meshery using a Helm chart.
4343
4444
Example usage:
@@ -206,7 +206,6 @@ func CreateMesheryDesign(uri, name, email string) (string, error) {
206206
}
207207

208208
func GenerateSnapshot(designID, chartURI, email, assetLocation string) error {
209-
210209
payload := map[string]interface{}{
211210
"Payload": map[string]string{
212211
"application_type": "Helm Chart",
@@ -264,8 +263,7 @@ func isValidEmail(email string) bool {
264263
return emailRegex.MatchString(email)
265264
}
266265

267-
func main() {
268-
266+
func Main() {
269267
generateKanvasSnapshotCmd.Flags().StringVarP(&chartURI, "file", "f", "", "URI to Helm chart (required)")
270268
generateKanvasSnapshotCmd.Flags().StringVarP(&designName, "design-name", "n", "", "Optional name for the Meshery design")
271269
generateKanvasSnapshotCmd.Flags().StringVarP(&email, "email", "e", "", "Optional email to associate with the Meshery design")
@@ -277,7 +275,6 @@ func main() {
277275
Log.Error(err)
278276
os.Exit(1)
279277
}
280-
281278
}
282279

283280
func init() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21.8
55
require (
66
github.com/layer5io/meshkit v0.7.78
77
github.com/sirupsen/logrus v1.9.3
8+
github.com/spf13/cobra v1.8.1
89
github.com/spf13/viper v1.19.0
910
)
1011

@@ -21,7 +22,6 @@ require (
2122
github.com/sourcegraph/conc v0.3.0 // indirect
2223
github.com/spf13/afero v1.11.0 // indirect
2324
github.com/spf13/cast v1.6.0 // indirect
24-
github.com/spf13/cobra v1.8.1 // indirect
2525
github.com/spf13/pflag v1.0.5 // indirect
2626
github.com/subosito/gotenv v1.6.0 // indirect
2727
go.uber.org/multierr v1.11.0 // indirect

helm-kanvas-snapshot

8.06 MB
Binary file not shown.

0 commit comments

Comments
 (0)