drone-kuboard/main.go

111 lines
2.4 KiB
Go
Raw Normal View History

2023-10-17 16:32:16 +08:00
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":
2023-10-17 16:46:41 +08:00
// 如果image和tag有空值报错
if os.Getenv("PLUGIN_IMAGE") == "" || os.Getenv("PLUGIN_TAG") == "" {
panic("Configuration item image or tag must not be empty")
return
}
2023-10-17 16:32:16 +08:00
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{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "cluster",
Usage: "cluster name",
EnvVars: []string{"PLUGIN_CLUSTER"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "kind",
Usage: "workload type",
EnvVars: []string{"PLUGIN_KIND"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "name",
Usage: "workload name",
EnvVars: []string{"PLUGIN_NAME"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "namespace",
Usage: "workload namespace",
EnvVars: []string{"PLUGIN_NAMESPACE"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
Name: "image",
Usage: "image uri",
EnvVars: []string{"PLUGIN_IMAGE"},
},
&cli.StringFlag{
Name: "tag",
Usage: "image tag",
EnvVars: []string{"PLUGIN_TAG"},
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "kuboard_uri",
Usage: "kuboard uri",
EnvVars: []string{"PLUGIN_KUBOARD_URI"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "kuboard_username",
Usage: "kuboard username",
EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"},
2023-10-17 16:32:16 +08:00
},
&cli.StringFlag{
2023-10-17 16:46:41 +08:00
Required: true,
Name: "kuboard_key",
Usage: "kuboard access key",
EnvVars: []string{"PLUGIN_KUBOARD_KEY"},
2023-10-17 16:32:16 +08:00
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
log.Println("The image version was successfully updated.")
}