()
| 36 | } |
| 37 | |
| 38 | func (c *Command) Run() error { |
| 39 | var err error |
| 40 | |
| 41 | // app configuration |
| 42 | configFilePath, err := c.globalFlags.GetConfigFile() |
| 43 | if err != nil { |
| 44 | return console.ExitWithError(err) |
| 45 | } |
| 46 | configData, err := ioutil.ReadFile(configFilePath) |
| 47 | if err != nil { |
| 48 | return console.ExitWithErrorString("Failed to read configuration file [%s]: %s", configFilePath, err.Error()) |
| 49 | } |
| 50 | c.conf, err = config.Load(configData, conv.S(c.globalFlags.ConfigFileFormat), core.DefaultAppName(configFilePath)) |
| 51 | if err != nil { |
| 52 | return console.ExitWithError(err) |
| 53 | } |
| 54 | |
| 55 | // CLI flags validation |
| 56 | if err := c.validateFlags(c._commandFlags); err != nil { |
| 57 | return console.ExitWithError(core.NewErrorExtraInfo(err, "https://github.com/coldbrewcloud/coldbrew-cli/wiki/Command:-deploy")) |
| 58 | } |
| 59 | |
| 60 | // merge flags into main configuration |
| 61 | c.conf = c.mergeFlagsIntoConfiguration(c.conf, c._commandFlags) |
| 62 | |
| 63 | // AWS client |
| 64 | c.awsClient = c.globalFlags.GetAWSClient() |
| 65 | |
| 66 | // test if target cluster is available to use |
| 67 | console.ProcessingOnResource("Checking cluster availability", conv.S(c.conf.ClusterName), false) |
| 68 | if err := c.isClusterAvailable(conv.S(c.conf.ClusterName)); err != nil { |
| 69 | return console.ExitWithError(core.NewErrorExtraInfo(err, "https://github.com/coldbrewcloud/coldbrew-cli/wiki/Error:-Cluster-not-found")) |
| 70 | } |
| 71 | |
| 72 | // docker client |
| 73 | c.dockerClient = docker.NewClient(conv.S(c.conf.Docker.Bin)) |
| 74 | if !c.dockerClient.DockerBinAvailable() { |
| 75 | return console.ExitWithError(core.NewErrorExtraInfo( |
| 76 | fmt.Errorf("Failed to find Docker binary [%s].", c.conf.Docker.Bin), |
| 77 | "https://github.com/coldbrewcloud/coldbrew-cli/wiki/Error:-Docker-binary-not-found")) |
| 78 | } |
| 79 | |
| 80 | // prepare ECR repo (create one if needed) |
| 81 | ecrRepoURI, err := c.prepareECRRepo(conv.S(c.conf.AWS.ECRRepositoryName)) |
| 82 | if err != nil { |
| 83 | return console.ExitWithError(err) |
| 84 | } |
| 85 | |
| 86 | // prepare docker image (build one if needed) |
| 87 | dockerImage := conv.S(c._commandFlags.DockerImage) |
| 88 | if utils.IsBlank(dockerImage) { // build local docker image |
| 89 | dockerImage = fmt.Sprintf("%s:latest", ecrRepoURI) |
| 90 | console.ProcessingOnResource("Building Docker image", dockerImage, true) |
| 91 | if err := c.buildDockerImage(dockerImage); err != nil { |
| 92 | return console.ExitWithError(err) |
| 93 | } |
| 94 | } else { // use local docker image |
| 95 | // if needed, re-tag local image so it can be pushed to target ECR repo |
nothing calls this directly
no test coverage detected