MCPcopy Index your code
hub / github.com/coldbrewcloud/coldbrew-cli / Run

Method Run

commands/deploy/command.go:38–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36}
37
38func (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

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 13

validateFlagsMethod · 0.95
isClusterAvailableMethod · 0.95
prepareECRRepoMethod · 0.95
buildDockerImageMethod · 0.95
pushDockerImageMethod · 0.95
GetConfigFileMethod · 0.80
ErrorMethod · 0.80
GetAWSClientMethod · 0.80
DockerBinAvailableMethod · 0.80

Tested by

no test coverage detected