-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating documentation * Cleaning up gdg-template ChangeLog: - Refactoring GDG template tool - Refactoring GDG CLI tool * Additional documentation prepping for the v0.6.0 release.
- Loading branch information
1 parent
0e945da
commit 09e5db5
Showing
32 changed files
with
629 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ version: "3" | |
|
||
vars: | ||
BIN_NAME: gdg | ||
VERSION : { sh: grep "const Version " internal/version/version.go | sed -E 's/.*"(.+)"$$/\1/' } | ||
VERSION: { sh: grep "const Version " internal/version/version.go | sed -E 's/.*"(.+)"$$/\1/' } | ||
GIT_COMMIT: { sh: git rev-parse HEAD } | ||
GIT_DIRTY: { sh: test -n "`git status --porcelain`" && echo "+CHANGES" || true } | ||
BUILD_DATE: { sh: date '+%Y-%m-%d-%H:%M:%S' } | ||
IMAGE_NAME: "esnet/gdg" | ||
LD_FLAGS: "-s -w -X github.com/esnet/gdg/internal/version.GitCommit={{ .GIT_COMMIT}}{{ .GIT_DIRTY}} -X github.com/esnet/gdg/internal/version.BuildDate={{ .BUILD_DATE }} " | ||
|
||
dotenv: ['.env'] | ||
dotenv: [ '.env' ] | ||
|
||
tasks: | ||
default: | ||
|
@@ -23,100 +23,100 @@ tasks: | |
- go install github.com/securego/gosec/v2/cmd/gosec@master | ||
- go install golang.org/x/vuln/cmd/govulncheck@latest | ||
- go install github.com/vektra/mockery/[email protected] | ||
|
||
- go install github.com/goreleaser/[email protected] | ||
security: | ||
desc: "Run security scan" | ||
cmds: | ||
- gosec --exclude=G402,G304 ./... | ||
lint: | ||
desc: "Lint project, skipping test files." | ||
cmds: | ||
- golangci-lint run --timeout=30m --skip-dirs "(^|/)test($|/)" --skip-files "_test.go" ./... | ||
- golangci-lint run --timeout=30m --skip-dirs "(^|/)test($|/)" --skip-files "_test.go" ./... | ||
spellcheck: | ||
desc: "Check Spelling across code" | ||
cmds: | ||
- misspell . | grep -v "website" | ||
- misspell . | grep -v "website" | ||
lint_tests: | ||
desc: "Lint project, including test files." | ||
cmds: | ||
- golangci-lint run ./... | ||
- golangci-lint run ./... | ||
authors: | ||
desc: "Building GDG" | ||
cmds: | ||
- echo "Authors\n=======\n" > AUTHORS.md | ||
- "git log --raw | grep \"^Author: \" | sort | uniq | cut -d ' ' -f2 | sed 's/^/- /' >> AUTHORS.md" | ||
silent: false | ||
mocks: | ||
mocks: | ||
desc: "Re-generate Mocks" | ||
cmds: | ||
- rm -fr internal/service/mocks | ||
- mockery | ||
- mockery | ||
linux: | ||
desc: "Build linux binary" | ||
cmds: | ||
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go | ||
- env GOOS='linux' GOARCH='amd64' go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}_linux cmd/gdg/main.go | ||
build_all: | ||
desc: "Buiding All binaries" | ||
desc: "Buiding All binaries" | ||
cmds: | ||
- task: build | ||
- task: build_generate | ||
build: | ||
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}" | ||
desc: "Buiding {{ .BIN_NAME }} {{ .VERSION }}" | ||
cmds: | ||
- echo "GOPATH=${GOPATH}" | ||
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }} cmd/gdg/main.go | ||
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }} cmd/gdg/main.go | ||
build_generate: | ||
desc: "Buiding {{ .BIN_NAME }}-generate {{ .VERSION }}" | ||
desc: "Buiding {{ .BIN_NAME }}-generate {{ .VERSION }}" | ||
cmds: | ||
- echo "GOPATH=${GOPATH}" | ||
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}-generate cmd/gdg-generate/main.go | ||
install: | ||
desc: "installing {{ .BIN_NAME }} {{ .VERSION }}" | ||
cmds: | ||
- go build -ldflags "{{ .LD_FLAGS }}" -o bin/{{ .BIN_NAME }}-generate cmd/gdg-generate/main.go | ||
install: | ||
desc: "installing {{ .BIN_NAME }} {{ .VERSION }}" | ||
cmds: | ||
- echo "GOPATH=${GOPATH}" | ||
- go install -ldflags "{{ .LD_FLAGS}}" cmd/gdg/main.go | ||
silent: false | ||
push: | ||
push: | ||
desc: "Pushing docker image to registry: latest {{ .VERSION }} {{ .GIT_COMMIT }}" | ||
deps: [tag] | ||
deps: [ tag ] | ||
cmds: | ||
- docker push $(IMAGE_NAME):{{ .GIT_COMMIT }} | ||
- docker push $(IMAGE_NAME):{{ .VERSION }} | ||
- docker push $(IMAGE_NAME):latest | ||
clean: | ||
desc: "clean up data" | ||
cmds: | ||
- "test ! -e bin/{{ .BIN_NAME }} || rm bin/{{ .BIN_NAME }}" | ||
- "test ! -e bin/{{ .BIN_NAME }} || rm bin/{{ .BIN_NAME }}" | ||
- "rm -fr dist/" | ||
release-snapshot: | ||
deps: [clean] | ||
release-snapshot: | ||
deps: [ clean ] | ||
desc: "Release Snapshot" | ||
cmds: | ||
- goreleaser build --snapshot | ||
release: | ||
deps: [clean] | ||
release: | ||
deps: [ clean ] | ||
desc: "TEST Release of GDG, no validation, no publish" | ||
cmds: | ||
- goreleaser release --skip=publish,validate | ||
|
||
test: | ||
desc: "test check" | ||
cmds: | ||
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... | ||
- go tool cover -html=coverage.out | ||
env: | ||
GRAFANA_INTEGRATION: "1" | ||
TEST_TOKEN_CONFIG: "0" | ||
desc: "test check" | ||
cmds: | ||
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... | ||
- go tool cover -html=coverage.out | ||
env: | ||
GRAFANA_INTEGRATION: "1" | ||
TEST_TOKEN_CONFIG: "0" | ||
test_tokens: | ||
desc: "test Token Based Only" | ||
cmds: | ||
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... | ||
- go tool cover -html=coverage.out | ||
env: | ||
GRAFANA_INTEGRATION: "1" | ||
TEST_TOKEN_CONFIG: "1" | ||
desc: "test Token Based Only" | ||
cmds: | ||
- go test -v -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... | ||
- go tool cover -html=coverage.out | ||
env: | ||
GRAFANA_INTEGRATION: "1" | ||
TEST_TOKEN_CONFIG: "1" | ||
|
||
vuln_check: | ||
desc: "Vulnerability check" | ||
cmds: | ||
- govulncheck ./... | ||
desc: "Vulnerability check" | ||
cmds: | ||
- govulncheck ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/esnet/gdg/internal/config" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v3" | ||
"log" | ||
"log/slog" | ||
) | ||
|
||
var showConfigCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Show current templates configuration", | ||
Long: `Show current templates configuration`, | ||
Aliases: []string{"cfg"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
data, err := yaml.Marshal(config.Config().GetTemplateConfig()) | ||
if err != nil { | ||
log.Fatalf("unable to load template configuration: %v", err) | ||
} | ||
slog.Info("Configuration", | ||
slog.String("template-config", tplCfgFile), | ||
slog.String("gdg-config", cfgFile)) | ||
fmt.Println(string(data)) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(showConfigCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cli | ||
|
||
import ( | ||
assets "github.com/esnet/gdg/config" | ||
"github.com/esnet/gdg/internal/config" | ||
appconfig "github.com/esnet/gdg/internal/log" | ||
"github.com/esnet/gdg/internal/templating" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var ( | ||
cfgFile string | ||
tplCfgFile string | ||
template templating.Templating | ||
rootCmd = &cobra.Command{ | ||
Use: "gdg-generate", | ||
Short: "Generates dashboard templates for use with GDG given a valid configuration", | ||
Long: `Generates dashboard templates for use with GDG given a valid configuration`, | ||
} | ||
) | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
rootCmd.CompletionOptions.DisableDefaultCmd = true | ||
|
||
rootCmd.PersistentFlags().StringP("config", "c", "", "config file (default: config/importer.yml)") | ||
rootCmd.PersistentFlags().StringP("template-config", "", "", "GDG Template configuration file override. (default: config/templates.yml)") | ||
} | ||
|
||
func initConfig() { | ||
var err error | ||
cfgFile, err = rootCmd.Flags().GetString("config") | ||
if err != nil { | ||
log.Fatal("unable to get config file") | ||
} | ||
tplCfgFile, err = rootCmd.Flags().GetString("template-config") | ||
if err != nil { | ||
log.Fatal("unable to get template config file") | ||
} | ||
|
||
defaultConfiguration, err := assets.GetFile("importer-example.yml") | ||
if err != nil { | ||
slog.Warn("unable to load default configuration, no fallback") | ||
} | ||
|
||
config.InitGdgConfig(cfgFile, defaultConfiguration) | ||
config.InitTemplateConfig(tplCfgFile) | ||
cfg := config.Config() | ||
appconfig.InitializeAppLogger(os.Stdout, os.Stderr, cfg.IsDebug()) | ||
template = templating.NewTemplate() | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var tplCmd = &cobra.Command{ | ||
Use: "template", | ||
Aliases: []string{"tpl", "templates"}, | ||
Short: "Templating Utilities", | ||
Long: `Templating Utilities`, | ||
} | ||
|
||
var listTemplatesCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List current templates", | ||
Long: `List current templates`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
templates := template.ListTemplates() | ||
slog.Info("Available templates for current configuration", | ||
slog.String("template-config", tplCfgFile), | ||
slog.String("gdg-config", cfgFile)) | ||
for ndx, t := range templates { | ||
slog.Info(fmt.Sprintf("%d: %s", ndx+1, t)) | ||
} | ||
}, | ||
} | ||
|
||
var generateTemplatesCmd = &cobra.Command{ | ||
Use: "generate", | ||
Aliases: []string{}, | ||
Short: "Generate current templates", | ||
Long: `Generate current templates`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
templateFilter, _ := cmd.Flags().GetString("template") | ||
payload, err := template.Generate(templateFilter) | ||
if err != nil { | ||
log.Fatal("Failed to generate templates", slog.Any("err", err)) | ||
} | ||
|
||
tableObj := table.NewWriter() | ||
tableObj.SetOutputMirror(os.Stdout) | ||
tableObj.SetStyle(table.StyleLight) | ||
|
||
tableObj.AppendHeader(table.Row{"Template Name", "Output"}) | ||
count := 0 | ||
for key, val := range payload { | ||
count += len(val) | ||
for _, file := range val { | ||
tableObj.AppendRow(table.Row{key, file}) | ||
} | ||
} | ||
slog.Info("Generate dashboards for the given templates", | ||
slog.Any("template-count", len(payload)), | ||
slog.Any("dashboard-count", count)) | ||
tableObj.Render() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(tplCmd) | ||
tplCmd.AddCommand(listTemplatesCmd) | ||
tplCmd.AddCommand(generateTemplatesCmd) | ||
generateTemplatesCmd.PersistentFlags().StringP("template", "t", "", "Specify template name, optional. Default is to operate on all configured templates that are found.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/esnet/gdg/internal/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of gdg-generate", | ||
Long: `Print the version number of gdg-generate`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
version.PrintVersionInfo() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
Oops, something went wrong.