/
main.go
81 lines (74 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "ansible plugin"
app.Usage = "ansible plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "inventory-path",
Usage: "ansible inventory path",
Value: defaultInventoryPath,
EnvVar: "PLUGIN_INVENTORY_PATH",
},
cli.StringSliceFlag{
Name: "inventories",
Usage: "ansible inventory files",
Value: &cli.StringSlice{"staging"},
EnvVar: "PLUGIN_INVENTORY,PLUGIN_INVENTORIES",
},
cli.StringFlag{
Name: "playbook",
Usage: "ansible playbook to execute",
Value: defaultPlaybook,
EnvVar: "PLUGIN_PLAYBOOK",
},
cli.StringFlag{
Name: "ssh-key",
Usage: "ssh key to access remote hosts",
EnvVar: "SSH_KEY,PLUGIN_SSH_KEY",
},
cli.StringFlag{
Name: "path",
Usage: "project base path",
EnvVar: "DRONE_WORKSPACE",
},
cli.StringFlag{
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
},
cli.StringFlag{
Name: "commit.tag",
Usage: "project base path",
EnvVar: "DRONE_TAG",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
plugin := Plugin{
Build: Build{
Path: c.String("path"),
SHA: c.String("commit.sha"),
Tag: c.String("commit.tag"),
},
Config: Config{
InventoryPath: c.String("inventory-path"),
Inventories: c.StringSlice("inventories"),
Playbook: c.String("playbook"),
SSHKey: c.String("ssh-key"),
},
}
return plugin.Exec()
}