()
| 38 | } |
| 39 | |
| 40 | func (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) |
nothing calls this directly
no test coverage detected