From 7f79bcdfc2f2b6839cdfdbe152f9c51813420145 Mon Sep 17 00:00:00 2001 From: Jared O'Connell <46976761+jaredoconnell@users.noreply.github.com> Date: Wed, 28 Jun 2023 15:58:03 -0400 Subject: [PATCH] Added deployer selection to run-plugin (#93) * Added deployer selection to run-plugin * Improve message --- cmd/run-plugin/run.go | 47 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/cmd/run-plugin/run.go b/cmd/run-plugin/run.go index 391237ac..be241dee 100644 --- a/cmd/run-plugin/run.go +++ b/cmd/run-plugin/run.go @@ -5,12 +5,15 @@ import ( "context" "flag" "fmt" + "go.flow.arcalot.io/deployer" + podman "go.flow.arcalot.io/podmandeployer" "os" "os/signal" log "go.arcalot.io/log/v2" docker "go.flow.arcalot.io/dockerdeployer" "go.flow.arcalot.io/pluginsdk/atp" + testdeployer "go.flow.arcalot.io/testdeployer" "gopkg.in/yaml.v3" ) @@ -18,18 +21,49 @@ func main() { var image string var file string var stepID string + var d deployer.AnyConnectorFactory + var defaultConfig any + var deployerID = "docker" flag.StringVar(&image, "image", image, "Docker image to run") flag.StringVar(&file, "file", file, "Input file") flag.StringVar(&stepID, "step", stepID, "Step name") + flag.StringVar(&deployerID, "deployer", stepID, "The name of the deployer") flag.Parse() - d := docker.NewFactory() - configSchema := d.ConfigurationSchema() - defaultConfig, err := configSchema.UnserializeType(map[string]any{}) - if err != nil { - panic(err) + switch deployerID { + case "docker": + dockerFactory := docker.NewFactory() + d = deployer.Any(dockerFactory) + + configSchema := dockerFactory.ConfigurationSchema() + var err error + defaultConfig, err = configSchema.UnserializeType(map[string]any{}) + if err != nil { + panic(err) + } + case "podman": + podmanFactory := podman.NewFactory() + d = deployer.Any(podmanFactory) + configSchema := podmanFactory.ConfigurationSchema() + var err error + defaultConfig, err = configSchema.UnserializeType(map[string]any{}) + if err != nil { + panic(err) + } + case "testimpl": + podmanFactory := testdeployer.NewFactory() + d = deployer.Any(podmanFactory) + configSchema := podmanFactory.ConfigurationSchema() + var err error + defaultConfig, err = configSchema.UnserializeType(map[string]any{}) + if err != nil { + panic(err) + } + default: + panic("No deployer or invalid deployer selected. Options: docker, podman, testimpl. Select with -deployer") } + connector, err := d.Create(defaultConfig, log.New(log.Config{ Level: log.LevelDebug, Destination: log.DestinationStdout, @@ -52,6 +86,7 @@ func main() { } }() + fmt.Println("Deploying") plugin, err := connector.Deploy(ctx, image) if err != nil { panic(err) @@ -63,6 +98,7 @@ func main() { }() atpClient := atp.NewClient(plugin) + fmt.Println("Getting schema") pluginSchema, err := atpClient.ReadSchema() if err != nil { panic(err) @@ -83,6 +119,7 @@ func main() { if _, err := step.Input().Unserialize(input); err != nil { panic(err) } + fmt.Printf("Running step %s\n", stepID) outputID, outputData, err := atpClient.Execute(stepID, input) output := map[string]any{ "outputID": outputID,