Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement plugin scaffold #518

Merged
merged 16 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ __pycache__/
dist/

# Editor files
.vscode
.idea
.idea/*
.history
.vscode/*
.vsix

# Logs
*.log
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ linters-settings:
- "gopkg.in/natefinch/lumberjack.v2"
- "github.com/expr-lang/expr"
- "github.com/jackc/pgx/v5/pgproto3"
- "github.com/cybercyst/go-scaffold/pkg/scaffold"
- "golang.org/x/text/cases"
- "golang.org/x/text/language"
- "gopkg.in/yaml.v2"
test:
files:
- $test
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tidy:
@go mod tidy

build-dev:
@go mod tidy && CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w -X ${CONFIG_PACKAGE}.Version=${VERSION} -X ${CMD_PACKAGE}.UsageReportURL=localhost:59091"
@go mod tidy && CGO_ENABLED=0 go build -tags embed_plugin_template,embed_swagger -trimpath -ldflags "-s -w -X ${CONFIG_PACKAGE}.Version=${VERSION} -X ${CMD_PACKAGE}.UsageReportURL=localhost:59091"

create-build-dir:
@mkdir -p dist
Expand All @@ -33,11 +33,11 @@ build-platform: tidy
@mkdir -p $(OUTPUT_DIR)
@cp README.md LICENSE gatewayd.yaml gatewayd_plugins.yaml $(OUTPUT_DIR)/
@if [ "$(GOOS)" = "windows" ]; then \
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -tags embed_swagger,windows -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/gatewayd.exe; \
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -tags embed_plugin_template,embed_swagger,windows -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/gatewayd.exe; \
sha256sum $(OUTPUT_DIR)/gatewayd.exe | sed 's#$(OUTPUT_DIR)/##g' >> $(OUTPUT_DIR)/checksum.txt; \
zip -q -r dist/gatewayd-$(GOOS)-$(GOARCH)-${VERSION}.zip -j $(OUTPUT_DIR)/; \
else \
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -tags embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/gatewayd; \
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -tags embed_plugin_template,embed_swagger -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/gatewayd; \
sha256sum $(OUTPUT_DIR)/gatewayd | sed 's#$(OUTPUT_DIR)/##g' >> $(OUTPUT_DIR)/checksum.txt; \
tar czf dist/gatewayd-$(GOOS)-$(GOARCH)-${VERSION}.tar.gz -C $(OUTPUT_DIR)/ ${FILES}; \
fi
Expand Down Expand Up @@ -69,13 +69,13 @@ build-linux-packages:
@sha256sum dist/gatewayd-$(VERSION:v%=%).aarch64.rpm | sed 's/dist\///g' >> dist/checksums.txt

run: tidy
@go run -tags embed_swagger main.go run --dev
@go run -tags embed_plugin_template,embed_swagger main.go run --dev

run-race: tidy
@go run -race -tags embed_swagger main.go run --dev
@go run -race -tags embed_plugin_template,embed_swagger main.go run --dev

run-tracing: tidy
@go run -tags embed_swagger main.go run --tracing --dev
@go run -tags embed_plugin_template,embed_swagger main.go run --tracing --dev

clean:
@go clean -testcache
Expand Down Expand Up @@ -104,4 +104,7 @@ update:
@buf mod update

gen-docs:
@go run main.go gen-docs
@go run main.go gen-docs

golint:
@golangci-lint run --show-stats
42 changes: 42 additions & 0 deletions cmd/plugin_scaffold.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"github.com/gatewayd-io/gatewayd/plugin"
"github.com/spf13/cobra"
)

var (
pluginScaffoldInputFile string
pluginScaffoldOutputDir string
)

// pluginScaffoldCmd represents the scaffold command.
var pluginScaffoldCmd = &cobra.Command{
Use: "scaffold",
Short: "Scaffold a plugin and store the files into a directory",
Run: func(cmd *cobra.Command, _ []string) {
createdFiles, err := plugin.Scaffold(pluginScaffoldInputFile, pluginScaffoldOutputDir)
if err != nil {
cmd.Println("Scaffold failed: ", err)
return
}

cmd.Println("scaffold done")
cmd.Println("created files:")
for _, file := range createdFiles {
cmd.Println(file)
}
},
}

func init() {
pluginCmd.AddCommand(pluginScaffoldCmd)
pluginScaffoldCmd.Flags().StringVarP(
&pluginScaffoldInputFile,
"input-file", "i", "input.yaml",
"Plugin scaffold input file")
pluginScaffoldCmd.Flags().StringVarP(
&pluginScaffoldOutputDir,
"output-dir", "o", "./plugins",
"Output directory for the scaffold")
}
1 change: 1 addition & 0 deletions cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Available Commands:
install Install a plugin from a local archive or a GitHub repository
lint Lint the GatewayD plugins config
list List the GatewayD plugins
scaffold Scaffold a plugin and store the files into a directory

Flags:
-h, --help help for plugin
Expand Down
12 changes: 12 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (
ErrCodeDispensePluginFailed
ErrCodePluginMetricsMergeFailed
ErrCodePluginPingFailed
ErrCodePluginScaffoldFailed
ErrCopyEmbeddedFilesFailed
ErrCodePluginScaffoldInputFileReadFailed
ErrCodeClientReceiveFailed
ErrCodeClientSendFailed
ErrCodeServerReceiveFailed
Expand Down Expand Up @@ -92,6 +95,15 @@ var (
ErrFailedToPingPlugin = &GatewayDError{
ErrCodePluginPingFailed, "failed to ping plugin", nil,
}
ErrFailedToScaffoldPlugin = &GatewayDError{
ErrCodePluginScaffoldFailed, "failed to scaffold plugin", nil,
}
ErrFailedToCopyEmbeddedFiles = &GatewayDError{
ErrCopyEmbeddedFilesFailed, "failed to copy embedded files", nil,
}
ErrFailedToReadPluginScaffoldInputFile = &GatewayDError{
ErrCodePluginScaffoldInputFileReadFailed, "failed to read plugin scaffold input file", nil,
}

ErrClientReceiveFailed = &GatewayDError{
ErrCodeClientReceiveFailed, "couldn't receive data from the server", nil,
Expand Down
39 changes: 37 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/gatewayd-io/gatewayd

go 1.22
go 1.22.0

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/NYTimes/gziphandler v1.1.1
github.com/codingsince1985/checksum v1.3.0
github.com/cybercyst/go-scaffold v0.0.0-20240404115540-744e601147cd
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.11
github.com/getsentry/sentry-go v0.27.0
Expand Down Expand Up @@ -33,58 +34,92 @@ require (
go.opentelemetry.io/otel/sdk v1.26.0
go.opentelemetry.io/otel/trace v1.26.0
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
golang.org/x/text v0.14.0
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.3.8 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/expr-lang/expr v1.16.5 // indirect
github.com/extemporalgenome/slug v0.0.0-20150414033109-0320c85e32e0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v6 v6.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.5.2 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pganalyze/pg_query_go/v5 v5.1.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/qri-io/jsonpointer v0.1.1 // indirect
github.com/qri-io/jsonschema v0.2.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tetratelabs/wazero v1.7.1 // indirect
github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
oras.land/oras-go/v2 v2.0.0 // indirect
)
Loading