package main import ( "github.com/urfave/cli/v2" "log" "os" "strings" ) type payload struct { Kind string `json:"kind"` Name string `json:"name"` Namespace string `json:"namespace"` Images map[string]string `json:"images,omitempty"` } type errorResponse struct { Reason string } func main() { // 默认是重启 action := restart // 判断是啥操作 if actionKey := os.Getenv("PLUGIN_ACTION"); actionKey != "" { switch strings.ToLower(actionKey) { case "restart": action = restart case "update": // 如果image和tag有空值,报错 if os.Getenv("PLUGIN_IMAGE") == "" || os.Getenv("PLUGIN_TAG") == "" { panic("Configuration item image or tag must not be empty") return } action = update } } app := &cli.App{ Name: "drone-kuboard", Usage: "Update Kuboard Workloads Image Tag", Authors: []*cli.Author{ &cli.Author{ Name: "lxh", Email: "lxh@cxh.cn", }, }, Action: action, Flags: []cli.Flag{ &cli.StringFlag{ Required: true, Name: "cluster", Usage: "cluster name", EnvVars: []string{"PLUGIN_CLUSTER"}, }, &cli.StringFlag{ Required: true, Name: "kind", Usage: "workload type", EnvVars: []string{"PLUGIN_KIND"}, }, &cli.StringFlag{ Required: true, Name: "name", Usage: "workload name", EnvVars: []string{"PLUGIN_NAME"}, }, &cli.StringFlag{ Required: true, Name: "namespace", Usage: "workload namespace", EnvVars: []string{"PLUGIN_NAMESPACE"}, }, &cli.StringFlag{ Name: "image", Usage: "image uri", EnvVars: []string{"PLUGIN_IMAGE"}, }, &cli.StringFlag{ Name: "tag", Usage: "image tag", EnvVars: []string{"PLUGIN_TAG"}, }, &cli.StringFlag{ Required: true, Name: "kuboard_uri", Usage: "kuboard uri", EnvVars: []string{"PLUGIN_KUBOARD_URI"}, }, &cli.StringFlag{ Required: true, Name: "kuboard_username", Usage: "kuboard username", EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"}, }, &cli.StringFlag{ Required: true, Name: "kuboard_key", Usage: "kuboard access key", EnvVars: []string{"PLUGIN_KUBOARD_KEY"}, }, }, } if err := app.Run(os.Args); err != nil { log.Fatal(err) } log.Println("The image version was successfully updated.") }