MCPcopy Create free account
hub / github.com/coldbrewcloud/coldbrew-cli / Run

Method Run

commands/delete/command.go:40–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38}
39
40func (c *Command) Run() error {
41 c.awsClient = c.globalFlags.GetAWSClient()
42
43 appName := ""
44 clusterName := ""
45
46 // app configuration
47 configFilePath, err := c.globalFlags.GetConfigFile()
48 if err != nil {
49 return console.ExitWithError(err)
50 }
51 if utils.FileExists(configFilePath) {
52 configData, err := ioutil.ReadFile(configFilePath)
53 if err != nil {
54 return console.ExitWithErrorString("Failed to read configuration file [%s]: %s", configFilePath, err.Error())
55 }
56 conf, err := config.Load(configData, conv.S(c.globalFlags.ConfigFileFormat), core.DefaultAppName(configFilePath))
57 if err != nil {
58 return console.ExitWithError(err)
59 }
60
61 appName = conv.S(conf.Name)
62 clusterName = conv.S(conf.ClusterName)
63 }
64
65 // app/cluster name from CLI will override configuration file
66 if !utils.IsBlank(conv.S(c.commandFlags.AppName)) {
67 appName = conv.S(c.commandFlags.AppName)
68 }
69 if !utils.IsBlank(conv.S(c.commandFlags.ClusterName)) {
70 clusterName = conv.S(c.commandFlags.ClusterName)
71 }
72
73 if utils.IsBlank(appName) {
74 return console.ExitWithErrorString("App name is required.")
75 }
76 if utils.IsBlank(clusterName) {
77 return console.ExitWithErrorString("Cluster name is required.")
78 }
79
80 console.Info("Determining AWS resources that need to be deleted...")
81
82 // ECS Service
83 var ecsServiceToDelete *ecs.Service
84 ecsClusterName := core.DefaultECSClusterName(clusterName)
85 ecsServiceName := core.DefaultECSServiceName(appName)
86 ecsServiceToDelete, err = c.awsClient.ECS().RetrieveService(ecsClusterName, ecsServiceName)
87 if err != nil {
88 return console.ExitWithErrorString("Failed to retrieve ECS Service [%s/%s]: %s", ecsClusterName, ecsServiceName, err.Error())
89 }
90 if ecsServiceToDelete != nil && conv.S(ecsServiceToDelete.Status) == "ACTIVE" {
91 console.DetailWithResource("ECS Service", ecsServiceName)
92 } else {
93 return console.ExitWithErrorString("ECS Service [%s/%s] was not found.", ecsClusterName, ecsServiceName)
94 }
95
96 // identify ECR resources to delete
97 ecrRepositoryNameToDelete, err := c.identifyECRResourcesToDelete(appName, ecsServiceToDelete)

Callers

nothing calls this directly

Implementers 8

Commandcommands/clusterstatus/command.go
Commandcommands/deploy/command.go
Commandcommands/clusterdelete/command.go
Commandcommands/delete/command.go
Commandcommands/clustercreate/command.go
Commandcommands/create/command.go
Commandcommands/clusterscale/command.go
Commandcommands/status/command.go

Calls 15

GetAWSClientMethod · 0.80
GetConfigFileMethod · 0.80
ErrorMethod · 0.80
RetrieveServiceMethod · 0.80
ECSMethod · 0.80
UpdateServiceMethod · 0.80
DeleteLoadBalancerMethod · 0.80
ELBMethod · 0.80
DeleteTargetGroupMethod · 0.80

Tested by

no test coverage detected