From f05aefefa1ae502a967147d4b62be265ad9e05a2 Mon Sep 17 00:00:00 2001 From: Victor Castell <0x@vcastellm.xyz> Date: Sat, 10 Feb 2024 17:38:38 +0100 Subject: [PATCH] Embed http plugin (#1471) http plugin is one of the most used plugins together with the shell plugin, embedding it in the main binary allow for more lean deployment. --- .goreleaser.yml | 16 +++------- Makefile | 4 +-- builtin/bins/dkron-executor-http/main.go | 18 ----------- cmd/http.go | 30 +++++++++++++++++++ cmd/plugins.go | 13 +++++--- .../http}/http.go | 2 +- .../http}/http_test.go | 2 +- .../testdata/badssl-ca-untrusted-root.crt | 0 .../badssl.com-client-key-decrypted.pem | 0 .../http}/testdata/badssl.com-client.pem | 0 10 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 builtin/bins/dkron-executor-http/main.go create mode 100644 cmd/http.go rename {builtin/bins/dkron-executor-http => plugin/http}/http.go (99%) rename {builtin/bins/dkron-executor-http => plugin/http}/http_test.go (99%) rename {builtin/bins/dkron-executor-http => plugin/http}/testdata/badssl-ca-untrusted-root.crt (100%) rename {builtin/bins/dkron-executor-http => plugin/http}/testdata/badssl.com-client-key-decrypted.pem (100%) rename {builtin/bins/dkron-executor-http => plugin/http}/testdata/badssl.com-client.pem (100%) diff --git a/.goreleaser.yml b/.goreleaser.yml index ff6b7315e..11457aca5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,9 +5,9 @@ release: builds: - &xbuild - main: ./builtin/bins/dkron-executor-http/ - id: dkron-executor-http - binary: dkron-executor-http + main: . + id: dkron + binary: dkron env: - CGO_ENABLED=0 goos: @@ -22,7 +22,7 @@ builds: goarm: - '7' ldflags: - - -s -w + - -s -w -X github.com/distribworks/dkron/v4/dkron.Version={{.Version}} -X github.com/distribworks/dkron/v4/dkron.Codename=Abaniko - <<: *xbuild main: ./builtin/bins/dkron-executor-rabbitmq/ @@ -69,13 +69,6 @@ builds: id: dkron-processor-fluent binary: dkron-processor-fluent - - <<: *xbuild - main: . - id: dkron - binary: dkron - ldflags: - - -s -w -X github.com/distribworks/dkron/v4/dkron.Version={{.Version}} -X github.com/distribworks/dkron/v4/dkron.Codename=Abaniko - nfpms: - vendor: Distributed Works @@ -121,7 +114,6 @@ dockers: goarch: amd64 ids: &docker-ids - dkron - - dkron-executor-http - dkron-executor-rabbitmq - dkron-executor-nats - dkron-executor-kafka diff --git a/Makefile b/Makefile index 8b6fa33bd..7b2f1690a 100644 --- a/Makefile +++ b/Makefile @@ -72,8 +72,8 @@ localtest: updatetestcert: wget https://badssl.com/certs/badssl.com-client.p12 -q -O badssl.com-client.p12 - openssl pkcs12 -in badssl.com-client.p12 -nocerts -nodes -passin pass:badssl.com -out builtin/bins/dkron-executor-http/testdata/badssl.com-client-key-decrypted.pem - openssl pkcs12 -in badssl.com-client.p12 -nokeys -passin pass:badssl.com -out builtin/bins/dkron-executor-http/testdata/badssl.com-client.pem + openssl pkcs12 -in badssl.com-client.p12 -nocerts -nodes -passin pass:badssl.com -out plugin/http/testdata/badssl.com-client-key-decrypted.pem + openssl pkcs12 -in badssl.com-client.p12 -nokeys -passin pass:badssl.com -out plugin/http/testdata/badssl.com-client.pem rm badssl.com-client.p12 ui/node_modules: ui/package.json diff --git a/builtin/bins/dkron-executor-http/main.go b/builtin/bins/dkron-executor-http/main.go deleted file mode 100644 index 3d262017c..000000000 --- a/builtin/bins/dkron-executor-http/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - dkplugin "github.com/distribworks/dkron/v4/plugin" - "github.com/hashicorp/go-plugin" -) - -func main() { - plugin.Serve(&plugin.ServeConfig{ - HandshakeConfig: dkplugin.Handshake, - Plugins: map[string]plugin.Plugin{ - "executor": &dkplugin.ExecutorPlugin{Executor: &HTTP{}}, - }, - - // A non-nil value here enables gRPC serving for this plugin... - GRPCServer: plugin.DefaultGRPCServer, - }) -} diff --git a/cmd/http.go b/cmd/http.go new file mode 100644 index 000000000..8a65839c4 --- /dev/null +++ b/cmd/http.go @@ -0,0 +1,30 @@ +package cmd + +import ( + dkplugin "github.com/distribworks/dkron/v4/plugin" + "github.com/distribworks/dkron/v4/plugin/http" + "github.com/hashicorp/go-plugin" + "github.com/spf13/cobra" +) + +var httpCmd = &cobra.Command{ + Hidden: true, + Use: "http", + Short: "Run the http plugin", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: dkplugin.Handshake, + Plugins: map[string]plugin.Plugin{ + "executor": &dkplugin.ExecutorPlugin{Executor: &http.HTTP{}}, + }, + + // A non-nil value here enables gRPC serving for this plugin... + GRPCServer: plugin.DefaultGRPCServer, + }) + }, +} + +func init() { + dkronCmd.AddCommand(httpCmd) +} diff --git a/cmd/plugins.go b/cmd/plugins.go index 833d80219..f98746fba 100644 --- a/cmd/plugins.go +++ b/cmd/plugins.go @@ -15,6 +15,8 @@ import ( "github.com/spf13/viper" ) +var embededPlugins = []string{"shell", "http"} + type Plugins struct { Processors map[string]dkplugin.Processor Executors map[string]dkplugin.Executor @@ -95,11 +97,14 @@ func (p *Plugins) DiscoverPlugins() error { p.Executors[pluginName] = raw.(dkplugin.Executor) } - raw, err := p.pluginFactory(exePath, []string{"shell"}, dkplugin.ExecutorPluginName) - if err != nil { - return err + // Load the embeded plugins + for _, pluginName := range embededPlugins { + raw, err := p.pluginFactory(exePath, []string{pluginName}, dkplugin.ExecutorPluginName) + if err != nil { + return err + } + p.Executors[pluginName] = raw.(dkplugin.Executor) } - p.Executors["shell"] = raw.(dkplugin.Executor) return nil } diff --git a/builtin/bins/dkron-executor-http/http.go b/plugin/http/http.go similarity index 99% rename from builtin/bins/dkron-executor-http/http.go rename to plugin/http/http.go index 4cb637546..f82343073 100644 --- a/builtin/bins/dkron-executor-http/http.go +++ b/plugin/http/http.go @@ -1,4 +1,4 @@ -package main +package http import ( "bytes" diff --git a/builtin/bins/dkron-executor-http/http_test.go b/plugin/http/http_test.go similarity index 99% rename from builtin/bins/dkron-executor-http/http_test.go rename to plugin/http/http_test.go index febe634c1..f8eb68cec 100644 --- a/builtin/bins/dkron-executor-http/http_test.go +++ b/plugin/http/http_test.go @@ -1,4 +1,4 @@ -package main +package http import ( "bytes" diff --git a/builtin/bins/dkron-executor-http/testdata/badssl-ca-untrusted-root.crt b/plugin/http/testdata/badssl-ca-untrusted-root.crt similarity index 100% rename from builtin/bins/dkron-executor-http/testdata/badssl-ca-untrusted-root.crt rename to plugin/http/testdata/badssl-ca-untrusted-root.crt diff --git a/builtin/bins/dkron-executor-http/testdata/badssl.com-client-key-decrypted.pem b/plugin/http/testdata/badssl.com-client-key-decrypted.pem similarity index 100% rename from builtin/bins/dkron-executor-http/testdata/badssl.com-client-key-decrypted.pem rename to plugin/http/testdata/badssl.com-client-key-decrypted.pem diff --git a/builtin/bins/dkron-executor-http/testdata/badssl.com-client.pem b/plugin/http/testdata/badssl.com-client.pem similarity index 100% rename from builtin/bins/dkron-executor-http/testdata/badssl.com-client.pem rename to plugin/http/testdata/badssl.com-client.pem