99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
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":
|
|
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{
|
|
Name: "cluster",
|
|
Usage: "cluster name",
|
|
EnvVars: []string{"PLUGIN_CLUSTER"},
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "kind",
|
|
Usage: "workload type",
|
|
EnvVars: []string{"PLUGIN_KIND"},
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "name",
|
|
Usage: "workload name",
|
|
EnvVars: []string{"PLUGIN_NAME"},
|
|
},
|
|
&cli.StringFlag{
|
|
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{
|
|
Name: "kuboard_uri",
|
|
Usage: "kuboard uri",
|
|
EnvVars: []string{"PLUGIN_KUBOARD_URI"},
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "kuboard_username",
|
|
Usage: "kuboard username",
|
|
EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"},
|
|
},
|
|
&cli.StringFlag{
|
|
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.")
|
|
}
|