Skip to content

Commit

Permalink
Report to API in case of error building deploy images
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciojs committed Feb 11, 2024
1 parent 0301555 commit be3a5aa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions commands/cloud_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (d *KoolDeploy) Execute(args []string) (err error) {
d.Shell().Info(" > Build deploy image for service: ", svcName)

if err = cloud.BuildPushImageForDeploy(svcName, svc, deployCreated); err != nil {
if reportErr := deployer.BuildError(deployCreated, err); reportErr != nil {
d.Shell().Error(fmt.Errorf("error reporting build error: %v", reportErr))
}

return
}

Expand Down
29 changes: 29 additions & 0 deletions services/cloud/api/deploy_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package api

import "fmt"

// DeployError consumes the API endpoint to inform a build error for a deployment
type DeployError struct {
Endpoint
}

// NewDeployError creates a new DeployError instance
func NewDeployError(created *DeployCreateResponse, err error) (c *DeployError) {
c = &DeployError{
Endpoint: NewDefaultEndpoint("POST"),
}

c.SetPath("deploy/error")
c.Body().Set("id", fmt.Sprintf("%d", created.Deploy.ID))
c.Body().Set("err", err.Error())

return
}

// Run calls deploy/error in the Kool Dev API
func (c *DeployError) Run() (err error) {
var resp interface{}
c.SetResponseReceiver(&resp)
err = c.DoCall()
return
}
7 changes: 7 additions & 0 deletions services/cloud/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ func (d *Deployer) StartDeploy(created *api.DeployCreateResponse) (started *api.
started, err = start.Run()
return
}

func (d *Deployer) BuildError(created *api.DeployCreateResponse, gotErr error) (err error) {
var buildErr = api.NewDeployError(created, gotErr)

err = buildErr.Run()
return
}

0 comments on commit be3a5aa

Please sign in to comment.