/
main.go
87 lines (72 loc) · 1.65 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
82
83
84
85
86
87
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin"
)
var (
version = "unknown"
)
func main() {
fmt.Printf("Drone AWS OpsWorks Plugin built from %s\n", version)
repo := drone.Repo{}
build := drone.Build{}
vargs := Params{}
plugin.Param("repo", &repo)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.MustParse()
if vargs.AccessKey == "" {
fmt.Println("Please provide an access key id")
os.Exit(1)
}
if vargs.SecretKey == "" {
fmt.Println("Please provide a secret access key")
os.Exit(1)
}
if aws.StringValue(vargs.Region) == "" {
fmt.Println("Please provide a region")
os.Exit(1)
}
if aws.StringValue(vargs.StackID) == "" {
fmt.Println("Please provide a stack ID")
os.Exit(1)
}
if aws.StringValue(vargs.Command) == "" {
fmt.Println("Please provide a deploy command")
os.Exit(1)
}
svc := opsworks.New(
session.New(&aws.Config{
Region: vargs.Region,
Credentials: credentials.NewStaticCredentials(
vargs.AccessKey,
vargs.SecretKey,
"",
),
}),
)
_, err := svc.CreateDeployment(
&opsworks.CreateDeploymentInput{
Command: &opsworks.DeploymentCommand{
Name: vargs.Command,
Args: vargs.Arguments,
},
StackId: vargs.StackID,
AppId: vargs.AppID,
Comment: vargs.Comment,
CustomJson: vargs.CustomJSON,
InstanceIds: vargs.Instances,
},
)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Println("Successfully deployed")
}