Replicate most of drone-helm's config

This commit is contained in:
Erin Call
2019-12-09 09:56:02 -08:00
parent 238ede6f9e
commit e3051ec72e
12 changed files with 277 additions and 62 deletions

View File

@@ -2,44 +2,34 @@ package main
import (
"fmt"
"github.com/urfave/cli"
"github.com/kelseyhightower/envconfig"
"os"
"github.com/pelotech/drone-helm3/internal/run"
"github.com/pelotech/drone-helm3/internal/helm"
)
func main() {
app := cli.NewApp()
app.Name = "helm plugin"
app.Usage = "helm plugin"
app.Action = execute
app.Version = "0.0.1α"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "helm_command",
Usage: "Helm command to execute",
EnvVar: "PLUGIN_HELM_COMMAND,HELM_COMMAND",
},
}
var c helm.Config
if err := app.Run(os.Args); err != nil {
if err := envconfig.Process("plugin", &c); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
return
}
// Make the plan
plan, err := helm.NewPlan(c)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
return
}
// Execute the plan
err = plan.Execute()
// Expect the plan to go off the rails
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
// Throw away the plan
os.Exit(1)
}
}
func execute(c *cli.Context) error {
switch c.String("helm_command") {
case "upgrade":
run.Upgrade()
case "help":
run.Help()
default:
switch os.Getenv("DRONE_BUILD_EVENT") {
case "push", "tag", "deployment", "pull_request", "promote", "rollback":
run.Upgrade()
default:
run.Help()
}
return nil
}