Skip to content

Commit

Permalink
Added deployer selection to run-plugin (#93)
Browse files Browse the repository at this point in the history
* Added deployer selection to run-plugin

* Improve message
  • Loading branch information
jaredoconnell committed Jun 28, 2023
1 parent d50e999 commit 7f79bcd
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions cmd/run-plugin/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,65 @@ 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"
)

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,
Expand All @@ -52,6 +86,7 @@ func main() {
}
}()

fmt.Println("Deploying")
plugin, err := connector.Deploy(ctx, image)
if err != nil {
panic(err)
Expand All @@ -63,6 +98,7 @@ func main() {
}()

atpClient := atp.NewClient(plugin)
fmt.Println("Getting schema")
pluginSchema, err := atpClient.ReadSchema()
if err != nil {
panic(err)
Expand All @@ -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,
Expand Down

0 comments on commit 7f79bcd

Please sign in to comment.