-
Notifications
You must be signed in to change notification settings - Fork 3
/
services_deployments.go
71 lines (55 loc) · 1.71 KB
/
services_deployments.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
package cmd
import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func servicesDeploymentsRun(cmd *cobra.Command, args []string) {
var services []*string
for _, s := range args {
services = append(services, aws.String(s))
}
cluster := viper.GetString("cluster")
clustersDescription, err := ecsI.DescribeClusters(&ecs.DescribeClustersInput{
Clusters: []*string{aws.String(cluster)},
})
t.Must(err)
if len(clustersDescription.Clusters) == 0 {
t.Exitln("Source Cluster informed not found")
}
c := clustersDescription.Clusters[0]
for {
servicesDescription, err := ecsI.DescribeServices(&ecs.DescribeServicesInput{
Cluster: c.ClusterName,
Services: services,
})
t.Must(err)
for _, d := range servicesDescription.Services[0].Deployments {
if aws.StringValue(d.Status) == "PRIMARY" {
switch aws.StringValue(d.RolloutState) {
case ecs.DeploymentRolloutStateCompleted:
t.Outln("Complete!")
t.Exit(nil)
case ecs.DeploymentRolloutStateFailed:
t.Exitf("Failed! Reason: %s\n", aws.StringValue(d.RolloutStateReason))
}
}
}
time.Sleep(10 * time.Second)
}
}
var servicesDeploymentsCmd = &cobra.Command{
Use: "deployments [service]",
Short: "Query for the deployments state of specified service",
Args: cobra.MinimumNArgs(1),
Run: servicesDeploymentsRun,
PersistentPreRun: persistentPreRun,
}
func init() {
servicesCmd.AddCommand(servicesDeploymentsCmd)
flags := servicesDeploymentsCmd.Flags()
flags.StringP("cluster", "c", "", requiredSpec+clusterSpec)
viper.BindPFlag("cluster", servicesDeploymentsCmd.Flags().Lookup("cluster"))
}