Skip to content

Commit

Permalink
Embed http plugin (#1471)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vcastellm authored Feb 10, 2024
1 parent 586f72d commit f05aefe
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 38 deletions.
16 changes: 4 additions & 12 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -121,7 +114,6 @@ dockers:
goarch: amd64
ids: &docker-ids
- dkron
- dkron-executor-http
- dkron-executor-rabbitmq
- dkron-executor-nats
- dkron-executor-kafka
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions builtin/bins/dkron-executor-http/main.go

This file was deleted.

30 changes: 30 additions & 0 deletions cmd/http.go
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 9 additions & 4 deletions cmd/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package http

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package http

import (
"bytes"
Expand Down
File renamed without changes.

0 comments on commit f05aefe

Please sign in to comment.