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

Convert shell plugin to internal plugin #975

Merged
merged 2 commits into from
Jul 22, 2022
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
18 changes: 0 additions & 18 deletions builtin/bins/dkron-executor-shell/main.go

This file was deleted.

16 changes: 10 additions & 6 deletions cmd/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,37 @@ func (p *Plugins) DiscoverPlugins() error {
}

for _, file := range processors {

pluginName, ok := getPluginName(file)
if !ok {
continue
}

raw, err := p.pluginFactory(file, dkplugin.ProcessorPluginName)
raw, err := p.pluginFactory(file, []string{}, dkplugin.ProcessorPluginName)
if err != nil {
return err
}
p.Processors[pluginName] = raw.(dkplugin.Processor)
}

for _, file := range executors {

pluginName, ok := getPluginName(file)
if !ok {
continue
}

raw, err := p.pluginFactory(file, dkplugin.ExecutorPluginName)
raw, err := p.pluginFactory(file, []string{}, dkplugin.ExecutorPluginName)
if err != nil {
return err
}
p.Executors[pluginName] = raw.(dkplugin.Executor)
}

raw, err := p.pluginFactory(exePath, []string{"shell"}, dkplugin.ExecutorPluginName)
if err != nil {
return err
}
p.Executors["shell"] = raw.(dkplugin.Executor)

return nil
}

Expand All @@ -107,10 +111,10 @@ func getPluginName(file string) (string, bool) {
return name, true
}

func (p *Plugins) pluginFactory(path string, pluginType string) (interface{}, error) {
func (p *Plugins) pluginFactory(path string, args []string, pluginType string) (interface{}, error) {
// Build the plugin client configuration and init the plugin
var config plugin.ClientConfig
config.Cmd = exec.Command(path)
config.Cmd = exec.Command(path, args...)
config.HandshakeConfig = dkplugin.Handshake
config.Managed = true
config.Plugins = dkplugin.PluginMap
Expand Down
27 changes: 27 additions & 0 deletions cmd/shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
dkplugin "github.com/distribworks/dkron/v3/plugin"
"github.com/distribworks/dkron/v3/plugin/shell"
"github.com/hashicorp/go-plugin"
"github.com/spf13/cobra"
)

var shellCmd = &cobra.Command{
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: dkplugin.Handshake,
Plugins: map[string]plugin.Plugin{
"executor": &dkplugin.ExecutorPlugin{Executor: &shell.Shell{}},
},

// A non-nil value here enables gRPC serving for this plugin...
GRPCServer: plugin.DefaultGRPCServer,
})
},
}

func init() {
dkronCmd.AddCommand(shellCmd)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package shell

import (
"encoding/base64"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package shell

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build !windows

package main
package shell

import (
"os/exec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build windows

package main
package shell

import (
"os/exec"
Expand Down